Implement page function (#339)
* implement page function Signed-off-by: wiseaidev <business@wiseai.dev> * add unit tests Signed-off-by: wiseaidev <business@wiseai.dev> * fix linter issues Signed-off-by: wiseaidev <business@wiseai.dev>
This commit is contained in:
parent
ac6a75be19
commit
e5e887229a
2 changed files with 20 additions and 0 deletions
|
@ -760,6 +760,9 @@ class FindQuery:
|
||||||
return await query.execute()
|
return await query.execute()
|
||||||
return await self.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):
|
def sort_by(self, *fields: str):
|
||||||
if not fields:
|
if not fields:
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -150,6 +150,23 @@ async def test_full_text_search_queries(members, m):
|
||||||
assert actual == [member1, member3]
|
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
|
@py_test_mark_asyncio
|
||||||
async def test_recursive_query_resolution(members, m):
|
async def test_recursive_query_resolution(members, m):
|
||||||
member1, member2, member3 = members
|
member1, member2, member3 = members
|
||||||
|
|
Loading…
Reference in a new issue