Automated Action 95a8111a53 Implement simple todo app with FastAPI
- Created project structure and FastAPI application
- Added SQLite database models and Pydantic schemas
- Implemented todo routes (add, list, delete)
- Set up Alembic migrations
- Added health endpoint

generated with BackendIM... (backend.im)
2025-05-13 13:09:47 +00:00

31 lines
732 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 if it doesn't exist
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
# Database URL
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
# Create engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create session
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create base class
Base = declarative_base()
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()