mm_sqlite 1.2.4 → 1.2.6
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/db.js +4 -4
- package/index.js +5 -4
- package/package.json +1 -1
package/db.js
CHANGED
|
@@ -7,11 +7,11 @@ const { Sql } = require('./sql');
|
|
|
7
7
|
class DB extends Sql {
|
|
8
8
|
/**
|
|
9
9
|
* @description 数据库管理器
|
|
10
|
-
* @param {object}
|
|
10
|
+
* @param {object} sqlite sqlite实例
|
|
11
11
|
*/
|
|
12
12
|
constructor(sqlite) {
|
|
13
13
|
super(sqlite.run, sqlite.exec);
|
|
14
|
-
// 保存
|
|
14
|
+
// 保存sqlite实例引用
|
|
15
15
|
this._sqlite = sqlite;
|
|
16
16
|
// 事务中
|
|
17
17
|
this.task = 0;
|
|
@@ -77,13 +77,13 @@ DB.prototype.new = function (table, key) {
|
|
|
77
77
|
* @returns {Promise<object>} 数据库连接对象
|
|
78
78
|
*/
|
|
79
79
|
DB.prototype.getConn = async function (timeout = 15000) {
|
|
80
|
-
if (!this.
|
|
80
|
+
if (!this._sqlite) {
|
|
81
81
|
throw new Error('SQLite实例未初始化');
|
|
82
82
|
}
|
|
83
83
|
try {
|
|
84
84
|
// 使用Promise.race实现超时控制
|
|
85
85
|
return await Promise.race([
|
|
86
|
-
this.
|
|
86
|
+
this._sqlite.getConn(),
|
|
87
87
|
this._createTimeoutPromise(timeout, '获取数据库连接超时')
|
|
88
88
|
]);
|
|
89
89
|
} catch (error) {
|
package/index.js
CHANGED
|
@@ -311,7 +311,8 @@ SQLite.prototype.run = async function (sql, params, timeout) {
|
|
|
311
311
|
code: error.errno,
|
|
312
312
|
message: error.message
|
|
313
313
|
};
|
|
314
|
-
|
|
314
|
+
// 不抛出错误,保持与MySQL一致的错误处理行为
|
|
315
|
+
resolve([]);
|
|
315
316
|
} else {
|
|
316
317
|
// 保持与MySQL兼容的返回值格式,始终返回数组
|
|
317
318
|
resolve(rows);
|
|
@@ -345,7 +346,7 @@ SQLite.prototype.run = async function (sql, params, timeout) {
|
|
|
345
346
|
if (err.code && (err.code === 'ECONNRESET' || err.code === 'ETIMEDOUT')) {
|
|
346
347
|
this._handleConnectionError(err);
|
|
347
348
|
}
|
|
348
|
-
//
|
|
349
|
+
// 返回空数组,保持与MySQL一致的错误处理行为
|
|
349
350
|
return [];
|
|
350
351
|
}
|
|
351
352
|
};
|
|
@@ -387,7 +388,7 @@ SQLite.prototype.exec = async function (sql, params, timeout) {
|
|
|
387
388
|
code: error.errno,
|
|
388
389
|
message: error.message
|
|
389
390
|
};
|
|
390
|
-
|
|
391
|
+
// 不抛出错误,保持与MySQL一致的错误处理行为
|
|
391
392
|
resolve(0);
|
|
392
393
|
} else {
|
|
393
394
|
// 保持与MySQL兼容的返回值格式
|
|
@@ -422,7 +423,7 @@ SQLite.prototype.exec = async function (sql, params, timeout) {
|
|
|
422
423
|
if (err.code && (err.code === 'ECONNRESET' || err.code === 'ETIMEDOUT')) {
|
|
423
424
|
this._handleConnectionError(err);
|
|
424
425
|
}
|
|
425
|
-
//
|
|
426
|
+
// 返回0,保持与MySQL一致的错误处理行为
|
|
426
427
|
return 0;
|
|
427
428
|
}
|
|
428
429
|
};
|