diff --git a/aredis_om/model/model.py b/aredis_om/model/model.py index 92bb6f9a..0a38c5c1 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 count(self, batch_size=10): + return len(await self.all(batch_size)) + 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..3cdde680 100644 --- a/tests/test_hash_model.py +++ b/tests/test_hash_model.py @@ -95,6 +95,13 @@ 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 + count = await m.Member.find().count() + assert count == 3 @py_test_mark_asyncio async def test_exact_match_queries(members, m):