Automated Action 43ed4aaa3f Create simple todo application with FastAPI and SQLite
- Set up project structure with FastAPI and SQLite
- Created Todo model with SQLAlchemy ORM
- Added CRUD operations for todos
- Implemented API endpoints for Todo operations
- Added health check endpoint
- Added Alembic for database migrations
- Updated README with documentation

generated with BackendIM... (backend.im)
2025-05-13 12:04:52 +00:00

27 lines
664 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)
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()