API

Here’s the public API for Henson-Database.

Database

class henson_database.Database(app=None)[source]

An interface to interact with a relational database.

Parameters:app (Optional[henson.base.Application]) – An application instance that has an attribute named settings that contains a mapping of settings to interact with a database.

Changed in version 0.4.0: Alembic migrations are supported.

Model

Return a base class for creating models.

Returns:
The base class
to use for creating new models.
Return type:sqlalchemy.ext.declarative.declarative_base
engine

Return the engine.

Returns:The engine.
Return type:sqlalchemy.engine.Engine
init_app(app)[source]

Initialize an application for use with the database.

If database settings are provided by app as a dict rather than individual keys and values, expands them to the format expected by the extension’s internal create_engine call.

Parameters:app (henson.base.Application) – Application instance that has an attribute named settings that contains a mapping of settings needed to interact with the database.
metadata

Return the metadata associated with db.Model.

Returns:The metadata.
Return type:sqlalchemy.MetaData
register_cli()[source]

Register the command line interface.

New in version 0.4.0.

session()[source]

Yield a context manager for a SQLAlchemy session.

Yields:sqlalchemy.orm.session.Session – A new session instance.
sessionmaker

Return a function to get a new session.

Returns:A function that can be used to get a new session.
Return type:callable