Automated Action 55fa6c2bbd Create comprehensive FastAPI REST API service
- Set up FastAPI application with CORS support
- Implement SQLAlchemy models and database session management
- Create CRUD API endpoints for items management
- Configure Alembic for database migrations
- Add health check and service info endpoints
- Include comprehensive documentation and project structure
- Integrate Ruff for code quality and formatting
2025-06-19 04:39:38 +00:00

22 lines
520 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from pathlib import Path
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)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()