database

Classes

Database(database_file)

Wrapper for interacting with SQLite3 database.

class Database(database_file: str)[source]

Wrapper for interacting with SQLite3 database.

file

Database file name.

add_dataframe(table_name: str, dataframe: pandas.core.frame.DataFrame) None[source]

Adds data into specified table.

If table exists, then data is appended to the existing table.

Parameters
  • table_name – The name of the table.

  • dataframe – Data to add to table.

create_table(table_name: str, table_spec: Union[metrics.analysis.simulation.Simulation, metrics.analysis.analysis.Analysis]) None[source]

Creates table in connected database.

Parameters
  • table_name – The name of the table.

  • table_spec – Object specifying the table columns (Simulation or Analysis object).

delete_data_from_table(table_name: str) None[source]

Delete data in specified table if it exists.

Parameters

table_name – Name of the table.

drop_table(table_name: str) None[source]

Drop table.

Parameters

table_name – Name of the table.

execute_query(query: str) pandas.core.frame.DataFrame[source]

Execute query.

Parameters

query – Query to execute.

Returns

Dataframe with query results.

get_connection() sqlite3.Connection[source]

Obtains connection to a SQLite database.

Returns

Connection to the database file.

load_dataframe(table_name: str, key: str) pandas.core.frame.DataFrame[source]

Load data for specified simulation key.

Parameters
  • table_name – The name of the table.

  • key – Simulation key.

Returns

Selected data from the SQLite table.

static make_create_table_query(table_name: str, table_spec: Union[metrics.analysis.simulation.Simulation, metrics.analysis.analysis.Analysis]) str[source]

Return query string that creates the SQLite table.

Parameters
  • table_name – The name of the table.

  • table_spec – Object specifying the table columns (Simulation or Analysis object).

Returns

Query string for creating table.

static make_select_from_query(table_name: str, key: str) str[source]

Return query string that selects rows with the specified key.

Parameters
  • table_name – The name of the table.

  • key – Simulation key.

Returns

Query string for selecting from database table.