mm_sqlite 1.2.3 → 1.2.5
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 +1 -1
- 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