StaticTablesContext¶
- class lsst.daf.butler.registry.interfaces.StaticTablesContext(db: Database, connection: Connection)¶
Bases:
objectHelper 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:
- db
Database The database.
- connection
sqlalchemy.engine.Connection The connection object.
- db
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.
- addTable(name: str, spec: TableSpec) Table¶
Add a new table to the schema, returning its sqlalchemy representation.
- Parameters:
- name
str The name of the table.
- spec
ddl.TableSpec The specification of the table.
- name
- Returns:
- table
sqlalchemy.schema.Table The created table.
- 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:
- specs
tupleofddl.TableSpec Specifications of multiple tables.
- specs
- Returns:
- tables
tupleofsqlalchemy.schema.Table All the tables created.
- tables
Notes
specsmust be an instance of a type created bycollections.namedtuple, not just regular tuple, and the returned object is guaranteed to be the same. Becausenamedtupleis just a factory fortypeobjects, not an actual type itself, we cannot represent this with type annotations.