Low-level (older) API¶
Note: all query methods are coroutines.
Select, update, delete¶
-
peewee_async.
execute
(query)¶ Execute SELECT, INSERT, UPDATE or DELETE query asyncronously.
Parameters: query – peewee query instance created with Model.select()
,Model.update()
etc.Returns: result depends on query type, it’s the same as for sync query.execute()
-
peewee_async.
get_object
(source, *args)¶ Get object asynchronously.
Parameters: - source – mode class or query to get object from
- args – lookup parameters
Returns: model instance or raises
peewee.DoesNotExist
if object not found
-
peewee_async.
create_object
(model, **data)¶ Create object asynchronously.
Parameters: - model – mode class
- data – data for initializing object
Returns: new object saved to database
-
peewee_async.
delete_object
(obj, recursive=False, delete_nullable=False)¶ Delete object asynchronously.
Parameters: - obj – object to delete
- recursive – if
True
also delete all other objects depends on object - delete_nullable – if True and delete is recursive then delete even ‘nullable’ dependencies
For details please check out Model.delete_instance() in peewee docs.
-
peewee_async.
update_object
(obj, only=None)¶ Update object asynchronously.
Parameters: - obj – object to update
- only – list or tuple of fields to updata, is None then all fields updated
- This function does the same as Model.save() for already saved object,
- but it doesn’t invoke
save()
method on model class. That is important to know if you overrided save method for your model.
-
peewee_async.
prefetch
(sq, *subqueries)¶ Asynchronous version of the prefetch() from peewee.
Transactions¶
Transactions required Python 3.5+ to work, because their syntax is based on async context managers.
Important note transactions rely on data isolation on asyncio per-task basis. That means, all queries for single transaction should be performed within same task.
-
peewee_async.
atomic
(db)¶ Asynchronous context manager (async with), similar to peewee.atomic().
-
peewee_async.
savepoint
(db, sid=None)¶ Asynchronous context manager (async with), similar to peewee.savepoint().
-
peewee_async.
transaction
(db)¶ Asynchronous context manager (async with), similar to peewee.transaction(). Will start new asyncio task for transaction if not started already.
Aggregation¶
-
peewee_async.
count
(query, clear_limit=False)¶ Perform COUNT aggregated query asynchronously.
Returns: number of objects in select()
query
-
peewee_async.
scalar
(query, as_tuple=False)¶ Get single value from
select()
query, i.e. for aggregation.Returns: result is the same as after sync query.scalar()
call
Databases¶
-
class
peewee_async.
PostgresqlDatabase
(database, thread_safe=True, autorollback=False, field_types=None, operations=None, autocommit=None, **kwargs) PosgreSQL database driver providing single drop-in sync connection and single async connection interface.
Example:
database = PostgresqlDatabase('test')
See also: http://peewee.readthedocs.io/en/latest/peewee/api.html#PostgresqlDatabase
-
atomic_async
() Similar to peewee Database.atomic() method, but returns asynchronous context manager.
-
connect_async
(loop=None, timeout=None) Set up async connection on specified event loop or on default event loop.
-
savepoint_async
(sid=None) Similar to peewee Database.savepoint() method, but returns asynchronous context manager.
-
transaction_async
() Similar to peewee Database.transaction() method, but returns asynchronous context manager.
-
-
class
peewee_async.
PooledPostgresqlDatabase
(database, thread_safe=True, autorollback=False, field_types=None, operations=None, autocommit=None, **kwargs) PosgreSQL database driver providing single drop-in sync connection and async connections pool interface.
Parameters: max_connections – connections pool size Example:
database = PooledPostgresqlDatabase('test', max_connections=20)
See also: http://peewee.readthedocs.io/en/latest/peewee/api.html#PostgresqlDatabase
-
connect_async
(loop=None, timeout=None) Set up async connection on specified event loop or on default event loop.
-
-
class
peewee_asyncext.
PostgresqlExtDatabase
(*args, **kwargs) PosgreSQL database extended driver providing single drop-in sync connection and single async connection interface.
JSON fields support is always enabled, HStore supports is enabled by default, but can be disabled with
register_hstore=False
argument.Example:
database = PostgresqlExtDatabase('test', register_hstore=False)
See also: https://peewee.readthedocs.io/en/latest/peewee/
playhouse.html#PostgresqlExtDatabase-
atomic_async
() Similar to peewee Database.atomic() method, but returns asynchronous context manager.
-
connect_async
(loop=None, timeout=None) Set up async connection on specified event loop or on default event loop.
-
savepoint_async
(sid=None) Similar to peewee Database.savepoint() method, but returns asynchronous context manager.
-
transaction_async
() Similar to peewee Database.transaction() method, but returns asynchronous context manager.
-
-
class
peewee_asyncext.
PooledPostgresqlExtDatabase
(*args, **kwargs) PosgreSQL database extended driver providing single drop-in sync connection and async connections pool interface.
JSON fields support is always enabled, HStore supports is enabled by default, but can be disabled with
register_hstore=False
argument.Parameters: max_connections – connections pool size Example:
database = PooledPostgresqlExtDatabase('test', register_hstore=False, max_connections=20)
See also: https://peewee.readthedocs.io/en/latest/peewee/
playhouse.html#PostgresqlExtDatabase-
connect_async
(loop=None, timeout=None) Set up async connection on specified event loop or on default event loop.
-