TableSpec

class lsst.daf.butler.TableSpec(fields: NamedValueSet[FieldSpec], unique: Set[Tuple[str, ...]], foreignKeys: List[ForeignKeySpec], sql: Optional[str] = None, doc: Optional[str] = None)

Bases: object

A struct-like class used to define a logical Registry table (which may also be implemented in the database as a view).

Attributes Summary

doc Documentation for the table.
sql A SQL SELECT statement that can be used to define this logical table as a view.

Methods Summary

addForeignKeys(tableName, schema) Add SQLAlchemy foreign key constraints for this table to the corresponding entry in the given schema.
fromConfig(config, *args, **kwds)
isView() Return True if this logical table should be implemented as some kind of view.
toSqlAlchemy(tableName, schema) Construct a SQLAlchemy Table or View corresponding to this specification.

Attributes Documentation

doc = None

Documentation for the table.

sql = None

A SQL SELECT statement that can be used to define this logical table as a view.

Should be None if this table’s contents is not defined in terms of other tables.

Methods Documentation

addForeignKeys(tableName: str, schema: lsst.daf.butler.core.schema.Schema)

Add SQLAlchemy foreign key constraints for this table to the corresponding entry in the given schema.

Parameters:
tableName : str

Name of the logical table.

schema : Schema

Object represening the full schema. Will be modified in-place.

Notes

This must be called after toSqlAlchemy has been called on all tables in the schema.

classmethod fromConfig(config, *args, **kwds)
isView() → bool

Return True if this logical table should be implemented as some kind of view.

toSqlAlchemy(tableName: str, schema: lsst.daf.butler.core.schema.Schema) → Union[sqlalchemy.sql.schema.Table, lsst.daf.butler.core.views.View]

Construct a SQLAlchemy Table or View corresponding to this specification.

This does not emit the actual DDL statements that would create the table or view in the database; it merely creates a SQLAlchemy representation of the table or view.

Parameters:
tableName : str

Name of the logical table.

schema : Schema

Object represening the full schema. Will be modified in-place.

Returns:
table : sqlalchemy.Table or View

A SQLAlchemy object representing the logical table.

Notes

This does not add foreign key constraints, as all tables must be created (in the SQLAlchemy metadata sense) before foreign keys can safely be created. addForeignKeys must be called to complete this process.