Automated Action 96f40fc562 Create FastAPI endpoint service
- Set up FastAPI project structure with best practices
- Implemented SQLAlchemy models with SQLite database
- Added Alembic for database migrations
- Created CRUD API endpoints for items
- Added health check endpoint
- Updated documentation

generated with BackendIM... (backend.im)
2025-05-13 19:03:02 +00:00

29 lines
705 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from pathlib import Path
from app.core.config import settings
# Ensure the DB directory exists
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()
# Dependency to get DB session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()