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.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.
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.Notes
specs
must be an instance of a type created bycollections.namedtuple
, not just regular tuple, and the returned object is guaranteed to be the same. Becausenamedtuple
is just a factory fortype
objects, not an actual type itself, we cannot represent this with type annotations.