connection

aiomyorm.connection.Connection()

A async context manager to run a custom sql statement.

Creates new connection.Returns a Connection instance. You can also use this connection in ORM by specifying the conn parameter. If you have not set autocommit=True, you should commit manual by use conn.commit().

aiomyorm.connection.Transaction()

Get a connection to do atomic transaction.

This is a subclass of Connection and they have the same usage, and on exit, this connection will automatically commit or roll back on error. You can also use this connection in ORM by specifying the conn parameter. Example:

async whit connection.Transaction() as conn:
    await Table(tl1='abc',tl2=123).save(conn=conn)
aiomyorm.connection.close_db_connection()

Close connection with database.You may sometime need it.

aiomyorm.connection.execute(sql: str, args: Union[list, tuple, None] = (), conn: Optional[aiomyorm.connection.Connection] = None) → int

Execute a insert,update or delete query, and return the number of affected rows.You can use this method when you encounter a query that ORM cannot complete.

Parameters:
  • sql (str) – a sql statement, use ? as placeholder.
  • args (list or tuple) – argument in placeholder.
  • conn – use this parameter to specify a custom connection.
Returns:

(int) affected rows.

aiomyorm.connection.select(sql: str, args: Union[list, tuple, None] = (), conn: Optional[aiomyorm.connection.Connection] = None) → list

Execute a select query, and return a list of result.You can use this method when you encounter a query that ORM cannot complete

Parameters:
  • sql (str) – a sql statement, use ? as placeholder.
  • args (list or tuple) – argument in placeholder.
  • conn – use this parameter to specify a custom connection.
Returns:

(list) a list of result.