from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# 数据库连接 URL，根据实际情况修改用户名、密码、主机、端口和数据库名
# SQLALCHEMY_DATABASE_URL = "mysql+pymysql://root:ultrapower123@localhost:3306/ultra_me"
SQLALCHEMY_DATABASE_URL = "mysql+pymysql://root:ngsk0809cruise@localhost:33306/gcgj"
# 创建数据库引擎
engine = create_engine(SQLALCHEMY_DATABASE_URL)

# 创建会话工厂
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)


# 依赖函数，用于获取数据库会
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()
