Automated Action 12b80aca5b Implement and optimize Calculator API with FastAPI and SQLAlchemy
- Fixed Pydantic configuration using ConfigDict for latest Pydantic version
- Fixed import order in alembic/env.py for proper module imports
- Applied code formatting with Ruff
- Optimized database connection settings
- Ensured proper error handling for API endpoints

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

23 lines
539 B
Python

from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Create DB directory
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()