Skip to content

aimbat.db

Module to define the AIMBAT project file and create the database engine.

Attributes:

Name Type Description
engine

AIMBAT database engine.

engine module-attribute

engine = create_engine(url=db_url, echo=False)

AIMBAT database engine.

set_sqlite_pragma

set_sqlite_pragma(
    dbapi_connection: Connection,
    connection_record: ConnectionPoolEntry,
) -> None

Enables foreign key support for SQLite connections.

Source code in src/aimbat/db.py
@event.listens_for(engine, "connect")
def set_sqlite_pragma(
    dbapi_connection: sqlite3.Connection, connection_record: ConnectionPoolEntry
) -> None:
    """Enables foreign key support for SQLite connections."""
    cursor = dbapi_connection.cursor()
    cursor.execute("PRAGMA foreign_keys=ON")
    cursor.close()