Exemplo n.º 1
0
    def test_limit(self):
        for x in range(4):
            self._identifier()

        qu = self._db.query(Identifier)
        eq_(qu.count(), fast_query_count(qu))

        qu2 = qu.limit(2)
        eq_(qu2.count(), fast_query_count(qu2))

        qu3 = qu.limit(6)
        eq_(qu3.count(), fast_query_count(qu3))
Exemplo n.º 2
0
    def test_distinct(self):
        e1 = self._edition(title="The title", authors="Author 1")
        e2 = self._edition(title="The title", authors="Author 1")
        e3 = self._edition(title="The title", authors="Author 2")
        e4 = self._edition(title="Another title", authors="Author 1")

        # Without the distinct clause, a query against Edition will
        # return four editions.
        qu = self._db.query(Edition)
        eq_(qu.count(), fast_query_count(qu))

        # If made distinct on Edition.author, the query will return only
        # two editions.
        qu2 = qu.distinct(Edition.author)
        eq_(qu2.count(), fast_query_count(qu2))

        # If made distinct on Edition.title _and_ Edition.author,
        # the query will return three editions.
        qu3 = qu.distinct(Edition.title, Edition.author)
        eq_(qu3.count(), fast_query_count(qu3))
Exemplo n.º 3
0
 def test_no_distinct(self):
     identifier = self._identifier()
     qu = self._db.query(Identifier)
     eq_(1, fast_query_count(qu))
Exemplo n.º 4
0
 def apply(self, q):
     """Modify the given query with OFFSET and LIMIT."""
     self.query_size = fast_query_count(q)
     return q.offset(self.offset).limit(self.size)