Первый коммит

This commit is contained in:
2026-02-25 14:47:19 +03:00
commit 1e376aff24
170 changed files with 4893 additions and 0 deletions

29
app/modules/shared/db.py Normal file
View File

@@ -0,0 +1,29 @@
from __future__ import annotations
import os
from sqlalchemy import create_engine
from sqlalchemy.engine import Engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool
_ENGINE: Engine | None = None
_SESSION_FACTORY: sessionmaker | None = None
def database_url() -> str:
return os.getenv("DATABASE_URL", "postgresql+psycopg://agent:agent@db:5432/agent")
def get_engine() -> Engine:
global _ENGINE
if _ENGINE is None:
_ENGINE = create_engine(database_url(), poolclass=NullPool, future=True)
return _ENGINE
def get_session_factory() -> sessionmaker:
global _SESSION_FACTORY
if _SESSION_FACTORY is None:
_SESSION_FACTORY = sessionmaker(bind=get_engine(), autoflush=False, autocommit=False)
return _SESSION_FACTORY