Skip to content

Commit

Permalink
implement count functionality
Browse files Browse the repository at this point in the history
Signed-off-by: wiseaidev <[email protected]>
  • Loading branch information
wiseaidev committed Aug 8, 2022
1 parent dcd84e0 commit 8b6fe19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions aredis_om/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ async def all(self, batch_size=10):
return await query.execute()
return await self.execute()

async def count(self, batch_size=10):
return len(await self.all(batch_size))

def sort_by(self, *fields: str):
if not fields:
return self
Expand Down
5 changes: 5 additions & 0 deletions tests/test_hash_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ async def members(m):

yield member1, member2, member3

@py_test_mark_asyncio
async def test_count_query(members, m):

count = await m.Member.find(m.Member.first_name="Kim").count()
assert count == 1

@py_test_mark_asyncio
async def test_exact_match_queries(members, m):
Expand Down

0 comments on commit 8b6fe19

Please sign in to comment.