calibpipe.database.adapter package#

Adapter sub-package.

Contains all utilities to adapt CalibPipe data to a DB and use it.

Sub-package content:

  • database_containers: DB containers (in correspondence with CalibPipe containers) to connect CalibPipe data and the DB system.

  • adapter: Small class used to translate CalibPipe container data to DB-level data that can be directly inserted in a DB.

class calibpipe.database.adapter.Adapter[source]#

Bases: object

Adapt CalibPipe containers into DB objects.

The main method is to_postgres(), converting a CalibPipe container to a tuple containing the objects required to interact with the corresponding data in the database.

static to_postgres(container: Container, version: str | None = None) tuple[Table, dict[str, Any]] | None[source]#

Convert a CalibPipe container in DB data that can be inserted or queried.

Parameters:
container: ContainerMap.cp_container

CalibPipe container (containing data) to convert to DB-level data

version: str

Software version corresponding to the data

Returns:
Optional[tuple[sa.Table, dict[str, Any]]]

None if no DB table information is associated to the container. A tuple containing the SQL table corresponding to the container, and a dictionary with the valued attributes contained in the CalibPipe container.

static get_db_kwargs(container: Container, table_info: SQLTableInfo) dict[str, Any][source]#

Get kwargs required to insert a row from a CalibPipe container.

Subpackages#

Submodules#

calibpipe.database.adapter.adapter module#

Adapter class.

class calibpipe.database.adapter.adapter.Adapter[source]#

Bases: object

Adapt CalibPipe containers into DB objects.

The main method is to_postgres(), converting a CalibPipe container to a tuple containing the objects required to interact with the corresponding data in the database.

static to_postgres(container: Container, version: str | None = None) tuple[Table, dict[str, Any]] | None[source]#

Convert a CalibPipe container in DB data that can be inserted or queried.

Parameters:
container: ContainerMap.cp_container

CalibPipe container (containing data) to convert to DB-level data

version: str

Software version corresponding to the data

Returns:
Optional[tuple[sa.Table, dict[str, Any]]]

None if no DB table information is associated to the container. A tuple containing the SQL table corresponding to the container, and a dictionary with the valued attributes contained in the CalibPipe container.

static get_db_kwargs(container: Container, table_info: SQLTableInfo) dict[str, Any][source]#

Get kwargs required to insert a row from a CalibPipe container.