Automated Action 6776db0bbd Create REST API with FastAPI and SQLite
- Set up project structure with FastAPI
- Configure SQLAlchemy with SQLite
- Implement user and item models
- Set up Alembic for database migrations
- Create CRUD operations for models
- Implement API endpoints for users and items
- Add authentication functionality
- Add health check endpoint
- Configure Ruff for linting
- Update README with comprehensive documentation
2025-05-22 11:40:52 +00:00

29 lines
712 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
# Create SQLAlchemy engine
engine = create_engine(
settings.SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False} # Needed for SQLite
)
# Create sessionmaker
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create Base class for declarative models
Base = declarative_base()
def get_db():
"""
Dependency function to get a DB session.
To be used in FastAPI dependency injection system.
"""
db = SessionLocal()
try:
yield db
finally:
db.close()