Automated Action 7fdb11e728 Create FastAPI REST API with SQLite database and CRUD operations
- Set up project structure with FastAPI, SQLAlchemy, and Alembic
- Create database models for User and Item
- Implement CRUD operations for all models
- Create API endpoints with validation
- Add health check endpoint
- Configure CORS middleware
- Set up database migrations
- Add comprehensive documentation in README
2025-05-21 08:51:23 +00:00

23 lines
521 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
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()