diff --git a/aredis_om/model/model.py b/aredis_om/model/model.py index 92bb6f9a..268d4116 100644 --- a/aredis_om/model/model.py +++ b/aredis_om/model/model.py @@ -760,6 +760,9 @@ async def all(self, batch_size=10): return await query.execute() return await self.execute() + async def page(self, offset=0, limit=10): + return await self.copy(offset=offset, limit=limit).execute() + def sort_by(self, *fields: str): if not fields: return self diff --git a/tests/test_hash_model.py b/tests/test_hash_model.py index 0a79aa6b..171ab5eb 100644 --- a/tests/test_hash_model.py +++ b/tests/test_hash_model.py @@ -143,6 +143,23 @@ async def test_full_text_search_queries(members, m): assert actual == [member1, member3] +@py_test_mark_asyncio +async def test_pagination_queries(members, m): + member1, member2, member3 = members + + actual = await m.Member.find(m.Member.last_name == "Brookins").page() + + assert actual == [member1, member2] + + actual = await m.Member.find().page(1, 1) + + assert actual == [member2] + + actual = await m.Member.find().page(0, 1) + + assert actual == [member1] + + @py_test_mark_asyncio async def test_recursive_query_resolution(members, m): member1, member2, member3 = members