
- Add SQLAlchemy models for Todo with timestamps - Create Pydantic schemas for request/response validation - Implement CRUD operations for Todo management - Add REST API endpoints for todo operations (GET, POST, PUT, DELETE) - Configure SQLite database with proper connection settings - Set up Alembic migrations for database schema management - Add comprehensive API documentation and health check endpoint - Enable CORS for all origins - Include proper error handling and HTTP status codes - Update README with complete setup and usage instructions
23 lines
522 B
Python
23 lines
522 B
Python
from sqlalchemy import create_engine
|
|
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 a session factory
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
def get_db():
|
|
"""Dependency for getting DB session."""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|