simdb.database package

Database module.

The database module contains the code for creating and interacting with the database. Using SQLAlchemy the code can be used with various types of databases including SQLite and PostgreSQL.

class simdb.database.Database(db_type: DBMS, scopefunc=None, **kwargs)[source]

Bases: object

Class to wrap the database access.

class DBMS(value)[source]

Bases: Enum

DBMSs supported.

MSSQL = 3
POSTGRESQL = 2
SQLITE = 1
add_watcher(sim_ref: str, watcher: Watcher)[source]
close()[source]

Close the database session and dispose of the engine.

delete_simulation(sim_ref: str) Simulation[source]

Delete the specified simulation from the database.

Parameters:

sim_ref – The simulation UUID or alias.

Returns:

None

engine: sqlalchemy.engine.Engine
get_aliases(prefix: str | None) List[str][source]
get_file(file_uuid_str: str) File[source]

Get the specified file from the database.

Parameters:

file_uuid_str – The string representation of the file UUID.

Returns:

The File.

get_metadata(sim_ref: str, name: str) List[str][source]

Get all the metadata for the given simulation with the given key.

Parameters:
  • sim_ref – the simulation identifier

  • name – the metadata key

Returns:

The matching MetaData.

get_simulation(sim_ref: str) Simulation[source]

Get the specified simulation from the database.

Parameters:

sim_ref – The simulation UUID or alias.

Returns:

The Simulation.

get_simulation_children(simulation: Simulation) List[dict][source]
get_simulation_data(query)[source]
get_simulation_parents(simulation: Simulation) List[dict][source]
insert_simulation(simulation: Simulation) None[source]

Insert the given simulation into the database.

Parameters:

simulation – The Simulation to insert.

Returns:

None

list_files() List[File][source]

Return a list of all the files stored in the database.

Returns:

A list of Files.

list_metadata_keys() List[dict][source]
list_metadata_values(name: str) List[str][source]
list_simulation_data(meta_keys: List[str] = None, limit: int = 0, page: int = 1, sort_by: str = '', sort_asc: bool = False) Tuple[int, List[dict]][source]

Return a list of all the simulations stored in the database.

Returns:

A list of Simulations.

list_simulations(meta_keys: List[str] = None, limit: int = 0) List[Simulation][source]

Return a list of all the simulations stored in the database.

Returns:

A list of Simulations.

list_watchers(sim_ref: str) List[Watcher][source]
query_meta(constraints: List[Tuple[str, str, QueryType]]) List[Simulation][source]

Query the metadata and return matching simulations.

Returns:

query_meta_data(constraints: List[Tuple[str, str, QueryType]], meta_keys: List[str], limit: int = 0, page: int = 1, sort_by: str = '', sort_asc: bool = False) Tuple[int, List[dict]][source]

Query the metadata and return matching simulations.

Returns:

remove()[source]

Remove the current session

remove_watcher(sim_ref: str, username: str)[source]
reset() None[source]

Clear all the data out of the database.

Returns:

None

exception simdb.database.DatabaseError[source]

Bases: RuntimeError

simdb.database.get_local_db(config: Config) Database[source]

Subpackages

Submodules