DatabaseContext¶
- class felis.db.database_context.DatabaseContext¶
Bases:
AbstractContextManagerInterface for managing database operations across different SQL dialects.
Attributes Summary
The SQLAlchemy dialect for the context (
Dialect).Get the dialect name for this database context (
str).The SQAlchemy engine for the context (
Engine).The SQLAlchemy metadata representing the database for the context (
MetaData).Methods Summary
close()Close and clean up database resources.
Create all database objects in the schema using the metadata object.
Create all indexes in the schema using the metadata object.
drop()Drop the schema in the database if it exists.
Drop all indexes in the schema using the metadata object.
execute(statement[, parameters])Execute a SQL statement and return the result.
Create the target schema in the database if it does not exist already.
Attributes Documentation
- dialect_name¶
Get the dialect name for this database context (
str).
Methods Documentation
- abstract create_all()¶
Create all database objects in the schema using the metadata object.
- Raises:
DatabaseContextError – If there is an error creating the schema objects in the database.
- Return type:
- abstract create_indexes()¶
Create all indexes in the schema using the metadata object.
- Raises:
DatabaseContextError – If there is an error creating the indexes in the database.
- Return type:
- abstract drop()¶
Drop the schema in the database if it exists.
Implementations should use
IF EXISTSsemantics to avoid raising an error if the schema does not exist.- Raises:
DatabaseContextError – If there is an error dropping the schema.
- Return type:
- abstract drop_indexes()¶
Drop all indexes in the schema using the metadata object.
- Raises:
DatabaseContextError – If there is an error dropping the indexes in the database.
- Return type:
- abstract execute(statement, parameters=None)¶
Execute a SQL statement and return the result.
- Parameters:
statement (
str|Executable|TextClause) – The SQL statement to execute.
- Returns:
The result of the statement execution.
- Return type:
- Raises:
DatabaseContextError – If there is an error executing the SQL statement.
- abstract initialize()¶
Create the target schema in the database if it does not exist already.
Sub-classes should implement idempotent behavior so that calling this method multiple times has no adverse effects. If the schema already exists, the method should simply return without raising an error. (A warning message may be logged in this case.)
- Raises:
DatabaseContextError – If there is an error instantiating the schema.
- Return type: