Skip to content

Commit fa95061

Browse files
author
Ricardo Sánchez
committed
Adding async_first and abstract base class
1 parent 3129d4a commit fa95061

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

mongoengine_plus/aio/async_query_set.py

Lines changed: 3 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

mongoengine_plus/models/base.py

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

55

66
class BaseModel:
7+
meta = {
8+
'abstract': True,
9+
}
710
_excluded: ClassVar = []
811
_hidden: ClassVar = []
912

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.dev0'

tests/aio/test_async_query_set.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ 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'

0 commit comments

Comments
 (0)