deps.py 507 B

123456789101112131415161718192021
  1. from typing import Generator
  2. from fastapi import Depends, HTTPException, status
  3. from fastapi.security import OAuth2PasswordBearer
  4. from jose import jwt
  5. from pydantic import ValidationError
  6. from sqlalchemy.orm import Session
  7. from app.session import SessionLocal
  8. from app.config import settings
  9. reusable_oauth2 = OAuth2PasswordBearer(
  10. tokenUrl=f"{settings.API_V1_STR}/login/access-token"
  11. )
  12. def get_db() -> Generator:
  13. try:
  14. db = SessionLocal()
  15. yield db
  16. finally:
  17. db.close()