Automated Action 0d888832b4 Create simple todo app with FastAPI and SQLite
- Set up project structure and FastAPI application
- Create database models with SQLAlchemy
- Set up Alembic for database migrations
- Create API endpoints for todo CRUD operations
- Add health check endpoint
- Add unit tests for API endpoints
- Configure Ruff for linting and formatting
2025-05-22 10:47:24 +00:00

29 lines
714 B
Python

from typing import Generator
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session, sessionmaker
from app.core.config import SQLALCHEMY_DATABASE_URL
# Create SQLAlchemy engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}, # Needed for SQLite
)
# Create session factory
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create base class for models
Base = declarative_base()
def get_db() -> Generator[Session, None, None]:
"""Dependency to get database session."""
db = SessionLocal()
try:
yield db
finally:
db.close()