todoapp-pbq0j1/app/db/session.py
Automated Action ef0bc51fbb Create simple FastAPI todo application
- Set up project structure with proper directory layout
- Implemented SQLite database with SQLAlchemy ORM
- Created Todo model with CRUD operations
- Added Alembic for database migrations
- Implemented RESTful API endpoints for todos
- Added health check endpoint
- Configured CORS for all origins
- Created comprehensive documentation
- Added linting with Ruff
2025-06-17 06:40:03 +00:00

22 lines
520 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
DB_DIR = Path("/app") / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()