增加发布正式版的命令
This commit is contained in:
32
lib/db.py
32
lib/db.py
@@ -1,24 +1,28 @@
|
||||
"""
|
||||
数据库连接配置
|
||||
"""
|
||||
import os
|
||||
import pymysql
|
||||
from contextlib import contextmanager
|
||||
from lib.logger import log_info, log_error, log_warning
|
||||
|
||||
# 数据库配置
|
||||
DB_CONFIG = {
|
||||
'host': 'haoslm2.xicp.net',
|
||||
'port': 10216,
|
||||
'user': 'root',
|
||||
'password': 'DsideaL147258369',
|
||||
'database': 'yltcharge',
|
||||
'charset': 'utf8mb4',
|
||||
'cursorclass': pymysql.cursors.DictCursor,
|
||||
'autocommit': True,
|
||||
'connect_timeout': 30, # 连接超时30秒
|
||||
'read_timeout': 60, # 读取超时60秒
|
||||
'write_timeout': 60 # 写入超时60秒
|
||||
}
|
||||
def get_db_config():
|
||||
"""从环境变量或默认值获取数据库配置"""
|
||||
return {
|
||||
'host': os.environ.get('DB_HOST', 'haoslm2.xicp.net'),
|
||||
'port': int(os.environ.get('DB_PORT', 10216)),
|
||||
'user': os.environ.get('DB_USER', 'root'),
|
||||
'password': os.environ.get('DB_PASSWORD', 'DsideaL147258369'),
|
||||
'database': os.environ.get('DB_NAME', 'yltcharge'),
|
||||
'charset': 'utf8mb4',
|
||||
'cursorclass': pymysql.cursors.DictCursor,
|
||||
'autocommit': True,
|
||||
'connect_timeout': 30,
|
||||
'read_timeout': 60,
|
||||
'write_timeout': 60
|
||||
}
|
||||
|
||||
DB_CONFIG = get_db_config()
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
||||
Reference in New Issue
Block a user