asyncqlio.backends.postgresql.asyncpg

The asyncpg connector for PostgreSQL databases.

Functions

get_param_query(sql, params) Re-does a SQL query so that it uses asyncpg’s special query format.

Classes

AsyncpgConnector(parsed) A connector that uses the asyncpg library.
AsyncpgResultSet(cur)
AsyncpgTransaction(conn) A transaction that uses the asyncpg library.
CONNECTOR_TYPE alias of asyncqlio.backends.postgresql.asyncpg.AsyncpgConnector
asyncqlio.backends.postgresql.asyncpg.get_param_query(sql, params)[source]

Re-does a SQL query so that it uses asyncpg’s special query format.

Parameters:
  • sql (str) – The SQL statement to use.
  • params (dict) – The dict of parameters to use.
Return type:

Tuple[str, tuple]

Returns:

A two-item tuple of (new_query, arguments)

class asyncqlio.backends.postgresql.asyncpg.AsyncpgResultSet(cur)[source]

Bases: asyncqlio.backends.base.BaseResultSet

keys
Return type:Iterable[str]
Returns:An iterable of keys that this query contained.
coroutine close()[source]

Closes this result set.

coroutine fetch_many(self, n)[source]

Fetches the next N rows in this query.

Parameters:n (int) – The number of rows to fetch.
coroutine fetch_row()[source]

Fetches the next row in this query.

This should return None if the row could not be fetched.

coroutine flatten(self)

Flattens this ResultSet.

Return type:List[DictRow]
Returns:A list of DictRow objects.
class asyncqlio.backends.postgresql.asyncpg.AsyncpgTransaction(conn)[source]

Bases: asyncqlio.backends.base.BaseTransaction

A transaction that uses the asyncpg library.

acquired_connection = None

The acquired connection from the connection pool.

transaction = None

The asyncpg internal transaction.

coroutine begin(**transaction_options)[source]

Begins the transaction.

coroutine close(self, *, has_error=False)[source]

Called at the end of a transaction to cleanup. The connection will be released if there’s no error; otherwise it will be closed.

Parameters:has_error (bool) – If the transaction has an error.
coroutine commit()[source]

Commits the transaction.

coroutine create_savepoint(self, name)[source]

Creates a savepoint in the current transaction.

Warning

This is not supported in all DB engines. If so, this will raise NotImplementedError.

Parameters:name (str) – The name of the savepoint to create.
coroutine cursor(self, sql, params=None)[source]

Executes a SQL statement and returns a cursor to iterate over the rows of the result.

Return type:AsyncpgResultSet
coroutine execute(self, sql, params=None)[source]

Executes SQL inside the transaction.

Parameters:
coroutine release_savepoint(self, name)[source]

Releases a savepoint in the current transaction.

Parameters:name (str) – The name of the savepoint to release.
coroutine rollback(self, checkpoint=None)[source]

Rolls back the transaction.

Parameters:checkpoint (Optional[str]) – If provided, the checkpoint to rollback to. Otherwise, the entire transaction will be rolled back.
class asyncqlio.backends.postgresql.asyncpg.AsyncpgConnector(parsed)[source]

Bases: asyncqlio.backends.base.BaseConnector

A connector that uses the asyncpg library.

pool = None

The asyncpg.pool.Pool connection pool.

emit_param(name)[source]

Emits a parameter that can be used as a substitute during a query.

Parameters:name (str) – The name of the parameter.
Return type:str
Returns:A string that represents the substitute to be placed in the query.
get_transaction()[source]

Gets a new transaction object for this connection.

Return type:AsyncpgTransaction
Returns:A new BaseTransaction object attached to this connection.
coroutine close()[source]

Closes the current Connector.

coroutine connect(self, *, loop=None)[source]

Connects the current connector to the database server. This is called automatically by the :class:`.DatabaseInterface

Return type:BaseConnector
Returns:The original BaseConnector instance.
coroutine get_db_server_version()[source]

Gets the version of the DB server running.

asyncqlio.backends.postgresql.asyncpg.CONNECTOR_TYPE

alias of asyncqlio.backends.postgresql.asyncpg.AsyncpgConnector