db_manager.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from sqlalchemy import create_engine, and_, or_, desc
  2. from sqlalchemy.orm import sessionmaker, Session
  3. class DatabaseManager1:
  4. """数据库管理类"""
  5. # mysql+pymysql://<用户名>:<密码>@<主机地址>:<端口>/<数据库名>?charset=utf8mb4
  6. def __init__(self):
  7. connection_string = (
  8. f"mysql+pymysql://wx2016_longvideo:wx2016_longvideoP%40assword1234@rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com:3306/open_aigc?charset=utf8mb4"
  9. )
  10. self.engine = create_engine(connection_string, pool_pre_ping=True, pool_recycle=3600)
  11. self.SessionLocal = sessionmaker(bind=self.engine, autoflush=False, autocommit=False)
  12. def get_session(self) -> Session:
  13. """获取数据库会话"""
  14. return self.SessionLocal()
  15. class DatabaseManager2:
  16. """数据库管理类"""
  17. # mysql+pymysql://<用户名>:<密码>@<主机地址>:<端口>/<数据库名>?charset=utf8mb4
  18. def __init__(self):
  19. connection_string = (
  20. f"mysql+pymysql://content_rw:bC1aH4bA1lB0@rm-t4nh1xx6o2a6vj8qu3o.mysql.singapore.rds.aliyuncs.com:3306/open_aigc_pattern?charset=utf8mb4"
  21. )
  22. self.engine = create_engine(connection_string, pool_pre_ping=True, pool_recycle=3600)
  23. self.SessionLocal = sessionmaker(bind=self.engine, autoflush=False, autocommit=False)
  24. def get_session(self) -> Session:
  25. """获取数据库会话"""
  26. return self.SessionLocal()