Database¶
-
class passengersim.database.database.Database(engine: 'sqlite' | None =
'sqlite', filename=None, pragmas: Iterable[str] =(), commit_count_delay: int | None =250)[source]¶ Bases:
objectA 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.
dataframe(query[, params, dtype])Run a SQL query and return the results as a pandas DataFrame.
delete_experiment(name)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.
A parenthesis enclosed set of n placeholders for the selected engine.
table_info(table_name)Get info about a table
List of all tables in the database.
Return True if the database engine is SQLite and the filename is not None.
Attributes
- 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.
-
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
-
dataframe(query: str, params: list | tuple | dict | None =
None, dtype=None)[source]¶ Run a SQL query and return the results as a pandas DataFrame.
-
save_dataframe(name: str, df: DataFrame, if_exists: 'fail' | 'replace' | 'append' =
'replace')[source]¶ Save a dataframe as a table in this 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.