befly 3.58.0 → 3.60.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.
- package/lib/connect.js +9 -1
- package/lib/dbHelper.js +19 -1
- package/package.json +2 -2
package/lib/connect.js
CHANGED
|
@@ -76,7 +76,15 @@ export class Connect {
|
|
|
76
76
|
username: config.username,
|
|
77
77
|
password: config.password,
|
|
78
78
|
max: config.max,
|
|
79
|
-
bigint: true
|
|
79
|
+
bigint: true,
|
|
80
|
+
idleTimeout: config.idleTimeout,
|
|
81
|
+
maxLifetime: config.maxLifetime,
|
|
82
|
+
connectionTimeout: config.connectionTimeout,
|
|
83
|
+
onclose: (client, err) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
Logger.warn(`MySQL 连接关闭:${err.message ?? err}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
80
88
|
});
|
|
81
89
|
|
|
82
90
|
await this.mysqlClient`SELECT 1`;
|
package/lib/dbHelper.js
CHANGED
|
@@ -323,7 +323,7 @@ class DbHelper {
|
|
|
323
323
|
return result;
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
async execute(sql, params) {
|
|
326
|
+
async execute(sql, params, retryOnConnectionClosed = true) {
|
|
327
327
|
if (!this.sql) {
|
|
328
328
|
throw new Error("数据库连接未初始化", {
|
|
329
329
|
cause: null,
|
|
@@ -389,6 +389,11 @@ class DbHelper {
|
|
|
389
389
|
} catch (error) {
|
|
390
390
|
const duration = Date.now() - startTime;
|
|
391
391
|
const msg = getExecuteErrorMessage(error);
|
|
392
|
+
|
|
393
|
+
if (retryOnConnectionClosed && this.isConnectionClosedError(error, msg)) {
|
|
394
|
+
return this.execute(sql, params, false);
|
|
395
|
+
}
|
|
396
|
+
|
|
392
397
|
const sqlInfo = {
|
|
393
398
|
sql: sql,
|
|
394
399
|
params: safeParams,
|
|
@@ -409,6 +414,19 @@ class DbHelper {
|
|
|
409
414
|
}
|
|
410
415
|
}
|
|
411
416
|
|
|
417
|
+
isConnectionClosedError(error, msg) {
|
|
418
|
+
if (error?.code === "ERR_MYSQL_CONNECTION_CLOSED") {
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
if (error?.code === "ERR_POSTGRES_CONNECTION_CLOSED") {
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
if (typeof msg === "string" && msg.includes("Connection closed")) {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
|
|
412
430
|
async tableExists(tableName) {
|
|
413
431
|
const snakeTableName = snakeCase(tableName);
|
|
414
432
|
const executeRes = await this.execute("SELECT COUNT(*) as count FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?", [snakeTableName]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.60.0",
|
|
4
4
|
"gitHead": "49c39d36695036e85fc64083cc43c1652fff96cb",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"pathe": "^2.0.3",
|
|
59
|
-
"picomatch": "^4.0.
|
|
59
|
+
"picomatch": "^4.0.5",
|
|
60
60
|
"zod": "^4.4.3"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|