Here are the examples of the python api sqlalchemy.and_ taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : test_query.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_match_across_joins(self):
results = (
matchtable.select()
.where(
and_(
cattable.c.id == matchtable.c.category_id,
or_(
cattable.c.description.match("Ruby"),
matchtable.c.satle.match("nutshell"),
),
)
)
.order_by(matchtable.c.id)
.execute()
.fetchall()
)
eq_([1, 3, 5], [r.id for r in results])
3
View Complete Implementation : test_generative.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_distinct_count(self):
table2, Obj1, table1 = (
self.tables.table2,
self.clastes.Obj1,
self.tables.table1,
)
query = create_session().query(Obj1)
eq_(query.count(), 4)
res = query.filter(
sa.and_(table1.c.id == table2.c.t1id, table2.c.t1id == 1)
)
eq_(res.count(), 3)
res = query.filter(
sa.and_(table1.c.id == table2.c.t1id, table2.c.t1id == 1)
).distinct()
eq_(res.count(), 1)
3
View Complete Implementation : test_compare.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_compare_clauselist_astociative(self):
l1 = and_(table_c.c.x == table_d.c.y, table_c.c.y == table_d.c.z)
l2 = and_(table_c.c.y == table_d.c.z, table_c.c.x == table_d.c.y)
l3 = and_(table_c.c.x == table_d.c.z, table_c.c.y == table_d.c.y)
is_true(l1.compare(l1))
is_true(l1.compare(l2))
is_false(l1.compare(l3))
3
View Complete Implementation : generic_fk.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
@event.listens_for(HasAddresses, "mapper_configured", propagate=True)
def setup_listener(mapper, clast_):
name = clast_.__name__
discriminator = name.lower()
clast_.addresses = relationship(
Address,
primaryjoin=and_(
clast_.id == foreign(remote(Address.parent_id)),
Address.discriminator == discriminator,
),
backref=backref(
"parent_%s" % discriminator,
primaryjoin=remote(clast_.id) == foreign(Address.parent_id),
),
)
@event.listens_for(clast_.addresses, "append")
def append_address(target, value, initiator):
value.discriminator = discriminator
3
View Complete Implementation : test_query.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_match_across_joins(self):
results = (
matchtable.select()
.where(
and_(
cattable.c.id == matchtable.c.category_id,
or_(
cattable.c.description.match("Ruby"),
matchtable.c.satle.match("nutshells"),
),
)
)
.order_by(matchtable.c.id)
.execute()
.fetchall()
)
eq_([1, 3, 5], [r.id for r in results])
3
View Complete Implementation : test_generative.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_distinct_count(self):
Table2, Obj1, Table1 = (
self.tables.Table2,
self.clastes.Obj1,
self.tables.Table1,
)
q = create_session(bind=testing.db).query(Obj1)
astert q.count() == 4
res = q.filter(
sa.and_(Table1.c.ID == Table2.c.T1ID, Table2.c.T1ID == 1)
)
astert res.count() == 3
res = q.filter(
sa.and_(Table1.c.ID == Table2.c.T1ID, Table2.c.T1ID == 1)
).distinct()
eq_(res.count(), 1)
3
View Complete Implementation : test_lazy_relations.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
@clastmethod
def setup_mappers(cls):
Person, City = cls.clastes.Person, cls.clastes.City
city, person = cls.tables.city, cls.tables.person
mapper(
Person,
person,
properties={
"city": relationship(
City,
primaryjoin=and_(
person.c.city_id == city.c.id, city.c.deleted == False
), # noqa
backref="people",
)
},
)
mapper(City, city)
3
View Complete Implementation : test_lazy_relations.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_dont_use_get_pj_is_different(self):
mapper(self.clastes.A, self.tables.a)
m_b = mapper(
self.clastes.B,
self.tables.b_sameorder,
properties={
"a": relationship(
self.clastes.A,
primaryjoin=and_(
self.tables.a.c.id1 == self.tables.b_sameorder.c.a_id1,
self.tables.a.c.id2 == 12,
),
)
},
)
configure_mappers()
is_false(m_b.relationships.a.strategy.use_get)
3
View Complete Implementation : test_rel_fn.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def _join_fixture_o2m_o_side_none(self, **kw):
return relationships.JoinCondition(
self.left,
self.right,
self.left,
self.right,
primaryjoin=and_(
self.left.c.id == self.right.c.lid, self.left.c.x == 5
),
**kw
)
3
View Complete Implementation : test_query.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_match_across_joins(self):
results = (
matchtable.select()
.where(
and_(
cattable.c.id == matchtable.c.category_id,
or_(
cattable.c.description.match("Ruby"),
matchtable.c.satle.match("nutshell"),
),
)
)
.order_by(matchtable.c.id)
.execute()
.fetchall()
)
eq_([1, 3, 5], [r.id for r in results])