DatabaseContext¶
- class felis.db.utils.DatabaseContext(metadata, engine)¶
Bases:
object
Manage the database connection and SQLAlchemy metadata.
- Parameters:
Methods Summary
Create all tables in the schema using the metadata object.
Create the schema in the database if it does not exist.
create_mock_engine
(engine_url[, output_file])Create a mock engine for testing or dumping DDL statements.
Drop the schema in the database if it exists.
Methods Documentation
- create_if_not_exists()¶
Create the schema in the database if it does not exist.
- Raises:
ValueError – If the database is not supported.
sqlalchemy.exc.SQLAlchemyError – If there is an error creating the schema.
- Return type:
Notes
In MySQL, this will create a new database and, in PostgreSQL, it will create a new schema. For other variants, this is an unsupported operation.
- static create_mock_engine(engine_url, output_file=None)¶
Create a mock engine for testing or dumping DDL statements.
- drop_if_exists()¶
Drop the schema in the database if it exists.
- Raises:
ValueError – If the database is not supported.
- Return type:
Notes
In MySQL, this will drop a database. In PostgreSQL, it will drop a schema. For other variants, this is an unsupported operation.