25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

session.py 601 B

123456789101112131415161718192021
  1. # Information about the database session is stored here
  2. from sqlalchemy import create_engine
  3. from sqlalchemy.orm import sessionmaker
  4. from core.config import settings
  5. SQLALCHEMY_DATABASE_URL = (
  6. settings.DATABASE_URL
  7. ) # get the database url from core/config.py
  8. engine = create_engine(SQLALCHEMY_DATABASE_URL)
  9. print(SQLALCHEMY_DATABASE_URL)
  10. SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
  11. def get_db(): # get the database session (if we change the database, we can change it here)
  12. db = SessionLocal()
  13. try:
  14. yield db
  15. finally:
  16. db.close()