from typing import Any
from typing import Callable


def run_in_session(engine: Any, func: Callable[[Any], Any]) -> Any:
    """Run the given function within the scope of a single database connection session."""
    conn = engine.raw_connection()
    try:
        return func(conn)
    finally:
        conn.close()