Automated Action 07301a47e7 Implement RESTful API using FastAPI and SQLite
- Set up project structure with FastAPI framework
- Implement database models using SQLAlchemy
- Create Alembic migrations for database schema
- Build CRUD endpoints for Items resource
- Add health check endpoint
- Include API documentation with Swagger and ReDoc
- Update README with project documentation
2025-05-18 16:46:51 +00:00

27 lines
668 B
Python

from pathlib import Path
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, Session
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)
Base = declarative_base()
metadata = MetaData()
# Dependency
def get_db() -> Session:
db = SessionLocal()
try:
yield db
finally:
db.close()