Database

class passengersim.database.database.Database(engine: 'sqlite' | None = 'sqlite', filename=None, pragmas: Iterable[str] = (), commit_count_delay: int | None = 250, *, connection: Connection | None = None)[source]

Bases: object

A wrapper to manage transactions for PassengerSim on SQLite.

Methods

__init__([engine, filename, pragmas, ...])

add_indexes([fare_detail, leg_detail])

backup(dst[, show_progress])

Back up this database to another copy.

close()

Detach the writer; commit and close only a library-owned connection.

connect_to_simulation_engine(sim)

Attach the native writer to this connection without reopening it.

dataframe(query[, params, dtype])

Run a SQL query and return the results as a pandas DataFrame.

delete_experiment(name)

disconnect_from_simulation_engine()

Detach the writer while leaving the Python connection open.

index_names(table_name)

List of all named indexes on a given table.

load_configs([scenario, on_validation_error])

load_raw_configs([scenario])

open([filename])

Open the connection if it is not already open.

save_configs(cfg)

Save configs into the database.

save_dataframe(name, df[, if_exists])

Save a dataframe as a table in this database.

save_details(db_writer, sim, dcp)

Save details, can be done at each RRD/DCP and at the end of the run

save_final(sim)

schema(name)

Get a table schema from the SQLite database.

sql_placeholders(n)

A parenthesis enclosed set of n placeholders for the selected engine.

table_info(table_name)

Get info about a table

table_names()

List of all tables in the database.

use_sqlite()

Return True when this wrapper holds a SQLite connection.

Attributes

connection

The Python connection shared with the native writer.

database_path

Absolute main-database path, or None for memory/disabled connections.

is_open

property database_path

Absolute main-database path, or None for memory/disabled connections.

property connection : Connection | None

The Python connection shared with the native writer.

connect_to_simulation_engine(sim: SimulationEngine)[source]

Attach the native writer to this connection without reopening it.

disconnect_from_simulation_engine()[source]

Detach the writer while leaving the Python connection open.

open(filename: str | None = None)[source]

Open the connection if it is not already open.

close()[source]

Detach the writer; commit and close only a library-owned connection.

property is_open : bool
use_sqlite() → bool[source]

Return True when this wrapper holds a SQLite connection.

sql_placeholders(n: int)[source]

A parenthesis enclosed set of n placeholders for the selected engine.

delete_experiment(name: str)[source]
save_configs(cfg: Config) → None[source]

Save configs into the database.

load_raw_configs(scenario=None) → dict | Any[source]
load_configs(scenario=None, on_validation_error: 'raise' | 'ignore' = 'raise') → Config | Any[source]
save_details(db_writer: DbWriter, sim: SimulationEngine, dcp: int)[source]

Save details, can be done at each RRD/DCP and at the end of the run

save_final(sim: SimulationEngine)[source]
dataframe(query: str, params: list | tuple | dict | None = None, dtype=None)[source]

Run a SQL query and return the results as a pandas DataFrame.

schema(name: str)[source]

Get a table schema from the SQLite database.

save_dataframe(name: str, df: DataFrame, if_exists: 'fail' | 'replace' | 'append' = 'replace')[source]

Save a dataframe as a table in this database.

table_names() → list[str][source]

List of all tables in the database.

table_info(table_name: str) → DataFrame[source]

Get info about a table

index_names(table_name) → list[str][source]

List of all named indexes on a given table.

add_indexes(fare_detail=True, leg_detail=True)[source]
backup(dst: Path | str | Connection, show_progress: bool = True)[source]

Back up this database to another copy.