File size: 1,168 Bytes
ff72db3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# import os
# from sqlalchemy import create_engine
# from sqlalchemy.ext.declarative import declarative_base
# from sqlalchemy.orm import sessionmaker
# from sqlalchemy.exc import SQLAlchemyError
# # MySQL ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ค์
# DATABASE_URL = os.getenv("DATABASE_URL", "mysql+mysqlconnector://root:root@10.10.10.180:3306/chathess")
# # SQLAlchemy ์์ง ์์ฑ (์์ธ ์ฒ๋ฆฌ ์ถ๊ฐ)
# try:
# engine = create_engine(DATABASE_URL)
# print("Database engine created successfully.")
# except SQLAlchemyError as e:
# print("Failed to create database engine.")
# print("Error:", e)
# engine = None
# # ์ธ์
์์ฑ (์์ง์ด None์ด๋ฉด ์ธ์
์ด๊ธฐํ ์ ํจ)
# if engine:
# SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# else:
# SessionLocal = None
# # Base ํด๋์ค ์์ฑ
# Base = declarative_base()
# # ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ธ์
์์กด์ฑ
# def get_db():
# if not SessionLocal:
# print("Database session is not available.")
# raise RuntimeError("Database is not initialized.")
# db = SessionLocal()
# try:
# yield db
# finally:
# db.close()
|