Automated Action 93c528a258 Create FastAPI REST API with SQLite
- Set up project structure and dependencies
- Create database models with SQLAlchemy
- Implement API endpoints for CRUD operations
- Set up Alembic for database migrations
- Add health check endpoint
- Configure Ruff for linting
- Update documentation in README
2025-05-29 10:18:27 +00:00

25 lines
620 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Ensure DB directory exists
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
# Create SQLAlchemy engine
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False})
# Create sessionmaker
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Dependency to use in routes
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()