bout_runners.database.database_creator

Module containing the DatabaseCreator class.

Classes

DatabaseCreator(db_connector)

Class for creating the schema of the database.

class bout_runners.database.database_creator.DatabaseCreator(db_connector: bout_runners.database.database_connector.DatabaseConnector)[source]

Class for creating the schema of the database.

Examples

Import dependencies

>>> from pathlib import Path
>>> from bout_runners.executor.bout_paths import BoutPaths
>>> from bout_runners.parameters.default_parameters import DefaultParameters
>>> from bout_runners.parameters.final_parameters import FinalParameters
>>> from bout_runners.database.database_connector import DatabaseConnector

Create the bout_paths object

>>> project_path = Path().joinpath('path', 'to', 'project')
>>> bout_inp_src_dir = Path().joinpath('path', 'to', 'source', 'BOUT.inp')
>>> bout_inp_dst_dir = Path().joinpath('path', 'to', 'destination', 'BOUT.inp')
>>> bout_paths = BoutPaths(project_path=project_path,
...                        bout_inp_src_dir=bout_inp_src_dir,
...                        bout_inp_dst_dir=bout_inp_dst_dir)

Obtain the parameters

>>> default_parameters = DefaultParameters(bout_paths)
>>> final_parameters = FinalParameters(default_parameters)
>>> final_parameters_dict = final_parameters.get_final_parameters()
>>> final_parameters_as_sql_types = \
...     final_parameters.cast_to_sql_type(final_parameters_dict)

Create the database

>>> db_connector = DatabaseConnector('name', project_path)
>>> db_creator = DatabaseCreator(db_connector)
>>> db_creator.create_all_schema_tables(final_parameters_as_sql_types)
Attributes
db_connectorDatabaseConnector

The database object to write to

Methods

create_all_schema_tables(parameters_as_sql_types)

Create the all the tables for a schema

get_create_table_statement(table_name, columns=None,

primary_key=’id’, foreign_keys=None)

Return a SQL string which can be used to create the table

_create_single_table(table_str)

Create a table in the database

_create_system_info_table()

Create a table for the system info

_create_split_table()

Create a table which stores the grid split

_create_file_modification_table()

Create a table for file modifications

_create_parameter_tables(parameters_as_sql_types)

Create a table for each BOUT.settings section and a join table

_create_run_table()

Create a table for the metadata_recorder of a run

Set the database to use.

Parameters
db_connectorDatabaseConnector

The database object to write to

Methods

create_all_schema_tables(parameters_as_sql_types)

Create the all the tables for a schema.

get_create_table_statement(table_name[, …])

Return a SQL string which can be used to create the table.

create_all_schema_tables(parameters_as_sql_types: Dict[str, Dict[str, str]]) → None[source]

Create the all the tables for a schema.

The database schema will be on normalized form, see [1] for a quick overview, and [2] for a slightly deeper explanation

Parameters
parameters_as_sql_typesdict

The dictionary on the form

>>> {'section': {'parameter': 'value_type'}}

References

1

https://www.databasestar.com/database-normalization/

2

http://www.bkent.net/Doc/simple5.htm

static get_create_table_statement(table_name: str, columns: Optional[Dict[str, str]] = None, primary_key: str = 'id', foreign_keys: Optional[Dict[str, Tuple[str, str]]] = None) → str[source]

Return a SQL string which can be used to create the table.

Parameters
table_namestr

Name of the table

columnsdict or None

Dictionary where the key is the column name and the value is the type

primary_keystr

Name of the primary key (the type is set to INTEGER)

foreign_keysdict or None

Dictionary where the key is the column in this table to be used as a foreign key and the value is the tuple consisting of (name_of_the_table, key_in_table) to refer to

Returns
create_statementstr

The SQL statement which creates table