
- Set up project structure with FastAPI - Implement SQLAlchemy models for inventory items and categories - Create database connection with SQLite - Add CRUD operations for inventory management - Implement API endpoints for categories, items, and inventory transactions - Add health check endpoint - Set up Alembic for database migrations - Update README with documentation
27 lines
639 B
Python
27 lines
639 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from app.core.config import settings
|
|
|
|
# Create DB directory if it doesn't exist
|
|
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
engine = create_engine(
|
|
settings.SQLALCHEMY_DATABASE_URL,
|
|
connect_args={"check_same_thread": False} # Only needed for SQLite
|
|
)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
def get_db():
|
|
"""
|
|
Dependency function to get a database session.
|
|
|
|
Yields:
|
|
Session: SQLAlchemy session
|
|
"""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close() |