Automated Action 9c5b74200b Setup basic FastAPI project with Todo API
- Created requirements.txt with necessary dependencies
- Set up FastAPI application structure with main.py
- Added health endpoint
- Configured SQLAlchemy with SQLite database
- Initialized Alembic for database migrations
- Created Todo model and API endpoints
- Updated README with setup and usage instructions
- Linted code with Ruff
2025-05-29 02:07:19 +00:00

31 lines
814 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from pathlib import Path
# Create the database directory if it doesn't exist
DB_DIR = Path("/app/storage/db")
DB_DIR.mkdir(parents=True, exist_ok=True)
# SQLite database URL
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
# Create the SQLAlchemy engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create a SessionLocal class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create a Base class for declarative models
Base = declarative_base()
# Dependency to get a database session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()