sqlalchemy_helpers.aio module¶
Database management (async).
This must remain independent from any web framework.
- class sqlalchemy_helpers.aio.AsyncDatabaseManager(uri, alembic_location, engine_args=None, base_model=None)[source]¶
Bases:
DatabaseManager
Helper for a SQLAlchemy and Alembic-powered database, asynchronous version.
- Parameters:
- alembic_cfg¶
the Alembic configuration object
- Type:
alembic.config.Config
- engine¶
the SQLAlchemy Engine instance
- Type:
- Session¶
the SQLAlchemy scoped session factory
- async get_status()[source]¶
Get the status of the database.
- Returns:
see
DatabaseStatus
.- Return type:
DatabaseStatus member
- async sqlalchemy_helpers.aio.get_by_pk(pk, *, session, model)[source]¶
Get a model instance using its primary key.
Example:
user = get_by_pk(42, session=session, model=User)
- async sqlalchemy_helpers.aio.get_one(session: AsyncSession, model, **attrs) Base [source]¶
Get an object from the datbase.
- Parameters:
session – The SQLAlchemy session to use
model – The SQLAlchemy model to query
- Returns:
the object
- async sqlalchemy_helpers.aio.get_or_create(session, model, **attrs)[source]¶
Function like Django’s
get_or_create()
method.It will return a tuple, the first argument being the instance and the second being a boolean:
True
if the instance has been created andFalse
otherwise.Example:
user, created = get_or_create(session, User, name="foo")