DatabaseMetadata

class lsst.daf.butler.registry.interfaces.DatabaseMetadata(namespace: str | None)

Bases: object

Wrapper around SqlAlchemy MetaData object to ensure threadsafety.

Parameters:
namespacestr or None

Name of the schema or namespace this instance is associated with.

Notes

sqlalchemy.MetaData is documented to be threadsafe for reads, but not with concurrent modifications. We add tables dynamically at runtime, and the MetaData object is shared by all Database instances sharing the same connection pool.

Methods Summary

add_table(db, name, spec, **kwargs)

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

create_all(connection)

Create all tables known to this MetaData object in the database.

get_table(name)

Return the definition of a table that was previously added to this MetaData object.

remove_table(name)

Remove a table that was previously added to this MetaData object.

Methods Documentation

add_table(db: Database, name: str, spec: TableSpec, **kwargs: Any) Table

Add a new table to the MetaData object, returning its sqlalchemy representation. This does not physically create the table in the database – it only sets up its definition.

Parameters:
dbDatabase

Database connection associated with the table definition.

namestr

The name of the table.

specddl.TableSpec

The specification of the table.

**kwargs

Additional keyword arguments to forward to the sqlalchemy.schema.Table constructor.

Returns:
tablesqlalchemy.schema.Table

The created table.

create_all(connection: Connection) None

Create all tables known to this MetaData object in the database. Same as sqlalchemy.MetaData.create_all.

Parameters:
connectionsqlalchemy.engine.connection

Database connection that will be used to create tables.

get_table(name: str) Table | None

Return the definition of a table that was previously added to this MetaData object.

Parameters:
namestr

Name of the table.

Returns:
tablesqlalchemy.schema.Table or None

The table definition, or None if the table is not known to this MetaData instance.

remove_table(name: str) None

Remove a table that was previously added to this MetaData object.

Parameters:
namestr

Name of the table.