mirror of
https://github.com/langgenius/dify.git
synced 2026-02-25 02:35:12 +00:00
Some checks failed
autofix.ci / autofix (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Main CI Pipeline / Check Changed Files (push) Has been cancelled
Main CI Pipeline / API Tests (push) Has been cancelled
Main CI Pipeline / Web Tests (push) Has been cancelled
Main CI Pipeline / Style Check (push) Has been cancelled
Main CI Pipeline / VDB Tests (push) Has been cancelled
Main CI Pipeline / DB Migration Test (push) Has been cancelled
Check i18n Files and Create PR / check-and-update (push) Has been cancelled
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
from sqlalchemy import Engine
|
|
from sqlalchemy.orm import Session, sessionmaker
|
|
|
|
_session_maker: sessionmaker | None = None
|
|
|
|
|
|
def configure_session_factory(engine: Engine, expire_on_commit: bool = False):
|
|
"""Configure the global session factory"""
|
|
global _session_maker
|
|
_session_maker = sessionmaker(bind=engine, expire_on_commit=expire_on_commit)
|
|
|
|
|
|
def get_session_maker() -> sessionmaker:
|
|
if _session_maker is None:
|
|
raise RuntimeError("Session factory not configured. Call configure_session_factory() first.")
|
|
return _session_maker
|
|
|
|
|
|
def create_session() -> Session:
|
|
return get_session_maker()()
|
|
|
|
|
|
# Class wrapper for convenience
|
|
class SessionFactory:
|
|
@staticmethod
|
|
def configure(engine: Engine, expire_on_commit: bool = False):
|
|
configure_session_factory(engine, expire_on_commit)
|
|
|
|
@staticmethod
|
|
def get_session_maker() -> sessionmaker:
|
|
return get_session_maker()
|
|
|
|
@staticmethod
|
|
def create_session() -> Session:
|
|
return create_session()
|
|
|
|
|
|
session_factory = SessionFactory()
|