feature: 数据库连接与SQL集中管理,提高代码可读性
This commit is contained in:
16
robot.py
16
robot.py
@@ -58,6 +58,7 @@ from xiuren.meitu_dl import meitu_dowload_pic, meitu_dowload_pub_pic, meitu_dowl
|
||||
from xiuren.random_pic import get_xiuren_pic, get_xiuren_heisi_pic
|
||||
from xiuren.xiuren_pdf import generate_pdf_from_images
|
||||
|
||||
from db.connection import DBConnectionManager
|
||||
from message_util import MessageUtil
|
||||
|
||||
|
||||
@@ -72,13 +73,16 @@ class Robot(Job):
|
||||
self.wxid = self.wcf.get_self_wxid()
|
||||
self.allContacts = self.get_all_contacts()
|
||||
self.LOG.info(f"DB+REDIS 连接池开始初始化")
|
||||
# db 配置加载
|
||||
self.db_pool = mysql.connector.pooling.MySQLConnectionPool(
|
||||
**self.config.mariadb # 解包字典,传入 host, user, password 等
|
||||
# 初始化数据库连接管理器
|
||||
self.db_manager = DBConnectionManager(
|
||||
mysql_config=self.config.mariadb,
|
||||
redis_config=self.config.redis
|
||||
)
|
||||
self.LOG.info(f"DB连接池加载完成: {self.config.mariadb}")
|
||||
self.redis_pool = redis.ConnectionPool(**self.config.redis)
|
||||
self.LOG.info(f"REDIS连接池加载完成: {self.config.redis}")
|
||||
self.LOG.info(f"数据库连接管理器初始化完成")
|
||||
|
||||
# 为了兼容现有代码,保留原有的连接池
|
||||
self.db_pool = self.db_manager.mysql_pool
|
||||
self.redis_pool = self.db_manager.redis_pool
|
||||
|
||||
# 初始化消息工具类
|
||||
self.message_util = MessageUtil(wcf, self.allContacts)
|
||||
|
||||
Reference in New Issue
Block a user