mm_sqlite 1.1.5 → 1.1.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/index.js +36 -28
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -517,37 +517,45 @@ Sqlite.prototype.read = async function (table, condition, options) {
|
|
|
517
517
|
};
|
|
518
518
|
|
|
519
519
|
/**
|
|
520
|
-
*
|
|
521
|
-
* @
|
|
522
|
-
* @returns {Object} 数据库操作实例
|
|
523
|
-
* @throws {TypeError} 当database参数无效时
|
|
520
|
+
* 获取数据库管理器(保持兼容性)
|
|
521
|
+
* @returns {Object} DB实例
|
|
524
522
|
*/
|
|
525
|
-
Sqlite.prototype.db = function (
|
|
526
|
-
|
|
527
|
-
if (database !== undefined && typeof database !== 'string') {
|
|
528
|
-
throw new TypeError('database must be string');
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
if (this._status !== 'connected') {
|
|
532
|
-
throw new Error('数据库连接未建立');
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
// 优化:缓存DB实例,避免重复创建
|
|
536
|
-
if (!this._db_instance) {
|
|
537
|
-
this._db_instance = new DB(this);
|
|
538
|
-
|
|
539
|
-
// 为DB实例添加必要的方法,确保与MySQL接口兼容
|
|
540
|
-
this._db_instance.run = this.run.bind(this);
|
|
541
|
-
this._db_instance.exec = this.exec.bind(this);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
if (database) {
|
|
545
|
-
this._db_instance.database = database;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
return this._db_instance;
|
|
523
|
+
Sqlite.prototype.db = function () {
|
|
524
|
+
return new DB(this);
|
|
549
525
|
};
|
|
550
526
|
|
|
527
|
+
// /**
|
|
528
|
+
// * 获取数据库操作实例
|
|
529
|
+
// * @param {String} database - 数据库名称
|
|
530
|
+
// * @returns {Object} 数据库操作实例
|
|
531
|
+
// * @throws {TypeError} 当database参数无效时
|
|
532
|
+
// */
|
|
533
|
+
// Sqlite.prototype.db = function (database) {
|
|
534
|
+
// // 参数校验
|
|
535
|
+
// if (database !== undefined && typeof database !== 'string') {
|
|
536
|
+
// throw new TypeError('database must be string');
|
|
537
|
+
// }
|
|
538
|
+
|
|
539
|
+
// if (this._status !== 'connected') {
|
|
540
|
+
// throw new Error('数据库连接未建立');
|
|
541
|
+
// }
|
|
542
|
+
|
|
543
|
+
// // 优化:缓存DB实例,避免重复创建
|
|
544
|
+
// if (!this._db_instance) {
|
|
545
|
+
// this._db_instance = new DB(this);
|
|
546
|
+
|
|
547
|
+
// // 为DB实例添加必要的方法,确保与MySQL接口兼容
|
|
548
|
+
// this._db_instance.run = this.run.bind(this);
|
|
549
|
+
// this._db_instance.exec = this.exec.bind(this);
|
|
550
|
+
// }
|
|
551
|
+
|
|
552
|
+
// if (database) {
|
|
553
|
+
// this._db_instance.database = database;
|
|
554
|
+
// }
|
|
555
|
+
|
|
556
|
+
// return this._db_instance;
|
|
557
|
+
// };
|
|
558
|
+
|
|
551
559
|
/**
|
|
552
560
|
* 开始事务
|
|
553
561
|
* @returns {Promise<Object>} 事务连接对象
|