Automated Action b8143c43e4 Implement ecommerce authentication and inventory API
- Set up project structure and FastAPI application
- Create database models for users, products, and inventory
- Configure SQLAlchemy and Alembic for database management
- Implement JWT authentication
- Create API endpoints for user, product, and inventory management
- Add admin-only routes and authorization middleware
- Add health check endpoint
- Update README with documentation
- Lint and fix code issues
2025-06-08 21:40:55 +00:00

25 lines
662 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
# Create SQLite engine with check_same_thread=False for SQLite
engine = create_engine(
settings.SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create SessionLocal class for database sessions
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def get_db():
"""
Dependency for FastAPI endpoints that need a database session.
Yields a database session and ensures it is closed after use.
"""
db = SessionLocal()
try:
yield db
finally:
db.close()