bout_runners.database.database_writer

Module containing the DatabaseWriter class.

Classes

DatabaseWriter(db_connector)

Class for writing to the schema of the database.

class bout_runners.database.database_writer.DatabaseWriter(db_connector: bout_runners.database.database_connector.DatabaseConnector)[source]

Class for writing to 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
>>> from bout_runners.database.database_creator import DatabaseCreator

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)

Write to the database

>>> db_writer = DatabaseWriter(db_connector)
>>> dummy_split_dict = {'number_of_processors': 1,
...                     'number_of_nodes': 2,
...                     'processors_per_node': 3}
>>> db_writer.create_entry('split', dummy_split_dict)
Attributes
db_connectorDatabaseConnector

The database object to write to

Methods

create_insert_string(field_names, table_name)

Create a question mark style string for database insertions

insert(insert_str, values)

Insert to the database

create_entry(table_name, entries_dict)

Create a database entry

Set the database to use.

Parameters
db_connectorDatabaseConnector

The database object to write to

Methods

create_entry(table_name, entries_dict)

Create a database entry.

create_insert_string(field_names, table_name)

Create a question mark style string for database insertions.

create_update_string(field_names, …)

Create a question mark style string for database update.

insert(insert_str, values)

Insert to the database.

update(update_str, values)

Insert to the database.

create_entry(table_name: str, entries_dict: Mapping[str, Optional[Union[int, str, float]]]) → None[source]

Create a database entry.

Parameters
table_namestr

Name of the table

entries_dictdict

Dictionary containing the entries as key value pairs

static create_insert_string(field_names: Sequence[str], table_name: str) → str[source]

Create a question mark style string for database insertions.

Values must be provided separately in the execution statement

Parameters
field_namesarray_like

Names of the fields to populate

table_namestr

Name of the table to use for the insertion

Returns
insert_strstr

The string to be used for insertion

static create_update_string(field_names: Tuple[str, ], table_name: str, search_condition: str) → str[source]

Create a question mark style string for database update.

Values must be provided separately in the execution statement

Parameters
field_namesarray_like

Names of the fields to populate

table_namestr

Name of the table to use for the update

search_conditionstr

Condition for the update Example

>>> 'id = 3 AND col = 42'
Returns
insert_strstr

The string to be used for update

insert(insert_str: str, values: Any) → None[source]

Insert to the database.

Parameters
insert_strstr

The write statement to execute

valuestuple

Values to be inserted in the query

Raises
ValueError

If the insert_str is not understood

update(update_str: str, values: Any) → None[source]

Insert to the database.

Parameters
update_strstr

The update statement to execute

valuestuple

Values to be inserted in the query

Raises
ValueError

If update_str is not understood