
- Created project structure with FastAPI setup - Added SQLite database connection with SQLAlchemy ORM - Implemented Todo model and schemas - Added CRUD operations for Todo items - Created API endpoints for Todo management - Added health check endpoint - Configured Alembic for database migrations - Updated project documentation in README.md
25 lines
621 B
Python
25 lines
621 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 SessionLocal class
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
def get_db():
|
|
"""
|
|
Dependency function that creates a new SQLAlchemy SessionLocal
|
|
that will be used in a single request, and then closed.
|
|
"""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close() |