Add session_scope context manager to manage session scope
This commit is contained in:
parent
6c7d06b2f9
commit
bb3257ed80
1 changed files with 10 additions and 0 deletions
|
|
@ -57,6 +57,16 @@ def get_session() -> Generator["Session", None, None]:
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def session_scope():
|
def session_scope():
|
||||||
|
"""
|
||||||
|
Context manager for managing a session scope.
|
||||||
|
|
||||||
|
Yields:
|
||||||
|
session: The session object.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
Exception: If an error occurs during the session scope.
|
||||||
|
|
||||||
|
"""
|
||||||
session = next(get_session())
|
session = next(get_session())
|
||||||
try:
|
try:
|
||||||
yield session
|
yield session
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue