Skip to content

enhancement: find().count() #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
delete when exists keys to delete
  • Loading branch information
tomcounsell committed Jul 18, 2022
commit ee3fd302bfc9f3a9ea661fdbde04332cd8cd6ad4
5 changes: 4 additions & 1 deletion aredis_om/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,10 @@ async def update(self, use_transaction=True, **field_values):
async def delete(self):
"""Delete all matching records in this query."""
# TODO: Better response type, error detection
return await self.model.db().delete(*[m.key() for m in await self.all()])
keys_to_delete = [m.key() for m in await self.all()]
if not keys_to_delete:
return 0
return await self.model.db().delete(*keys_to_delete)

async def __aiter__(self):
if self._model_cache:
Expand Down