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: str

The simulation UUID or alias.

Returns:

None

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: 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: str

the simulation identifier

name: str

the metadata key

Returns:

The matching metadata values.

get_simulation(sim_ref: str) Simulation[source]

Get the specified simulation from the database.

Parameters:
sim_ref: str

The simulation UUID or alias.

Returns:

The Simulation.

get_simulation_children(simulation: Simulation) list[dict][source]
get_simulation_children_ref(simulation: Simulation) list[SimulationReference][source]
get_simulation_data(query)[source]
get_simulation_parents(simulation: Simulation) list[dict][source]
get_simulation_parents_ref(simulation: Simulation) list[SimulationReference][source]
insert_simulation(simulation: Simulation) None[source]

Insert the given simulation into the database.

Parameters:
simulation: 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 = 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 tuple of (total_count, list of simulation data dicts).

list_simulations(meta_keys: list[str] | None = 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