Files
admin-edu-space/backend/database.py
T

21 lines
592 B
Python

"""
Database & Persistence Management for FastAPI (Capa 4)
Integrates SQLAlchemy Engine, SessionLocal and get_db dependency.
"""
from typing import Generator, Any
from app import create_app, db as flask_db
# Initialize shared application context
flask_app = create_app()
def get_db() -> Generator[Any, None, None]:
"""
FastAPI dependency yielding the SQLAlchemy session within Flask app context
to guarantee all models, ORM queries and services work seamlessly.
"""
with flask_app.app_context():
yield flask_db.session
def get_flask_app():
return flask_app