openpectus.aggregator.data.database
Attributes
Exceptions
Excetion raised when trying to access the database before it is configured. |
|
Excetion raised when trying to access a database session without a scope. |
Classes
FastAPI middleware that makes request scoped database sessions available |
Functions
Used from middleware to create a request context (scope), in which scoped_session() will work. |
|
|
|
|
|
|
Module Contents
- openpectus.aggregator.data.database._engine: sqlalchemy.Engine | None = None
- openpectus.aggregator.data.database._sessionmaker: sqlalchemy.orm.sessionmaker[sqlalchemy.orm.Session] | None = None
- openpectus.aggregator.data.database._session_ctx: contextvars.ContextVar[sqlalchemy.orm.Session | None]
- openpectus.aggregator.data.database.create_scope()
Used from middleware to create a request context (scope), in which scoped_session() will work.
Can also be used in non-request contexts to enable scoped_session() there.
Also used in tests to provide a scope
- openpectus.aggregator.data.database.scoped_session()
- Return type:
sqlalchemy.orm.Session
- openpectus.aggregator.data.database.configure_db(database_url)
- Parameters:
database_url (str)
- openpectus.aggregator.data.database.json_serialize(instance)
- Return type:
str
- openpectus.aggregator.data.database.json_deserialize(instance)
- Return type:
dict[str, Any]
- class openpectus.aggregator.data.database.DBSessionMiddleware(app)
Bases:
starlette.middleware.base.BaseHTTPMiddlewareFastAPI middleware that makes request scoped database sessions available
- Parameters:
app (starlette.types.ASGIApp)
- async dispatch(request, call_next)
- Parameters:
request (starlette.requests.Request)
call_next (starlette.middleware.base.RequestResponseEndpoint)
- exception openpectus.aggregator.data.database.DatabaseNotConfiguredError(*args)
Bases:
ExceptionExcetion raised when trying to access the database before it is configured.
- Parameters:
args (object)
- exception openpectus.aggregator.data.database.SessionMissingError
Bases:
ExceptionExcetion raised when trying to access a database session without a scope.