Automated Action e852047583 Create Todo application with FastAPI and SQLite
- Implemented project structure
- Added SQLAlchemy models and database connection
- Created Alembic migrations
- Implemented CRUD API endpoints
- Added health endpoint
- Updated README.md

generated with BackendIM... (backend.im)
2025-05-13 06:15:34 +00:00

24 lines
617 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} # Only needed for SQLite
)
# Create a SessionLocal class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Create a Base class
Base = declarative_base()
# Dependency to get DB session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()