Skip to content

Commit af6b109

Browse files
committed
Removed AsyncDatabase.fetch_results() + compat logic updated
1 parent 06386fa commit af6b109

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

peewee_async.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,6 @@ def execute_sql(self, *args, **kwargs):
298298
(str(args), str(kwargs)))
299299
return super().execute_sql(*args, **kwargs)
300300

301-
async def fetch_results(self, query, cursor):
302-
# TODO: Probably we don't need this method at all?
303-
# We might get here if we use older `Manager` interface.
304-
if isinstance(query, peewee.BaseModelSelect):
305-
return await AsyncQueryWrapper.make_for_all_rows(cursor, query)
306-
if isinstance(query, peewee.RawQuery):
307-
return await AsyncQueryWrapper.make_for_all_rows(cursor, query)
308-
assert False, "Unsupported type of query '%s', use AioModel instead" % type(query)
309-
310301
def connection(self) -> ConnectionContext:
311302
return ConnectionContext(self.aio_pool, self._task_data)
312303

@@ -324,16 +315,12 @@ async def aio_execute(self, query, fetch_results=None):
324315
325316
:param query: peewee query instance created with ``Model.select()``,
326317
``Model.update()`` etc.
327-
:param fetch_results: function with cursor param. It let you get data manually and don't need to close cursor
328-
It will be closed automatically
329-
:return: result depends on query type, it's the same as for sync
330-
``query.execute()``
318+
:param fetch_results: function with cursor param. It let you get data manually and
319+
don't need to close cursor It will be closed automatically.
320+
:return: result depends on query type, it's the same as for sync `query.execute()`
331321
"""
332322
sql, params = query.sql()
333-
if fetch_results is None:
334-
query_fetch_results = getattr(query, 'fetch_results', None)
335-
database_fetch_results = functools.partial(self.fetch_results, query)
336-
fetch_results = query_fetch_results or database_fetch_results
323+
fetch_results = fetch_results or getattr(query, 'fetch_results', None)
337324
return await self.aio_execute_sql(sql, params, fetch_results=fetch_results)
338325

339326

peewee_async_compat.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,23 @@ def _patch_query_with_compat_methods(query, async_query_cls):
4949
- aio_get (for SELECT)
5050
- aio_scalar (for SELECT)
5151
"""
52-
from peewee_async import AioModelSelect
52+
from peewee_async import AioModelSelect, AioModelUpdate, AioModelDelete, AioModelInsert
53+
54+
if getattr(query, 'aio_execute', None):
55+
# No need to patch
56+
return
57+
58+
if async_query_cls is None:
59+
if isinstance(query, peewee.RawQuery):
60+
async_query_cls = AioModelSelect
61+
if isinstance(query, peewee.SelectBase):
62+
async_query_cls = AioModelSelect
63+
elif isinstance(query, peewee.Update):
64+
async_query_cls = AioModelUpdate
65+
elif isinstance(query, peewee.Delete):
66+
async_query_cls = AioModelDelete
67+
elif isinstance(query, peewee.Insert):
68+
async_query_cls = AioModelInsert
5369

5470
query.aio_execute = partial(async_query_cls.aio_execute, query)
5571
query.fetch_results = partial(async_query_cls.fetch_results, query)
@@ -345,6 +361,7 @@ async def create_or_get(self, model_, **kwargs):
345361

346362
async def execute(self, query):
347363
"""Execute query asyncronously."""
364+
_patch_query_with_compat_methods(query, None)
348365
return await self.database.aio_execute(query)
349366

350367
async def prefetch(self, query, *subqueries, prefetch_type=peewee.PREFETCH_TYPE.JOIN):

0 commit comments

Comments
 (0)