API Reference

Connect

aql.connect(location, *args, **kwargs)

Connect to the specified database.

Parameters:
  • location (str | Location)

  • args (Any)

  • kwargs (Any)

Return type:

Connection

Tables

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

Bases: object

Parameters:
ilike(value)
Parameters:

value (str)

Return type:

Comparison

in_(values)
Parameters:

values (Sequence[Any])

Return type:

Comparison

like(value)
Parameters:

value (str)

Return type:

Comparison

property full_name: str
class aql.table.Table(name, cons, source=None)

Bases: Generic[T]

Table specification using custom columns and a source type.

Parameters:
create(if_not_exists=False)

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

Parameters:

if_not_exists (bool)

Return type:

Query

delete()

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

Return type:

Query

insert(*columns)

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

Parameters:

columns (Column)

Return type:

Query

select(*columns)

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

Parameters:

columns (Column)

Return type:

Query

update(*comps, **values)

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

Parameters:
  • comps (Comparison)

  • values (Any)

Return type:

Query

Errors

exception aql.AqlError

Bases: Exception

exception aql.BuildError

Bases: AqlError

exception aql.QueryError

Bases: AqlError

Advanced

class aql.engines.base.Engine

Bases: object

prepare(query)

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.

Parameters:

query (Query[T])

Return type:

PreparedQuery[T]

class aql.engines.base.Connection(engine, location, *args, **kwargs)

Bases: object

Parameters:
  • engine (Engine)

  • location (Location)

  • args (Any)

  • kwargs (Any)

async abort()

Rollback/cancel the current transaction.

Return type:

None

async begin()

Begin a new transaction.

Return type:

None

async close()

Close the connection.

Return type:

None

async commit()

Commit the current transaction.

Return type:

None

async connect()

Initiate the connection.

Return type:

None

async cursor()

Return a new cursor object.

Return type:

Cursor

execute(query)

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

Parameters:

query (Query[T])

Return type:

Result[T]

classmethod get_connector(name)

Given a name, get a connector class.

Parameters:

name (str)

Return type:

Tuple[Type[Connection], Type[Engine]]

query(query)

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

Parameters:

query (Query[T])

Return type:

Result[T]

async rollback()

Rollback/cancel the current transaction.

Return type:

None

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

Bases: object

Parameters:
async close()

Close the cursor.

Return type:

None

convert(row)

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

Return type:

T

async execute(query, parameters=None)

Execute the given query with this cursor.

Parameters:
  • query (str)

  • parameters (Any | None)

Return type:

None

async fetchall()

Return all rows from the previous query.

Return type:

Sequence[Any]

async fetchone()

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

Return type:

Any | None

async query(query, parameters=None)

Execute the given query with this cursor.

Parameters:
  • query (str)

  • parameters (Any | None)

Return type:

None

property connection: Connection

Return the associated connection object.

property last_id: int | None

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

property row_count: int

Number of rows affected by previous query.

class aql.engines.base.Result(query, connection)

Bases: Generic[T]

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())
Parameters:
async row()
Return type:

T | None

async rows()
Return type:

Sequence[T]

async run()
Return type:

Cursor

property last_id: int | None

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

property row_count: int

Number of rows affected by previous query.