Session¶
-
class
lsst.daf.butler.registry.interfaces.
Session
(db: lsst.daf.butler.registry.interfaces._database.Database)¶ Bases:
object
Class representing a persistent connection to a database.
Parameters: - db :
Database
Database instance.
Notes
Instances of Session class should not be created by client code;
Database.session
should be used to create context for a session:with db.session() as session: session.method() db.method()
In the current implementation sessions can be nested and transactions can be nested within a session. All nested sessions and transaction share the same database connection.
Session class represents a limited subset of database API that requires persistent connection to a database (e.g. temporary tables which have lifetime of a session). Potentially most of the database API could be associated with a Session class.
Methods Summary
dropTemporaryTable
(table)Drop a temporary table. makeTemporaryTable
(spec, name, None] = None)Create a temporary table. temporary_table
(spec, name, None] = None)Return a context manager that creates and then drops a context manager. Methods Documentation
-
dropTemporaryTable
(table: sqlalchemy.sql.schema.Table) → None¶ Drop a temporary table.
Parameters: - table :
sqlalchemy.schema.Table
A SQLAlchemy object returned by a previous call to
makeTemporaryTable
.
- table :
-
makeTemporaryTable
(spec: lsst.daf.butler.core.ddl.TableSpec, name: Optional[str, None] = None) → sqlalchemy.sql.schema.Table¶ Create a temporary table.
Parameters: - spec :
TableSpec
Specification for the table.
- name :
str
, optional A unique (within this session/connetion) name for the table. Subclasses may override to modify the actual name used. If not provided, a unique name will be generated.
Returns: - table :
sqlalchemy.schema.Table
SQLAlchemy representation of the table.
Notes
Temporary tables may be created, dropped, and written to even in read-only databases - at least according to the Python-level protections in the
Database
classes. Server permissions may say otherwise, but in that case they probably need to be modified to support the full range of expected read-only butler behavior.Temporary table rows are guaranteed to be dropped when a connection is closed.
Database
implementations are permitted to allow the table to remain as long as this is transparent to the user (i.e. “creating” the temporary table in a new session should not be an error, even if it does nothing).It may not be possible to use temporary tables within transactions with some database engines (or configurations thereof).
- spec :
-
temporary_table
(spec: lsst.daf.butler.core.ddl.TableSpec, name: Optional[str, None] = None) → Iterator[sqlalchemy.sql.schema.Table]¶ Return a context manager that creates and then drops a context manager.
Parameters: - spec :
ddl.TableSpec
Specification for the columns. Unique and foreign key constraints may be ignored.
- name :
str
, optional If provided, the name of the SQL construct. If not provided, an opaque but unique identifier is generated.
Returns: - table :
sqlalchemy.schema.Table
SQLAlchemy representation of the table.
- spec :
- db :