simdb.database.database module¶
-
class simdb.database.database.Database(db_type: DBMS, scopefunc=
None, **kwargs)[source]¶ Bases:
objectClass to wrap the database access.
- delete_simulation(sim_ref: str) Simulation[source]¶
Delete the specified simulation from the database.
- engine : Engine¶
- get_file(file_uuid_str: str) File[source]¶
Get the specified file from the database.
- get_metadata(sim_ref: str, name: str) list[str][source]¶
Get all the metadata for the given simulation with the given key.
- get_simulation(sim_ref: str) Simulation[source]¶
Get the specified simulation from the database.
- get_simulation_children(simulation: Simulation) list[dict][source]¶
- get_simulation_children_ref(simulation: Simulation) list[SimulationReference][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_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.
- query_meta(constraints: list[tuple[str, str, QueryType]]) list[Simulation][source]¶
Query the metadata and return matching simulations.
- Returns:¶
- exception simdb.database.database.DatabaseOutdatedError[source]¶
Bases:
DatabaseError
- exception simdb.database.database.DatabaseUninitializedError[source]¶
Bases:
DatabaseError
-
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.Sessionclass on behalf of the_orm.scoping.scoped_sessionclass.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.Sessionis 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.Sessionclass on behalf of the_orm.scoping.scoped_sessionclass.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 thisSessionsince the previous call toSession.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.Sessionclass on behalf of the_orm.scoping.scoped_sessionclass.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.deletedcollection.When the next flush proceeds, the object will move to the deleted state, indicating a
DELETEstatement 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
- execute(query: Any, *args, **kwargs) Any[source]¶
Execute a SQL expression construct.
Proxied for the
_orm.Sessionclass on behalf of the_orm.scoping.scoped_sessionclass.Returns a
_engine.Resultobject representing results of the statement execution.E.g.:
from sqlalchemy import select result = session.execute( select(User).where(User.id == 5) )The API contract of
_orm.Session.execute()is similar to that of_future.Connection.execute(), the 2.0 style version of_future.Connection.Changed in version 1.4: the
_orm.Session.execute()method is now the primary point of ORM statement execution when using 2.0 style ORM usage.- Parameters:¶
- statement
An executable statement (i.e. an
Executableexpression such as_expression.select()).- params
Optional dictionary, or list of dictionaries, containing bound parameter values. If a single dictionary, single-row execution occurs; if a list of dictionaries, an “executemany” will be invoked. The keys in each dictionary must correspond to parameter names present in the statement.
- execution_options
optional dictionary of execution options, which will be associated with the statement execution. This dictionary can provide a subset of the options that are accepted by
_engine.Connection.execution_options(), and may also provide additional options understood only in an ORM context.- bind_arguments
dictionary of additional arguments to determine the bind. May include “mapper”, “bind”, or other custom arguments. Contents of this dictionary are passed to the
Session.get_bind()method.- mapper
deprecated; use the bind_arguments dictionary
- bind
deprecated; use the bind_arguments dictionary
- **kw
deprecated; use the bind_arguments dictionary
- Returns:¶
a
_engine.Resultobject.
- query(obj: Base, *args, **kwargs) Any[source]¶
Return a new
_query.Queryobject corresponding to this_orm.Session.Proxied for the
_orm.Sessionclass on behalf of the_orm.scoping.scoped_sessionclass.
- rollback()[source]¶
Rollback the current transaction in progress.
Proxied for the
_orm.Sessionclass on behalf of the_orm.scoping.scoped_sessionclass.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.check_migrations(engine) str[source]¶
Check that the database is up-to-date with the latest Alembic migration.
Raises
DatabaseUninitializedErrorif the database has not been initialised at all (i.e. thealembic_versiontable is absent), orDatabaseOutdatedErrorif the database schema is behind the head revision.