Skip to content

db

Low-level Database Connection & Session Management.

Provides a context manager to create a new SQLAlchemy session and a decorator to provide a session to a function. This module is designed for managing the database connection in the EleanorAI Framework backend.

Note

SQLAlchemy engine documentation is available here.

Example
@dbsession
def my_function(sa_session: SASession):
    # Function implementation using the session...
    pass

with create_rdbms_session() as sa_session:
    # Code block using the session...

Functions

create_rdbms_session

create_rdbms_session() -> Generator[Session, None, None]

Creates a new session and yields it as a context manager.

The session is automatically committed if no exceptions occur during the execution of the code block. If an exception occurs, the session is rolled back and the exception is re-raised. Finally, the session is closed.

Example
with create_rdbms_session() as sa_session:
    # Code block using the session...
Warning

A commit() is executed on the session if no exceptions occur during processing. This effectively enables auto-commit for all managed sessions regardless of RDBMS backend / driver settings.

Yields:

  • SASession ( Session ) –

    The created session.

Raises:

  • Exception

    If an exception occurs during the execution of the code block.

dbsession

dbsession(func: Callable) -> Callable

Decorator that provides a database session to the decorated function.

Example
@dbsession
def my_function(sa_session: SASession):
    # Function implementation using the session...
    pass

Parameters:

  • func (Callable) –

    The function to be decorated.

Returns:

  • Callable ( Callable ) –

    The decorated function.