1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00
Files
AdministrationItDepartmens/backend/app/database.py
2025-01-05 02:50:02 +06:00

27 lines
958 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Database session configuration"""
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from .db.base_class import Base
from .config import settings
# Создаем URL для подключения к базе данных
SQLALCHEMY_DATABASE_URL = settings.DATABASE_URL
# Создаем движок SQLAlchemy с логированием SQL-запросов
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
echo=True, # Включаем логирование SQL-запросов
pool_pre_ping=True # Проверяем соединение перед использованием
)
# Создаем фабрику сессий
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Функция для получения сессии базы данных
def get_db():
"""Get database session"""
db = SessionLocal()
try:
yield db
finally:
db.close()