Automated Action 4e60587fda Create simple inventory management app with FastAPI and SQLite
- 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
2025-06-17 03:54:50 +00:00

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()