mirror of
https://github.com/open-webui/open-webui
synced 2024-11-07 09:09:53 +00:00
feat(sqlalchemy): use scoped session
This commit is contained in:
parent
c134eab27a
commit
eb01e8d275
@ -7,7 +7,7 @@ from typing_extensions import Self
|
|||||||
|
|
||||||
from sqlalchemy import create_engine, types, Dialect
|
from sqlalchemy import create_engine, types, Dialect
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker, scoped_session
|
||||||
from sqlalchemy.sql.type_api import _T
|
from sqlalchemy.sql.type_api import _T
|
||||||
|
|
||||||
from config import SRC_LOG_LEVELS, DATA_DIR, DATABASE_URL, BACKEND_DIR
|
from config import SRC_LOG_LEVELS, DATA_DIR, DATABASE_URL, BACKEND_DIR
|
||||||
@ -61,10 +61,10 @@ Base = declarative_base()
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def get_session():
|
def get_session():
|
||||||
db = SessionLocal()
|
session = scoped_session(SessionLocal)
|
||||||
try:
|
try:
|
||||||
yield db
|
yield session
|
||||||
db.commit()
|
session.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.rollback()
|
session.rollback()
|
||||||
raise e
|
raise e
|
||||||
|
Loading…
Reference in New Issue
Block a user