Automated Action e01f3a4d57 Create FastAPI Todo App
Create a simple Todo API with FastAPI and SQLite with CRUD functionality,
health check, error handling, and API documentation.
2025-05-31 21:13:37 +00:00

30 lines
699 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
# Ensure DB directory exists
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{settings.DB_DIR}/{settings.DB_NAME}"
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
"""
Dependency function to get a database session.
"""
db = SessionLocal()
try:
yield db
finally:
db.close()