Automated Action 0e00013b7f Implement product catalog API with CRUD operations
- Created FastAPI application with product catalog functionality
- Implemented CRUD operations for products
- Added SQLAlchemy models and Pydantic schemas
- Set up SQLite database with Alembic migrations
- Added health check endpoint
- Updated README with project documentation

generated with BackendIM... (backend.im)
2025-05-13 17:21:00 +00:00

28 lines
674 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
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)
Base = declarative_base()
def create_db_and_tables():
Base.metadata.create_all(bind=engine)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()