Automated Action 109d0c91b8 Create FastAPI application with basic CRUD functionality
- Set up project structure with FastAPI app
- Implement items CRUD API endpoints
- Configure SQLite database with SQLAlchemy
- Set up Alembic migrations
- Add health check endpoint
- Enable CORS middleware
- Create README with documentation
2025-06-06 09:44:58 +00:00

27 lines
674 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from pathlib import Path
# 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 SQLAlchemy engine
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create SessionLocal class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Dependency for getting DB session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()