
- 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
29 lines
714 B
Python
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()
|