todoapp-xht8o2/app/core/database.py
Automated Action fd0d96616b Initial setup of FastAPI Todo Application
- Set up project structure
- Create FastAPI app with SQLite database
- Implement Todo API with CRUD operations
- Set up Alembic for database migrations
- Add health endpoint
- Create README with documentation
2025-05-27 10:47:50 +00:00

22 lines
495 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
engine = create_engine(
settings.SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()