mm_sqlite 1.1.5 → 1.1.7
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 +64 -58
- 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>} 事务连接对象
|
|
@@ -707,36 +715,6 @@ Sqlite.prototype.table = function (name, key) {
|
|
|
707
715
|
return db;
|
|
708
716
|
};
|
|
709
717
|
|
|
710
|
-
// close 方法已在文件前面部分实现,这里不再重复
|
|
711
|
-
|
|
712
|
-
/**
|
|
713
|
-
* 确保连接池对象存在
|
|
714
|
-
*/
|
|
715
|
-
if (!$.pool) {
|
|
716
|
-
$.pool = {};
|
|
717
|
-
}
|
|
718
|
-
if (!$.pool.sqlite) {
|
|
719
|
-
$.pool.sqlite = {};
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
/**
|
|
723
|
-
* Sqlite管理器,用于创建缓存
|
|
724
|
-
* @param {String} scope 作用域
|
|
725
|
-
* @param {Object} config 配置参数
|
|
726
|
-
* @return {Object} 返回一个Sqlite类实例
|
|
727
|
-
*/
|
|
728
|
-
function sqliteAdmin(scope, config) {
|
|
729
|
-
if (!scope) {
|
|
730
|
-
scope = 'sys';
|
|
731
|
-
}
|
|
732
|
-
var obj = $.pool.sqlite[scope];
|
|
733
|
-
if (!obj) {
|
|
734
|
-
$.pool.sqlite[scope] = new Sqlite(config);
|
|
735
|
-
obj = $.pool.sqlite[scope];
|
|
736
|
-
}
|
|
737
|
-
return obj;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
718
|
/**
|
|
741
719
|
* 创建SQLite连接
|
|
742
720
|
* @private
|
|
@@ -911,6 +889,34 @@ Sqlite.prototype._closePool = function () {
|
|
|
911
889
|
this.logger('debug', '连接池已关闭');
|
|
912
890
|
};
|
|
913
891
|
|
|
892
|
+
/**
|
|
893
|
+
* 确保连接池对象存在
|
|
894
|
+
*/
|
|
895
|
+
if (!$.pool) {
|
|
896
|
+
$.pool = {};
|
|
897
|
+
}
|
|
898
|
+
if (!$.pool.sqlite) {
|
|
899
|
+
$.pool.sqlite = {};
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Sqlite管理器,用于创建缓存
|
|
904
|
+
* @param {String} scope 作用域
|
|
905
|
+
* @param {Object} config 配置参数
|
|
906
|
+
* @return {Object} 返回一个Sqlite类实例
|
|
907
|
+
*/
|
|
908
|
+
function sqliteAdmin(scope, config) {
|
|
909
|
+
if (!scope) {
|
|
910
|
+
scope = 'sys';
|
|
911
|
+
}
|
|
912
|
+
var obj = $.pool.sqlite[scope];
|
|
913
|
+
if (!obj) {
|
|
914
|
+
$.pool.sqlite[scope] = new Sqlite(config);
|
|
915
|
+
obj = $.pool.sqlite[scope];
|
|
916
|
+
}
|
|
917
|
+
return obj;
|
|
918
|
+
}
|
|
919
|
+
|
|
914
920
|
// 模块导出
|
|
915
921
|
exports.Sqlite = Sqlite;
|
|
916
922
|
exports.sqliteAdmin = sqliteAdmin;
|