simdb.database.database module

class simdb.database.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

session: Session
exception simdb.database.database.DatabaseError[source]

Bases: RuntimeError

class simdb.database.database.Session(session_factory, scopefunc=None)[source]

Bases: scoped_session

add(obj: Base, *args, **kwargs)[source]

Place an object into this _orm.Session.

Proxied for the _orm.Session class on behalf of the _orm.scoping.scoped_session class.

Objects that are in the transient state when passed to the _orm.Session.add() method will move to the pending state, until the next flush, at which point they will move to the persistent state.

Objects that are in the detached state when passed to the _orm.Session.add() method will move to the persistent state directly.

If the transaction used by the _orm.Session is rolled back, objects which were transient when they were passed to _orm.Session.add() will be moved back to the transient state, and will no longer be present within this _orm.Session.

See also

_orm.Session.add_all()

session_adding - at session_basics

commit()[source]

Flush pending changes and commit the current transaction.

Proxied for the _orm.Session class on behalf of the _orm.scoping.scoped_session class.

When the COMMIT operation is complete, all objects are fully expired, erasing their internal contents, which will be automatically re-loaded when the objects are next accessed. In the interim, these objects are in an expired state and will not function if they are detached from the Session. Additionally, this re-load operation is not supported when using asyncio-oriented APIs. The :paramref:`.Session.expire_on_commit` parameter may be used to disable this behavior.

When there is no transaction in place for the Session, indicating that no operations were invoked on this Session since the previous call to Session.commit(), the method will begin and commit an internal-only “logical” transaction, that does not normally affect the database unless pending flush changes were detected, but will still invoke event handlers and object expiration rules.

If 1.x-style use is in effect and there are currently SAVEPOINTs in progress via _orm.Session.begin_nested(), the operation will release the current SAVEPOINT but not commit the outermost database transaction.

If 2.0-style use is in effect via the :paramref:`_orm.Session.future` flag, the outermost database transaction is committed unconditionally, automatically releasing any SAVEPOINTs in effect.

When using legacy “autocommit” mode, this method is only valid to call if a transaction is actually in progress, else an error is raised. Similarly, when using legacy “subtransactions”, the method will instead close out the current “subtransaction”, rather than the actual database transaction, if a transaction is in progress.

See also

session_committing

unitofwork_transaction

asyncio_orm_avoid_lazyloads

delete(obj: Base)[source]

Mark an instance as deleted.

Proxied for the _orm.Session class on behalf of the _orm.scoping.scoped_session class.

The object is assumed to be either persistent or detached when passed; after the method is called, the object will remain in the persistent state until the next flush proceeds. During this time, the object will also be a member of the _orm.Session.deleted collection.

When the next flush proceeds, the object will move to the deleted state, indicating a DELETE statement was emitted for its row within the current transaction. When the transaction is successfully committed, the deleted object is moved to the detached state and is no longer present within this _orm.Session.

See also

session_deleting - at session_basics

query(obj: Base, *args, **kwargs) Any[source]

Return a new _query.Query object corresponding to this _orm.Session.

Proxied for the _orm.Session class on behalf of the _orm.scoping.scoped_session class.

rollback()[source]

Rollback the current transaction in progress.

Proxied for the _orm.Session class on behalf of the _orm.scoping.scoped_session class.

If no transaction is in progress, this method is a pass-through.

In 1.x-style use, this method rolls back the topmost database transaction if no nested transactions are in effect, or to the current nested transaction if one is in effect.

When 2.0-style use is in effect via the :paramref:`_orm.Session.future` flag, the method always rolls back the topmost database transaction, discarding any nested transactions that may be in progress.

See also

session_rollback

unitofwork_transaction

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