todoapp-itmyvk/app/db/session.py
Automated Action d667651110 Create simple Todo app with FastAPI and SQLite
- Add CRUD operations for todos (create, read, update, delete)
- Implement SQLAlchemy models and schemas
- Set up Alembic for database migrations
- Add health endpoint and CORS configuration
- Include comprehensive API documentation
- Structure project with proper separation of concerns
2025-06-19 22:02:18 +00:00

23 lines
521 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()