mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
22 lines
680 B
Python
22 lines
680 B
Python
"""Database session configuration"""
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
from .db.base import Base
|
|
from .config import settings
|
|
|
|
# Создаем URL для подключения к базе данных
|
|
SQLALCHEMY_DATABASE_URL = settings.DATABASE_URL
|
|
|
|
# Создаем движок SQLAlchemy
|
|
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
|
|
|
# Создаем фабрику сессий
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
# Функция для получения сессии базы данных
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close() |