Пример #1
0
    def test_apply_min(self):
        """Query.apply_min(col)

        min = session.query(Address).apply_min(Address.bounces)

        """
        session = create_session()

        # 0.5.0
        mins = list(session.query(Address).values(func.min(Address.bounces)))
        min = mins[0][0]
        assert min == 0

        min = session.query(func.min(Address.bounces)).one()[0]
        assert min == 0
Пример #2
0
    def test_apply_min(self):
        """Query.apply_min(col)

        min = session.query(Address).apply_min(Address.bounces)

        """
        session = create_session()

        # 0.5.0
        mins = list(session.query(Address).values(func.min(Address.bounces)))
        min = mins[0][0]
        assert min == 0

        min = session.query(func.min(Address.bounces)).one()[0]
        assert min == 0
Пример #3
0
 def test_aggregate(self):
     sess = create_session()
     query = sess.query(Foo)
     assert query.count() == 100
     assert sess.query(func.min(foo.c.bar)).filter(foo.c.bar<30).one() == (0,)
     
     assert sess.query(func.max(foo.c.bar)).filter(foo.c.bar<30).one() == (29,)
     assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29
     assert query.filter(foo.c.bar<30).values(sa.func.max(foo.c.bar)).next()[0] == 29
Пример #4
0
    def test_aggregate(self):
        sess = create_session()
        query = sess.query(Foo)
        assert query.count() == 100
        assert sess.query(func.min(
            foo.c.bar)).filter(foo.c.bar < 30).one() == (0, )

        assert sess.query(func.max(
            foo.c.bar)).filter(foo.c.bar < 30).one() == (29, )
        assert query.filter(foo.c.bar < 30).values(sa.func.max(
            foo.c.bar)).next()[0] == 29
        assert query.filter(foo.c.bar < 30).values(sa.func.max(
            foo.c.bar)).next()[0] == 29