Automated Action 2204ae214d Create a simple Todo app with FastAPI and SQLite
- Set up project structure and FastAPI application
- Create Todo database model with SQLAlchemy
- Configure Alembic for database migrations
- Implement CRUD endpoints for managing Todo items
- Add health check endpoint
- Include comprehensive documentation in README.md
- Configure and apply Ruff linting
2025-05-19 13:36:18 +00:00

26 lines
636 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# Create database directory
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()