mm_mysql 2.3.9 → 2.4.1
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.
- package/index.js +5 -29
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -207,11 +207,13 @@ Mysql.prototype.run = async function (sql, params = []) {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
this.error = null;
|
|
210
|
+
this.sql = '';
|
|
210
211
|
let conn = null;
|
|
211
212
|
let ret = [];
|
|
212
213
|
try {
|
|
213
214
|
// 获取连接
|
|
214
215
|
conn = await this.getConn();
|
|
216
|
+
this.sql = sql;
|
|
215
217
|
let [rows] = await conn.query(sql, params);
|
|
216
218
|
ret = rows;
|
|
217
219
|
} catch (err) {
|
|
@@ -243,11 +245,13 @@ Mysql.prototype.exec = async function (sql, params = []) {
|
|
|
243
245
|
throw new TypeError('params must be array');
|
|
244
246
|
}
|
|
245
247
|
this.error = null;
|
|
248
|
+
this.sql = '';
|
|
246
249
|
let conn = null;
|
|
247
250
|
let ret = 0;
|
|
248
251
|
try {
|
|
249
252
|
// 获取连接
|
|
250
253
|
conn = await this.getConn();
|
|
254
|
+
this.sql = sql;
|
|
251
255
|
let [result] = await conn.execute(sql, params);
|
|
252
256
|
ret = result.insertId || result.affectedRows || result.changedRows || 1;
|
|
253
257
|
} catch (error) {
|
|
@@ -413,7 +417,7 @@ Mysql.prototype.getPoolStats = function () {
|
|
|
413
417
|
*/
|
|
414
418
|
Mysql.prototype.healthCheck = async function () {
|
|
415
419
|
try {
|
|
416
|
-
if (!this._pool && !this.
|
|
420
|
+
if (!this._pool && !this._conneced) {
|
|
417
421
|
return {
|
|
418
422
|
status: 'error',
|
|
419
423
|
message: '数据库连接未初始化'
|
|
@@ -475,34 +479,6 @@ if (!$.pool.mysql) {
|
|
|
475
479
|
$.pool.mysql = {};
|
|
476
480
|
}
|
|
477
481
|
|
|
478
|
-
/**
|
|
479
|
-
* 全局锁对象,用于线程安全
|
|
480
|
-
*/
|
|
481
|
-
if (!$.pool.mysql._locks) {
|
|
482
|
-
$.pool.mysql._locks = {};
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* 获取锁
|
|
487
|
-
* @param {string} key - 锁的键名
|
|
488
|
-
* @returns {Promise<Function>} 释放锁的函数
|
|
489
|
-
*/
|
|
490
|
-
function _acquireLock(key) {
|
|
491
|
-
if (!$.pool.mysql._locks[key]) {
|
|
492
|
-
$.pool.mysql._locks[key] = Promise.resolve();
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
let release;
|
|
496
|
-
let lockPromise = $.pool.mysql._locks[key].then(() => {
|
|
497
|
-
return new Promise(resolve => {
|
|
498
|
-
release = resolve;
|
|
499
|
-
});
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
$.pool.mysql._locks[key] = lockPromise;
|
|
503
|
-
return lockPromise.then(() => release);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
482
|
/**
|
|
507
483
|
* @description Mysql管理器,用于创建缓存(线程安全版)
|
|
508
484
|
* @param {string} scope 作用域
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_mysql",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "这是超级美眉mysql帮助函数模块,用于便捷操作mysql,使用await方式,可以避免嵌套函数",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"mm_expand": "^2.2.
|
|
8
|
-
"mysql2": "^3.22.
|
|
7
|
+
"mm_expand": "^2.2.9",
|
|
8
|
+
"mysql2": "^3.22.3",
|
|
9
9
|
"sqlstring": "^2.3.3"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"node": ">=12.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"eslint": "^10.2.
|
|
39
|
+
"eslint": "^10.2.1",
|
|
40
40
|
"eslint-plugin-jsdoc": "^62.9.0",
|
|
41
41
|
"mm_eslint": "^1.7.1"
|
|
42
42
|
}
|