Skip to content

Commit 01e55db

Browse files
author
Ricardo
authored
Merge pull request #13 from cuenca-mx/asyncio
Asyncio
2 parents 92ab685 + 617cd5a commit 01e55db

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

mongoengine_plus/aio/async_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class AsyncDocument(Document):
88
meta = dict(
9-
allow_inheritance=True,
9+
abstract=True,
1010
queryset_class=AsyncQuerySet,
1111
)
1212

mongoengine_plus/aio/async_query_set.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55

66
class AsyncQuerySet(QuerySet):
7+
async def async_first(self):
8+
return await create_awaitable(self.first)
9+
710
async def async_get(self, *q_objs, **query):
811
return await create_awaitable(self.get, *q_objs, **query)
912

@@ -12,3 +15,6 @@ async def async_count(self, with_limit_and_skip=False):
1215

1316
async def async_to_list(self):
1417
return await create_awaitable(list, self)
18+
19+
async def async_update(self, *u_objs, **query):
20+
return await create_awaitable(self.update, *u_objs, **query)

mongoengine_plus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.2'
1+
__version__ = '0.0.3'

tests/aio/test_async_query_set.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,18 @@ async def test_to_list(cities):
2525
Q(state='Chiapas') | Q(state='Tabasco')
2626
).async_to_list()
2727
assert len(filtered) == 3
28+
29+
30+
@pytest.mark.asyncio
31+
async def test_first(cities):
32+
first_city = await City.objects(state='Tabasco').async_first()
33+
assert first_city.state == 'Tabasco'
34+
35+
36+
@pytest.mark.asyncio
37+
async def test_update(cities):
38+
await City.objects(name='San Cristobal').async_update(
39+
set__name='San Cristobal de las Casas'
40+
)
41+
sancris = await City.objects.async_get(name__contains='San Cristobal')
42+
assert sancris.name == 'San Cristobal de las Casas'

0 commit comments

Comments
 (0)