From f6c76acf740a78a54a043a09ba7a6631bb582d26 Mon Sep 17 00:00:00 2001 From: wiseaidev Date: Tue, 9 Aug 2022 15:09:22 +0300 Subject: [PATCH 1/3] implement page function Signed-off-by: wiseaidev --- aredis_om/model/model.py | 3 +++ 1 file changed, 3 insertions(+) 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 From 20b46201002daa0f37b4678963888a282b98cd77 Mon Sep 17 00:00:00 2001 From: wiseaidev Date: Tue, 9 Aug 2022 15:13:23 +0300 Subject: [PATCH 2/3] add unit tests Signed-off-by: wiseaidev --- tests/test_hash_model.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_hash_model.py b/tests/test_hash_model.py index 0a79aa6b..a002cc16 100644 --- a/tests/test_hash_model.py +++ b/tests/test_hash_model.py @@ -143,6 +143,19 @@ 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 == [member1] + + @py_test_mark_asyncio async def test_recursive_query_resolution(members, m): member1, member2, member3 = members @@ -611,4 +624,3 @@ class Address(m.BaseHashModel): assert ( Address.redisearch_schema() == f"ON HASH PREFIX 1 {key_prefix} SCHEMA pk TAG SEPARATOR | a_string TAG SEPARATOR | a_full_text_string TAG SEPARATOR | a_full_text_string AS a_full_text_string_fts TEXT an_integer NUMERIC SORTABLE a_float NUMERIC" - ) From 09b0bf637f10ceed5bc3607b1485f21a88228848 Mon Sep 17 00:00:00 2001 From: wiseaidev Date: Wed, 10 Aug 2022 08:58:44 +0300 Subject: [PATCH 3/3] fix linter issues Signed-off-by: wiseaidev --- tests/test_hash_model.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_hash_model.py b/tests/test_hash_model.py index a002cc16..171ab5eb 100644 --- a/tests/test_hash_model.py +++ b/tests/test_hash_model.py @@ -151,7 +151,11 @@ async def test_pagination_queries(members, m): assert actual == [member1, member2] - actual = await m.Member.find().page(1,1) + actual = await m.Member.find().page(1, 1) + + assert actual == [member2] + + actual = await m.Member.find().page(0, 1) assert actual == [member1] @@ -624,3 +628,4 @@ class Address(m.BaseHashModel): assert ( Address.redisearch_schema() == f"ON HASH PREFIX 1 {key_prefix} SCHEMA pk TAG SEPARATOR | a_string TAG SEPARATOR | a_full_text_string TAG SEPARATOR | a_full_text_string AS a_full_text_string_fts TEXT an_integer NUMERIC SORTABLE a_float NUMERIC" + )