Bamboost
bamboostindexstore

bamboost.index.store

SQLAlchemy Core helper utilities for the BAMBOOST index database.

Attributes

  • __all__=['collections_table', 'create_all', 'collections_upsert_stmt', 'simulations_upsert_stmt', 'parameters_upsert_stmt', 'fetch_collection', 'fetch_collections', 'fetch_collection_uid_by_alias', 'fetch_simulation', 'fetch_simulations', 'fetch_parameters', 'delete_collection_stmt', 'delete_simulation_stmt', 'json_serializer', 'json_deserializer']
  • log=BAMBOOST_LOGGER.getChild(__name__)
  • _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

json_serializer(value) -> str

Convert a value to a JSON string.

Arguments:
  • value:typing.Any
json_deserializer(value) -> Any

Convert a JSON string to a Python value.

Arguments:
  • value:str
collections_upsert_stmt(data) -> Insert

Create 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.

simulations_upsert_stmt(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.
parameters_upsert_stmt(data) -> Insert
Arguments:
  • data:typing.Sequence[typing.Mapping[str, typing.Any]] | typing.Mapping[str, typing.Any]
fetch_collection(session, uid) -> CollectionRecord | None
Arguments:
  • session:sqlalchemy.orm.Session
  • uid:str
fetch_collections(session) -> list[CollectionRecord]
Arguments:
  • session:sqlalchemy.orm.Session
fetch_collection_uid_by_alias(session, alias) -> str | None
Arguments:
  • session:sqlalchemy.orm.Session
  • alias:str
fetch_simulation(session, collection_uid, name) -> SimulationRecord | None
Arguments:
  • session:sqlalchemy.orm.Session
  • collection_uid:str
  • name:str
fetch_simulations(session) -> list[SimulationRecord]
Arguments:
  • session:sqlalchemy.orm.Session
fetch_parameters(session) -> list[ParameterRecord]
Arguments:
  • session:sqlalchemy.orm.Session
Arguments:
  • uid:str
delete_simulation_stmt(collection_uid, name)
Arguments:
  • collection_uid:str
  • name:str
_build_collection(session, row) -> CollectionRecord
Arguments:
  • session:sqlalchemy.orm.Session
  • row:sqlalchemy.RowMapping
_build_simulation(row, parameters) -> SimulationRecord
Arguments:
  • row:sqlalchemy.RowMapping
  • parameters:typing.Sequence[ParameterRecord] | None
_build_parameter(row) -> ParameterRecord
Arguments:
  • row:sqlalchemy.RowMapping
_fetch_parameters_for(session, simulation_ids) -> dict[int, list[ParameterRecord]]
Arguments:
  • session:sqlalchemy.orm.Session
  • simulation_ids:typing.Sequence[int]
_normalize_payload(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.Table

    The 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).
_collect_update_columns(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

SqliteJSONEncoder

JSON encoder that handles numpy and datetime types.

SqliteJSONEncoder.default(self, obj) -> Any
Arguments:
  • obj:typing.Any