StaticTablesContext

class lsst.daf.butler.registry.interfaces.StaticTablesContext(db: Database, connection: Connection)

Bases: object

Helper class used to declare the static schema for a registry layer in a database.

An instance of this class is returned by Database.declareStaticTables, which should be the only way it should be constructed.

Parameters:
dbDatabase

The database.

connectionsqlalchemy.engine.Connection

The connection object.

Methods Summary

addInitializer(initializer)

Add a method that does one-time initialization of a database.

addTable(name, spec)

Add a new table to the schema, returning its sqlalchemy representation.

addTableTuple(specs)

Add a named tuple of tables to the schema, returning their SQLAlchemy representations in a named tuple of the same type.

Methods Documentation

addInitializer(initializer: Callable[[Database], None]) None

Add a method that does one-time initialization of a database.

Initialization can mean anything that changes state of a database and needs to be done exactly once after database schema was created. An example for that could be population of schema attributes.

Parameters:
initializerCallable

Method of a single argument which is a Database instance.

addTable(name: str, spec: TableSpec) Table

Add a new table to the schema, returning its sqlalchemy representation.

Parameters:
namestr

The name of the table.

specddl.TableSpec

The specification of the table.

Returns:
tablesqlalchemy.schema.Table

The created table.

Notes

The new table may not actually be created until the end of the context created by Database.declareStaticTables, allowing tables to be declared in any order even in the presence of foreign key relationships.

addTableTuple(specs: tuple[lsst.daf.butler.ddl.TableSpec, ...]) tuple[sqlalchemy.sql.schema.Table, ...]

Add a named tuple of tables to the schema, returning their SQLAlchemy representations in a named tuple of the same type.

The new tables may not actually be created until the end of the context created by Database.declareStaticTables, allowing tables to be declared in any order even in the presence of foreign key relationships.

Parameters:
specstuple of ddl.TableSpec

Specifications of multiple tables.

Returns:
tablestuple of sqlalchemy.schema.Table

All the tables created.

Notes

specs must be an instance of a type created by collections.namedtuple, not just regular tuple, and the returned object is guaranteed to be the same. Because namedtuple is just a factory for type objects, not an actual type itself, we cannot represent this with type annotations.