bamboost.index.store
SQLAlchemy Core schema definitions and helper utilities for the BAMBOOST index database.
Attributes
- log=
BAMBOOST_LOGGER.getChild(__name__) - metadata=
MetaData() - collections_table=
Table(TABLENAME_COLLECTIONS, metadata, Column('uid', String, primary_key=True), Column('path', String, nullable=False), Column('created_at', DateTime, nullable=True), Column('description', String, nullable=False, default='', server_default=''), Column('tags', JSON, nullable=False, default=list, server_default='[]'), Column('aliases', JSON, nullable=False, default=list, server_default='[]'), Column('author', JSON, nullable=True, default=None, server_default='null')) - simulations_table=
Table(TABLENAME_SIMULATIONS, metadata, Column('id', Integer, primary_key=True, autoincrement=True), Column('collection_uid', String, ForeignKey(f'{TABLENAME_COLLECTIONS}.uid', ondelete='CASCADE')), Column('name', String, nullable=False), Column('created_at', DateTime, nullable=False, default=(datetime.now)), Column('modified_at', DateTime, nullable=False, default=(datetime.now)), Column('description', String, nullable=True), Column('tags', JSON, nullable=False, default=list, server_default='[]'), Column('status', String, nullable=False, default='initialized', server_default='initialized'), Column('submitted', Boolean, nullable=False, default=False, server_default='0'), UniqueConstraint('collection_uid', 'name', name='uix_collection_name')) - simulation_links_table=
Table(TABLENAME_SIMULATION_LINKS, metadata, Column('id', Integer, primary_key=True, autoincrement=True), Column('source_id', Integer, ForeignKey(f'{TABLENAME_SIMULATIONS}.id', ondelete='CASCADE'), nullable=False), Column('target_id', Integer, ForeignKey(f'{TABLENAME_SIMULATIONS}.id', ondelete='CASCADE'), nullable=False), Column('name', String, nullable=False), UniqueConstraint('source_id', 'name', name='uix_source_link_name')) - parameters_table=
Table(TABLENAME_PARAMETERS, metadata, Column('id', Integer, primary_key=True, autoincrement=True), Column('simulation_id', Integer, ForeignKey(f'{TABLENAME_SIMULATIONS}.id', ondelete='CASCADE'), nullable=False), Column('key', String, nullable=False), Column('value', JSON, nullable=False), UniqueConstraint('simulation_id', 'key', name='uix_simulation_key')) - _ENCODERS:
dict[type, typing.Callable[[typing.Any], typing.Any]]={datetime.datetime: lambda obj: obj.obj.isoformat(), complex: lambda obj: {'real': obj.obj.real, 'imag': obj.obj.imag}} - _DECODERS:
dict[type, typing.Callable[[typing.Any], typing.Any]]={datetime.datetime: datetime.datetime.datetime.datetime.fromisoformat, complex: lambda payload: complex(payload['real'], payload['imag'])}
Functions
(engine) -> NoneCreate all tables defined in this module.
Arguments:
- engine:
sqlalchemy.Engine
(value) -> strConvert a value to a JSON string.
Arguments:
- value:
typing.Any
(value) -> AnyConvert a JSON string to a Python value.
Arguments:
- value:
str
(data) -> InsertCreate an upsert statement for collections.
Arguments:
- data:
typing.Sequence[typing.Mapping[str, typing.Any]] | typing.Mapping[str, typing.Any]A single dictionary or a sequence of dictionaries representing the collections to be inserted or updated.
(data) -> ReturningInsert[Any]Create an upsert statement for simulations.
Arguments:
- data:
typing.Sequence[typing.Mapping[str, typing.Any]] | typing.Mapping[str, typing.Any]A single dictionary or a sequence of dictionaries representing the simulations to be inserted or updated.
Returns
sqlalchemy.sql.dml.ReturningInsert[typing.Any]A SQLAlchemy Insert statement with a RETURNING clause for the simulation IDs.(data) -> InsertArguments:
- data:
typing.Sequence[typing.Mapping[str, typing.Any]] | typing.Mapping[str, typing.Any]
(data) -> InsertArguments:
- data:
typing.Sequence[typing.Mapping[str, typing.Any]] | typing.Mapping[str, typing.Any]
(uid) -> DeleteArguments:
- uid:
str
(collection_uid, name) -> DeleteArguments:
- collection_uid:
str - name:
str
(source_id) -> DeleteArguments:
- source_id:
int
(session) -> tuple[str, ...]Fetch all collection UIDs without loading simulations.
Arguments:
- session:
sqlalchemy.orm.Session
(session, uid) -> CollectionRecord | NoneArguments:
- session:
sqlalchemy.orm.Session - uid:
str
(session) -> list[CollectionRecord]Arguments:
- session:
sqlalchemy.orm.Session
(session, alias) -> str | NoneArguments:
- session:
sqlalchemy.orm.Session - alias:
str
(session, collection_uid, simulation_name) -> None | intFetch the ID of a simulation given its collection UID and name.
Arguments:
- session:
sqlalchemy.orm.Session - collection_uid:
str - simulation_name:
str
(session, simulation_id) -> SimulationUID | NoneFetch the UID of a simulation given its ID.
Arguments:
- session:
sqlalchemy.orm.Session - simulation_id:
int
(session, collection_uid, name) -> SimulationRecord | NoneFetch a simulation given its collection UID and name.
Arguments:
- session:
sqlalchemy.orm.Session - collection_uid:
str - name:
str
(session, uids) -> list[SimulationRecord]Fetch multiple simulations by their collection UID and name.
Arguments:
- session:
sqlalchemy.orm.Session - uids:
typing.Sequence[tuple[str, str]]
(session, collection_uids=None) -> list[SimulationRecord]Fetch all simulations in the database.
Arguments:
- session:
sqlalchemy.orm.Session - collection_uids:
list[str] | None=None
(session) -> list[ParameterRecord]Arguments:
- session:
sqlalchemy.orm.Session
(session) -> list[LinkRecord]Arguments:
- session:
sqlalchemy.orm.Session
(session, collection_uid) -> list[LinkRecord]Fetch all links for a collection.
Arguments:
- session:
sqlalchemy.orm.Session - collection_uid:
str
(session, collection_uid) -> dict[str, dict[str, str]]Fetch all links for a collection as a mapping from simulation name to links.
Arguments:
- session:
sqlalchemy.orm.Session - collection_uid:
str
(session, collection_uid, simulation_name) -> Sequence[RowMapping]Fetch all simulations that link to the given simulation.
Arguments:
- session:
sqlalchemy.orm.Session - collection_uid:
str - simulation_name:
str
(engine, column) -> strBuild a SQLite-safe column definition for ALTER TABLE ADD COLUMN.
Arguments:
- engine:
sqlalchemy.Engine - column:
sqlalchemy.Column[typing.Any]
(column) -> str | NoneArguments:
- column:
sqlalchemy.Column[typing.Any]
(session, simulation_ids) -> dict[int, list[ParameterRecord]]Arguments:
- session:
sqlalchemy.orm.Session - simulation_ids:
typing.Iterable[int]
(session, simulation_ids) -> dict[int, dict[str, SimulationUID]]Arguments:
- session:
sqlalchemy.orm.Session - simulation_ids:
typing.Sequence[int]
(data, table) -> tuple[Sequence[dict[str, Any]] | dict[str, Any], bool]Ensure the payload is a list of dictionaries with only valid keys for the table.
Arguments:
- data:
typing.Sequence[typing.Mapping[str, typing.Any]] | typing.Mapping[str, typing.Any]A single dictionary or a sequence of dictionaries representing the records to be inserted or updated.
- table:
sqlalchemy.TableThe SQLAlchemy Table object representing the target database table.
Returns
tuple[typing.Sequence[dict[str, typing.Any]] | dict[str, typing.Any], bool]A tuple containing:
- A list of dictionaries (or a single dictionary if the input was a single record)
with keys filtered to match the table's columns.
- A boolean indicating whether the input was a single record (True) or
multiple records (False).(payload, excluded_keys) -> set[str]Collect the set of columns to be updated in an upsert operation.
Arguments:
- payload:
typing.Sequence[dict[str, typing.Any]] | dict[str, typing.Any]A single dictionary or a sequence of dictionaries representing the records to be inserted or updated.
- excluded_keys:
set[str]A set of keys to exclude from the update operation (e.g., primary keys).
Classes
ParameterRecord
(self, id, simulation_id, key, value) -> NoneArguments:
- id:
int - simulation_id:
int - key:
str - value:
typing.Any
Attributes:
- id:
int - simulation_id:
int - key:
str - value:
typing.Any
(cls, row) -> ParameterRecordArguments:
- cls
- row:
sqlalchemy.RowMapping
LinkRecord
(self, id, source_id, target_id, source_uid, name) -> NoneArguments:
- id:
int - source_id:
int - target_id:
int - source_uid:
SimulationUID - name:
str
Attributes:
- id:
int - source_id:
int - target_id:
int - source_uid:
SimulationUID - name:
str
(cls, row) -> LinkRecordArguments:
- cls
- row:
sqlalchemy.RowMapping
SimulationRecord
(self, id, collection_uid, name, created_at, modified_at, description, status, submitted, tags=list(), parameters=list(), links=dict()) -> NoneArguments:
- id:
int - collection_uid:
str - name:
str - created_at:
datetime.datetime - modified_at:
datetime.datetime - description:
str | None - status:
str - submitted:
bool - tags:
list[str]=list()
Attributes:
- id:
int - collection_uid:
str - name:
str - created_at:
datetime.datetime - modified_at:
datetime.datetime - description:
str | None - status:
str - submitted:
bool - parameter_dict:
dict[str, typing.Any]
(cls, row, parameters, links) -> SimulationRecordArguments:
- cls
- row:
sqlalchemy.RowMapping - parameters:
list[ParameterRecord] - links:
dict[str, SimulationUID]
(self, standalone=True, include_parameters=True, include_links=True) -> dict[str, Any]Arguments:
- standalone:
bool=True - include_parameters:
bool=True - include_links:
bool=True
CollectionMetadata
(self, uid, created_at=None, tags=list(), aliases=list(), author=None, description=None) -> NoneCollection metadata container. Can load/save from/to dicts, storing unknown fields in an extras dictionary.
Arguments:
- uid:
str - created_at:
datetime.datetime | None=None - tags:
list[str]=list() - aliases:
list[str]=list() - author:
str | dict | None=None - description:
str | None=None
Attributes:
- uid:
strUnique identifier of the collection.
- created_at:
datetime.datetime | None=field(default=None)Creation timestamp.
- aliases:
list[str]=field(default_factory=list)List of aliases for the collection.
- description:
str | None=field(default=None)Completely optional description of the collection.
- _extras:
dict[str, typing.Any]=field(default_factory=dict, init=False, repr=False)
(self) -> dict[str, Any](cls, data, *_) -> SelfCreate an instance from a dictionary, storing unknown fields in the extras dictionary.
Arguments:
- cls
- data:
dict[str, typing.Any]The input dictionary.
- _=
()
CollectionRecord
(self, uid, created_at=None, tags=list(), aliases=list(), author=None, description=None, path='', simulations=list()) -> NoneCollection record, including metadata and associated simulations. Used for exposing (read only) a record in the collection table in the sql database.
Arguments:
- uid:
str - created_at:
datetime.datetime | None=None - tags:
list[str]=list() - aliases:
list[str]=list() - author:
str | dict | None=None - description:
str | None=None - path:
str=''
Attributes:
- path:
str=field(default='')Path to the collection on disk. Guaranteed to be not null.
List of simulations associated with the collection.
- parameters:
list[ParameterRecord] - links:
dict[str, dict[str, SimulationUID]]Dictionary of links for each simulation in the collection.
Bases
(cls, row, simulations) -> CollectionRecordArguments:
- cls
- row:
sqlalchemy.RowMapping - simulations:
list[SimulationRecord]
(self) -> tuple[list[str], list[int]](self, flatten=True) -> 'DataFrame'Arguments:
- flatten:
bool=True
(self, filter, sorter) -> SelfSqliteJSONEncoder
JSON encoder that handles numpy and datetime types.
(self, obj) -> AnyArguments:
- obj:
typing.Any
Bamboost