sqlite_utilities

SQLite-specific utility functions for use in graphnet.data.

graphnet.data.sqlite.sqlite_utilities.database_exists(database_path)[source]

Check whether database exists at database_path.

Return type:

bool

Parameters:

database_path (str) –

graphnet.data.sqlite.sqlite_utilities.database_table_exists(database_path, table_name)[source]

Check whether table_name exists in database at database_path.

Return type:

bool

Parameters:
  • database_path (str) –

  • table_name (str) –

graphnet.data.sqlite.sqlite_utilities.run_sql_code(database_path, code)[source]

Execute SQLite code.

Parameters:
  • database_path (str) – Path to databases

  • code (str) – SQLite code

Return type:

None

graphnet.data.sqlite.sqlite_utilities.save_to_sql(df, table_name, database_path)[source]

Save a dataframe df to a table table_name in SQLite database.

Table must exist already.

Parameters:
  • df (DataFrame) – Dataframe with data to be stored in sqlite table

  • table_name (str) – Name of table. Must exist already

  • database_path (str) – Path to SQLite database

Return type:

None

graphnet.data.sqlite.sqlite_utilities.attach_index(database_path, table_name, index_column)[source]

Attach the table (i.e., event) index.

Important for query times!

Return type:

None

Parameters:
  • database_path (str) –

  • table_name (str) –

  • index_column (str) –

graphnet.data.sqlite.sqlite_utilities.create_table(columns, table_name, database_path, *, index_column, default_type NULL', integer_primary_key)[source]

Create a table.

Parameters:
  • columns (List[str]) – Column names to be created in table.

  • table_name (str) – Name of the table.

  • database_path (str) – Path to the database.

  • index_column (str, default: 'event_no') – Name of the index column.

  • default_type (str, default: 'NOT NULL') – The type used for all non-index columns.

  • integer_primary_key (bool, default: True) – Whether or not to create the index_column with the INTEGER PRIMARY KEY type. Such a column is required to have unique, integer values for each row. This is appropriate when the table has one row per event, e.g., event-level MC truth. It is not appropriate for pulse map series, particle-level MC truth, and other such data that is expected to have more that one row per event (i.e., with the same index).

Return type:

None

graphnet.data.sqlite.sqlite_utilities.create_table_and_save_to_sql(df, table_name, database_path, *, index_column, default_type NULL', integer_primary_key)[source]

Create table if it doesn’t exist and save dataframe to it.

Return type:

None

Parameters:
  • df (DataFrame) –

  • table_name (str) –

  • database_path (str) –

  • index_column (str) –

  • default_type (str) –

  • integer_primary_key (bool) –