aequilibrae.utils.db_utils#

Functions

add_column(conn, table_name, col_name, col_type)

add_column_unless_exists(conn, table_name, ...)

get_schema(conn, table_name)

has_column(conn, table_name, col_name)

has_table(conn, table_name)

list_columns(conn, table_name)

list_tables_in_db(conn)

read_and_close(filepath[, spatial])

A context manager for sqlite connections (alias for commit_and_close(db,commit=False)).

read_sql(sql, filepath, **kwargs)

safe_connect(filepath[, missing_ok])

Classes

AequilibraEConnection(*args, **kwargs)

This custom factory class intends to solve the issue of premature commits when trying to use manual transaction control.

ColumnDef(idx, name, type, not_null, ...)

commit_and_close(db[, commit, missing_ok, ...])

A context manager for sqlite connections which closes and commits.

class aequilibrae.utils.db_utils.AequilibraEConnection(*args, **kwargs)[source]#

This custom factory class intends to solve the issue of premature commits when trying to use manual transaction control.

After manual_transaction is called, context manager enters and exits are tracked via their depth, the sqlite3.Connection is placed into manual transaction control and a transaction is started. If another transaction is already in progress an RuntimeError is raised. When exiting with depth == 0, the normal context manager enter and exit is called.

backup(target, *, pages=-1, progress=None, name='main', sleep=0.25)#

Makes a backup of the database.

close()#

Close the database connection.

Any pending transaction is not committed implicitly.

commit()#

Commit any pending transaction to the database.

If there is no open transaction, this method is a no-op.

create_aggregate(name, n_arg, aggregate_class)#

Creates a new aggregate.

create_collation(name, callback, /)#

Creates a collation function.

create_function(name, narg, func, *, deterministic=False)#

Creates a new function.

cursor()#

Return a cursor for the connection.

enable_load_extension(enable, /)#

Enable dynamic loading of SQLite extension modules.

execute()#

Executes an SQL statement.

executemany(sql, parameters, /)#

Repeatedly executes an SQL statement.

executescript(sql_script, /)#

Executes multiple SQL statements at once.

interrupt()#

Abort any pending database operation.

iterdump()#

Returns iterator to the dump of the database in an SQL text format.

load_extension(name, /)#

Load SQLite extension module.

manual_transaction()[source]#
rollback()#

Roll back to the start of any pending transaction.

If there is no open transaction, this method is a no-op.

set_authorizer(authorizer_callback)#

Sets authorizer callback.

set_progress_handler(progress_handler, n)#

Sets progress handler callback.

set_trace_callback(trace_callback)#

Sets a trace callback called for each SQL statement (passed as unicode).

DataError#
DatabaseError#
Error#
IntegrityError#
InterfaceError#
InternalError#
NotSupportedError#
OperationalError#
ProgrammingError#
Warning#
in_transaction#
isolation_level#
row_factory#
text_factory#
total_changes#
class aequilibrae.utils.db_utils.ColumnDef(idx: int, name: str, type: str, not_null: bool, default: str, is_pk: bool)[source]#
default: str#
idx: int#
is_pk: bool#
name: str#
not_null: bool#
type: str#
class aequilibrae.utils.db_utils.commit_and_close(db: str | Path | Connection, commit: bool = True, missing_ok: bool = False, spatial=False)[source]#

A context manager for sqlite connections which closes and commits.

aequilibrae.utils.db_utils.add_column(conn, table_name, col_name, col_type, constraints=None)[source]#
aequilibrae.utils.db_utils.add_column_unless_exists(conn, table_name, col_name, col_type, constraints=None)[source]#
aequilibrae.utils.db_utils.get_schema(conn, table_name)[source]#
aequilibrae.utils.db_utils.has_column(conn, table_name, col_name)[source]#
aequilibrae.utils.db_utils.has_table(conn, table_name)[source]#
aequilibrae.utils.db_utils.list_columns(conn, table_name)[source]#
aequilibrae.utils.db_utils.list_tables_in_db(conn: Connection)[source]#
aequilibrae.utils.db_utils.read_and_close(filepath, spatial=False)[source]#

A context manager for sqlite connections (alias for commit_and_close(db,commit=False)).

aequilibrae.utils.db_utils.read_sql(sql, filepath, **kwargs)[source]#
aequilibrae.utils.db_utils.safe_connect(filepath: PathLike, missing_ok=False)[source]#