django_sorcery.db.middleware module

Django middleware support for sqlalchemy.

class django_sorcery.db.middleware.BaseMiddleware(get_response=None)[source]

Bases: object

Base middleware implementation that supports unit of work per request for django.

logger = <Logger django_sorcery.db.middleware (WARNING)>
process_request(request)[source]

Hook for adding arbitrary logic to request processing.

process_response(request, response)[source]

Commits or rollbacks scoped sessions depending on status code then removes them.

return_response(request, response)[source]

Hook for adding arbitrary logic to response processing.

class django_sorcery.db.middleware.SQLAlchemyDBMiddleware(get_response=None)[source]

Bases: django_sorcery.db.middleware.BaseMiddleware

A base SQLAlchemy db middleware.

Used by SQLAlchemy to provide a default middleware for a single db, it will first try to flush and if successfull, proceed with commit. If there are any errors during flush, will issue a rollback.

commit(request, response)[source]

Commits current scoped session.

db = None
flush(request, response)[source]

Flushes current scoped session.

remove(request, response)[source]

Removes current scoped session.

rollback(request, response)[source]

Rolls back current scoped session.

class django_sorcery.db.middleware.SQLAlchemyMiddleware(get_response=None)[source]

Bases: django_sorcery.db.middleware.SQLAlchemyDBMiddleware

A sqlalchemy middleware that manages all the dbs configured and initialized.

it will first try to flush all the configured and initialized SQLAlchemy instances and if successfull, proceed with commit. If there are any errors during flush, all transactions will be rolled back.

db = {}