Automated Action e1b1b89511 Create FastAPI REST API with SQLite
Features:
- Project structure with FastAPI framework
- SQLAlchemy models with SQLite database
- Alembic migrations system
- CRUD operations for items
- API routers with endpoints for items
- Health endpoint for monitoring
- Error handling and validation
- Comprehensive documentation
2025-05-18 05:45:33 +00:00

23 lines
551 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
# Create an engine for the database
engine = create_engine(
settings.SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}, # Needed for SQLite
)
# Create a SessionLocal class for session creation
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Dependency to get the database session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()