mm_mysql 2.0.7 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +29 -3
  2. package/package.json +3 -3
  3. package/test.js +1 -1
package/index.js CHANGED
@@ -20,7 +20,7 @@ class Mysql extends BaseService {
20
20
  host: '127.0.0.1',
21
21
  port: 3306,
22
22
  user: 'root',
23
- password: '',
23
+ password: 'Asd159357',
24
24
  database: '',
25
25
  charset: 'utf8mb4',
26
26
  timezone: '+08:00',
@@ -44,19 +44,45 @@ class Mysql extends BaseService {
44
44
  }
45
45
  }
46
46
 
47
+ /**
48
+ * 获取MySQL2支持的配置参数
49
+ * 过滤掉MySQL2不支持的参数,避免警告
50
+ * @returns {Object} 过滤后的配置对象
51
+ */
52
+ Mysql.prototype._getValidConfig = function() {
53
+ // MySQL2支持的连接配置参数
54
+ const validKeys = [
55
+ 'host', 'port', 'user', 'password', 'database',
56
+ 'charset', 'timezone', 'connectTimeout',
57
+ 'connectionLimit', 'acquireTimeout', 'waitForConnections'
58
+ ];
59
+
60
+ const filteredConfig = {};
61
+ for (const key of validKeys) {
62
+ if (key in this.config && this.config[key] !== undefined) {
63
+ filteredConfig[key] = this.config[key];
64
+ }
65
+ }
66
+
67
+ return filteredConfig;
68
+ };
69
+
47
70
  /**
48
71
  * 打开数据库连接
49
72
  * @returns {Promise<boolean>}
50
73
  */
51
74
  Mysql.prototype.open = async function() {
52
75
  try {
76
+ // 使用过滤后的配置参数,避免传递无效参数
77
+ const validConfig = this._getValidConfig();
78
+
53
79
  if (this._usePool) {
54
- this._pool = mysql.createPool(this.config);
80
+ this._pool = mysql.createPool(validConfig);
55
81
  // 测试连接池连接
56
82
  const conn = await this._pool.getConnection();
57
83
  conn.release();
58
84
  } else {
59
- this._connection = await mysql.createConnection(this.config);
85
+ this._connection = await mysql.createConnection(validConfig);
60
86
  }
61
87
 
62
88
  $.log.info(`[${this.constructor.name}] [open] 数据库连接成功`);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "mm_mysql",
3
- "version": "2.0.7",
3
+ "version": "2.1.0",
4
4
  "description": "这是超级美眉mysql帮助函数模块,用于便捷操作mysql,使用await方式,可以避免嵌套函数",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
- "mm_base_service": "^1.0.0",
8
- "mysql2": "^3.15.2"
7
+ "mm_base_service": "^1.0.2",
8
+ "mysql2": "^3.15.3"
9
9
  },
10
10
  "scripts": {
11
11
  "start": "node index.js",
package/test.js CHANGED
@@ -21,7 +21,7 @@ class TestMysql {
21
21
  host: '127.0.0.1',
22
22
  port: 3306,
23
23
  user: 'root',
24
- password: '',
24
+ password: 'Asd159357',
25
25
  database: '', // 先不指定数据库,连接成功后再创建
26
26
  debug: true,
27
27
  connectionLimit: 5