Module stac_fastapi.sqlalchemy.session¶
database session management.
Variables¶
logger
Classes¶
FastAPISessionMaker¶
class FastAPISessionMaker(
database_uri: str
)
FastAPISessionMaker.
Ancestors (in MRO)¶
- fastapi_utils.session.FastAPISessionMaker
Instance variables¶
cached_engine
Returns a lazily-cached sqlalchemy engine for the instance's database_uri.
cached_sessionmaker
Returns a lazily-cached sqlalchemy sessionmaker using the instance's (lazily-cached) engine.
Methods¶
context_session¶
def context_session(
self
) -> Iterator[sqlalchemy.orm.session.Session]
Override base method to include exception handling.
get_db¶
def get_db(
self
) -> Iterator[sqlalchemy.orm.session.Session]
A generator function that yields a sqlalchemy orm session and cleans up the session once resumed after yielding.
Can be used directly as a context-manager FastAPI dependency, or yielded from inside a separate dependency.
get_new_engine¶
def get_new_engine(
self
) -> sqlalchemy.engine.base.Engine
Returns a new sqlalchemy engine using the instance's database_uri.
get_new_sessionmaker¶
def get_new_sessionmaker(
self,
engine: Optional[sqlalchemy.engine.base.Engine]
) -> sqlalchemy.orm.session.sessionmaker
Returns a new sessionmaker for the provided sqlalchemy engine. If no engine is provided, the
instance's (lazily-cached) engine is used.
reset_cache¶
def reset_cache(
self
) -> None
Resets the engine and sessionmaker caches.
After calling this method, the next time you try to use the cached engine or sessionmaker, new ones will be created.
Session¶
class Session(
reader_conn_string: str,
writer_conn_string: str
)
Database session management.
Static methods¶
create_from_env¶
def create_from_env(
)
Create from environment.
create_from_settings¶
def create_from_settings(
settings: stac_fastapi.sqlalchemy.config.SqlalchemySettings
) -> 'Session'
Create a Session object from settings.