Database

class passengersim.database.database.Database(engine: 'sqlite' | None = 'sqlite', filename=None, pragmas: Iterable[str] = (), commit_count_delay: int | None = 250)[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()

Flush pending operations and close the connection.

connect_to_simulation_engine(sim)

dataframe(query[, params, dtype])

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

delete_experiment(name)

disconnect_from_simulation_engine()

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 if the database engine is SQLite and the filename is not None.

Attributes

is_open

connect_to_simulation_engine(sim: SimulationEngine)[source]
disconnect_from_simulation_engine()[source]
open(filename: str | None = None)[source]

Open the connection if it is not already open.

close()[source]

Flush pending operations and close the connection.

property is_open : bool
use_sqlite() bool[source]

Return True if the database engine is SQLite and the filename is not None.

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.