Add delete_many
to support for bulk deletes (#305)
* Add support for bulk deletes * linters * linters * fix review comments * update more-itertools version * poetry fix - maybe? * merge main & add more-itertools 8.14.0 * update poetry.lock * linters * fix test Co-authored-by: Chayim I. Kirshen <c@kirshen.com>
This commit is contained in:
parent
4661459ddd
commit
a00a68b414
5 changed files with 171 additions and 395 deletions
|
@ -16,6 +16,7 @@ from aredis_om import (
|
|||
Field,
|
||||
HashModel,
|
||||
Migrator,
|
||||
NotFoundError,
|
||||
QueryNotSupportedError,
|
||||
RedisModelError,
|
||||
)
|
||||
|
@ -591,6 +592,35 @@ async def test_saves_many(m):
|
|||
assert await m.Member.get(pk=member2.pk) == member2
|
||||
|
||||
|
||||
@py_test_mark_asyncio
|
||||
async def test_delete_many(m):
|
||||
member1 = m.Member(
|
||||
id=0,
|
||||
first_name="Andrew",
|
||||
last_name="Brookins",
|
||||
email="a@example.com",
|
||||
join_date=today,
|
||||
age=38,
|
||||
bio="This is the user bio.",
|
||||
)
|
||||
member2 = m.Member(
|
||||
id=1,
|
||||
first_name="Kim",
|
||||
last_name="Brookins",
|
||||
email="k@example.com",
|
||||
join_date=today,
|
||||
age=34,
|
||||
bio="This is the bio for Kim.",
|
||||
)
|
||||
members = [member1, member2]
|
||||
result = await m.Member.add(members)
|
||||
assert result == [member1, member2]
|
||||
result = await m.Member.delete_many(members)
|
||||
assert result == 2
|
||||
with pytest.raises(NotFoundError):
|
||||
await m.Member.get(pk=member1.pk)
|
||||
|
||||
|
||||
@py_test_mark_asyncio
|
||||
async def test_updates_a_model(members, m):
|
||||
member1, member2, member3 = members
|
||||
|
|
|
@ -299,6 +299,33 @@ async def test_saves_many_explicit_transaction(address, m):
|
|||
assert await m.Member.get(pk=member2.pk) == member2
|
||||
|
||||
|
||||
@py_test_mark_asyncio
|
||||
async def test_delete_many_implicit_pipeline(address, m):
|
||||
member1 = m.Member(
|
||||
first_name="Andrew",
|
||||
last_name="Brookins",
|
||||
email="a@example.com",
|
||||
join_date=today,
|
||||
address=address,
|
||||
age=38,
|
||||
)
|
||||
member2 = m.Member(
|
||||
first_name="Kim",
|
||||
last_name="Brookins",
|
||||
email="k@example.com",
|
||||
join_date=today,
|
||||
address=address,
|
||||
age=34,
|
||||
)
|
||||
members = [member1, member2]
|
||||
result = await m.Member.add(members)
|
||||
assert result == [member1, member2]
|
||||
result = await m.Member.delete_many(members)
|
||||
assert result == 2
|
||||
with pytest.raises(NotFoundError):
|
||||
await m.Member.get(pk=member2.pk)
|
||||
|
||||
|
||||
async def save(members):
|
||||
for m in members:
|
||||
await m.save()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue