Skip to content

Commit

Permalink
implement count functionality
Browse files Browse the repository at this point in the history
Signed-off-by: wiseaidev <business@wiseai.dev>
  • Loading branch information
wiseaidev committed Aug 8, 2022
1 parent dcd84e0 commit b16c1e0
Show file tree
Hide file tree
Showing 2 changed files with 12 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
9 changes: 9 additions & 0 deletions tests/test_hash_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ 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 == "Brookins") & (m.Member.last_name == "Brookins")).count()
assert count == 1
count = await m.Member.find(m.Member.first_name="Kim").count()
assert count == 1
count = await m.Member.find().count()
assert count == 3

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

0 comments on commit b16c1e0

Please sign in to comment.