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_mock_engine
(engine_url[, output_file])Create a mock engine for testing or dumping DDL statements.
drop
()Drop the schema in the database if it exists.
Create the schema in the database if it does not exist.
Methods Documentation
- static create_mock_engine(engine_url, output_file=None)¶
Create a mock engine for testing or dumping DDL statements.
- drop()¶
Drop the schema in the database if it exists.
- Raises:
ValueError – Raised 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.
- initialize()¶
Create the schema in the database if it does not exist.
- Raises:
ValueError – Raised if the database is not supported or it already exists.
sqlalchemy.exc.SQLAlchemyError – Raised 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.