API Reference

Connect

aql.connect(location: Union[str, aql.types.Location], *args: Any, **kwargs: Any)aql.engines.base.Connection

Connect to the specified database.

Tables

class aql.column.Column(name: str, ctype: Type = None, default: Any = <object object>, table_name: str = '')

Bases: object

ilike(value: str) → aql.types.Comparison
in_(values: Sequence[Any]) → aql.types.Comparison
like(value: str) → aql.types.Comparison
property full_name
class aql.table.Table(name: str, cons: Iterable[Union[aql.column.Column, aql.column.Index]], source: Type[T] = None)

Bases: typing.Generic

Table specification using custom columns and a source type.

create(if_not_exists: bool = False) → aql.query.Query

Shortcut for Query(<table>).create()

delete() → aql.query.Query

Shortcut for Query(<table>).delete()

insert(*columns: aql.column.Column) → aql.query.Query

Shortcut for Query(<table>).insert()

select(*columns: aql.column.Column) → aql.query.Query

Shortcut for Query(<table>).select()

update(*comps: aql.types.Comparison, **values: Any) → aql.query.Query

Shortcut for Query(<table>).update()

Errors

exception aql.AqlError

Bases: Exception

exception aql.BuildError

Bases: aql.errors.AqlError

exception aql.QueryError

Bases: aql.errors.AqlError

Advanced

class aql.engines.base.Engine

Bases: object

prepare(query: aql.query.Query[~ T][T]) → aql.query.PreparedQuery[~T][T]

Given a query, generate the full SQL query and all parameters.

Default behavior is to call the method on the engine class corresponding to the query action.

class aql.engines.base.Connection(engine: aql.engines.base.Engine, location: aql.types.Location, *args: Any, **kwargs: Any)

Bases: object

async abort()None

Rollback/cancel the current transaction.

async begin()None

Begin a new transaction.

async close()None

Close the connection.

async commit()None

Commit the current transaction.

async connect()None

Initiate the connection.

async cursor()aql.engines.base.Cursor

Return a new cursor object.

execute(query: aql.query.Query[~ T][T]) → aql.engines.base.Result[~T][T]

Execute the given query on a new cursor and return the cursor.

classmethod get_connector(name: str) → Tuple[Type[aql.engines.base.Connection], Type[aql.engines.base.Engine]]

Given a name, get a connector class.

query(query: aql.query.Query[~ T][T]) → aql.engines.base.Result[~T][T]

Execute the given query on a new cursor and return the cursor.

async rollback()None

Rollback/cancel the current transaction.

property autocommit
class aql.engines.base.Cursor(connection: aql.engines.base.Connection, cursor: Any)

Bases: object

async close()None

Close the cursor.

convert(row) → T

Convert from the cursor’s native data type to the query object type.

async execute(query: str, parameters: Any = None)None

Execute the given query with this cursor.

async fetchall() → Sequence[Any]

Return all rows from the previous query.

async fetchone() → Optional[Any]

Return the next row from the previous query, or None when exhausted.

async query(query: str, parameters: Any = None)None

Execute the given query with this cursor.

property connection

Return the associated connection object.

property last_id

ID of last modified row, or None if not available.

property row_count

Number of rows affected by previous query.

class aql.engines.base.Result(query: aql.query.Query[~ T][T], connection: aql.engines.base.Connection)

Bases: typing.Generic

Lazy awaitable or async-iterable object that runs the query once awaited.

Awaiting the result object will fetch and convert all rows to appropriate objects. Iterating the result will fetch and convert individual rows at a time.

Examples:

result = db.execute(Foo.select())
# query not yet executed
rows = await result
# query executed and any resulting rows returned
print(result.row_count)

async for row in db.execute(Foo.select()):
    ...

rows = await db.execute(Foo.select())
async row() → Optional[T]
async rows() → Sequence[T]
async run()aql.engines.base.Cursor
property last_id

ID of last modified row, or None if not available.

property row_count

Number of rows affected by previous query.