
- Set up FastAPI project structure - Configure SQLite database with SQLAlchemy - Create Item model and schemas - Implement CRUD endpoints for inventory items - Set up Alembic for database migrations - Add comprehensive documentation
18 lines
470 B
Python
18 lines
470 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
from app.core.config import settings
|
|
|
|
engine = create_engine(
|
|
settings.SQLALCHEMY_DATABASE_URL,
|
|
connect_args={"check_same_thread": False} # Required for SQLite
|
|
)
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
# Dependency for endpoints to get the DB session
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close() |