Automated Action 1b1f93e10f Create Todo application with FastAPI and SQLite
- Set up project structure with FastAPI
- Create Todo database model and schema
- Implement database connection with SQLAlchemy
- Set up Alembic migrations
- Implement CRUD API endpoints for Todo items
- Add health check endpoint
- Update documentation in README.md

generated with BackendIM... (backend.im)
2025-05-12 05:45:11 +00:00

22 lines
576 B
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.db.database import get_db
router = APIRouter()
@router.get("/")
async def health_check(db: Session = Depends(get_db)):
"""
Health check endpoint to verify the API is running and can connect to the database.
"""
try:
# Execute a simple query to check database connection
db.execute("SELECT 1")
db_status = "healthy"
except Exception:
db_status = "unhealthy"
return {
"status": "healthy",
"database": db_status
}