
- Set up FastAPI project structure - Configure SQLAlchemy with SQLite - Create Todo model and schemas - Implement CRUD operations - Add API endpoints for Todo management - Configure Alembic for database migrations - Add health check endpoint - Add comprehensive documentation
27 lines
612 B
Python
27 lines
612 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 engine
|
|
engine = create_engine(
|
|
settings.SQLALCHEMY_DATABASE_URL,
|
|
connect_args={"check_same_thread": False}, # SQLite specific
|
|
)
|
|
|
|
# Create SessionLocal class
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
# Create Base class
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
"""Dependency for getting DB session"""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|