mm_mysql 1.8.1 → 1.8.2
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/package.json +1 -1
- package/sql.js +22 -18
package/package.json
CHANGED
package/sql.js
CHANGED
|
@@ -250,6 +250,7 @@ Sql.prototype.getSql = function(where, sort, view) {
|
|
|
250
250
|
* @description 添加或修改
|
|
251
251
|
* @param {String} where 查询条件
|
|
252
252
|
* @param {String} set 修改的键值
|
|
253
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
253
254
|
* @return {Promise|Object} 执行结果
|
|
254
255
|
*/
|
|
255
256
|
Sql.prototype.addOrSetSql = async function(where, set, like) {
|
|
@@ -257,7 +258,7 @@ Sql.prototype.addOrSetSql = async function(where, set, like) {
|
|
|
257
258
|
return -1;
|
|
258
259
|
}
|
|
259
260
|
if (typeof(where) === "object") {
|
|
260
|
-
where = await this.toWhere(where);
|
|
261
|
+
where = await this.toWhere(where, like);
|
|
261
262
|
}
|
|
262
263
|
var count = await this.countSql(where);
|
|
263
264
|
if (count === 0) {
|
|
@@ -412,10 +413,11 @@ Sql.prototype.groupCountSql = async function(where, groupby, view, sort) {
|
|
|
412
413
|
* @param {String} groupby 分组的字段
|
|
413
414
|
* @param {String} view 返回的字段
|
|
414
415
|
* @param {String} sort 排序方式
|
|
416
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
415
417
|
* @return {Promise|Object} 查询到的内容列表和符合条件总数
|
|
416
418
|
*/
|
|
417
|
-
Sql.prototype.groupMath = async function(query, groupby, view, sort, method) {
|
|
418
|
-
var where = this.toWhere(query,
|
|
419
|
+
Sql.prototype.groupMath = async function(query, groupby, view, sort, method, like) {
|
|
420
|
+
var where = this.toWhere(query, like);
|
|
419
421
|
return await this.groupMathSql(where, groupby, view, sort, method);
|
|
420
422
|
};
|
|
421
423
|
|
|
@@ -458,7 +460,7 @@ Sql.prototype.groupCount = async function(query, groupby, view, sort) {
|
|
|
458
460
|
/**
|
|
459
461
|
* @description 转为where语句
|
|
460
462
|
* @param {Object} obj 用作拼接的对象
|
|
461
|
-
* @param {Boolean} like 是否使用like匹配,
|
|
463
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
462
464
|
* @return {String} where格式sql语句字符串
|
|
463
465
|
*/
|
|
464
466
|
Sql.prototype.toWhere = function(obj, like) {
|
|
@@ -570,10 +572,11 @@ Sql.prototype.toAddSql = function(item) {
|
|
|
570
572
|
/**
|
|
571
573
|
* @description 转删除sql语句
|
|
572
574
|
* @param {Object} query 查询键值
|
|
575
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
573
576
|
* @return {String} sql语句
|
|
574
577
|
*/
|
|
575
|
-
Sql.prototype.toDelSql = function(query) {
|
|
576
|
-
var where = this.toWhere(query);
|
|
578
|
+
Sql.prototype.toDelSql = function(query, like) {
|
|
579
|
+
var where = this.toWhere(query, like);
|
|
577
580
|
var sql = "DELETE FROM `{0}` WHERE {1};";
|
|
578
581
|
return sql.replace("{0}", this.table).replace("{1}", where);
|
|
579
582
|
};
|
|
@@ -582,10 +585,11 @@ Sql.prototype.toDelSql = function(query) {
|
|
|
582
585
|
* @description 转修改sql语句
|
|
583
586
|
* @param {Object} query 查询的键值集合
|
|
584
587
|
* @param {Object} item 修改的键值集合
|
|
588
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
585
589
|
* @return {String} sql语句
|
|
586
590
|
*/
|
|
587
|
-
Sql.prototype.toSetSql = function(query, item) {
|
|
588
|
-
var where = this.toWhere(query);
|
|
591
|
+
Sql.prototype.toSetSql = function(query, item, like) {
|
|
592
|
+
var where = this.toWhere(query, like);
|
|
589
593
|
var set = this.toSet(item);
|
|
590
594
|
var sql = "UPDATE `{0}` SET {1} WHERE {2};";
|
|
591
595
|
return sql.replace("{0}", this.table).replace("{1}", set).replace("{2}", where);
|
|
@@ -596,10 +600,10 @@ Sql.prototype.toSetSql = function(query, item) {
|
|
|
596
600
|
* @param {Object} query 查询键值集合
|
|
597
601
|
* @param {String} sort 排序规则
|
|
598
602
|
* @param {String} view 显示的字段
|
|
599
|
-
* @param {Boolean} like 是否使用like匹配,
|
|
603
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
600
604
|
* @return {String} sql语句
|
|
601
605
|
*/
|
|
602
|
-
Sql.prototype.toGetSql = function(query, sort, view, like
|
|
606
|
+
Sql.prototype.toGetSql = function(query, sort, view, like) {
|
|
603
607
|
var where = this.toWhere(query, like);
|
|
604
608
|
var sql = this.toQuery(where, sort, view);
|
|
605
609
|
return sql;
|
|
@@ -641,10 +645,10 @@ Sql.prototype.set = function(query, item) {
|
|
|
641
645
|
* @param {Object} query 查询条件
|
|
642
646
|
* @param {String} sort 排序
|
|
643
647
|
* @param {String} view 返回的字段
|
|
644
|
-
* @param {Boolean} like 是否使用like匹配,
|
|
648
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
645
649
|
* @return {Promise|Array} 查询结果
|
|
646
650
|
*/
|
|
647
|
-
Sql.prototype.get = function(query, sort, view, like
|
|
651
|
+
Sql.prototype.get = function(query, sort, view, like) {
|
|
648
652
|
var sql = this.toGetSql(query, sort, view, like);
|
|
649
653
|
return this.run(sql);
|
|
650
654
|
};
|
|
@@ -653,7 +657,7 @@ Sql.prototype.get = function(query, sort, view, like = true) {
|
|
|
653
657
|
* @description 添加或修改
|
|
654
658
|
* @param {Object} where 查询条件集合
|
|
655
659
|
* @param {Object} set 修改的键值
|
|
656
|
-
* @param {Boolean} like 是否使用like匹配,
|
|
660
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
657
661
|
* @return {Promise|Object} 执行结果
|
|
658
662
|
*/
|
|
659
663
|
Sql.prototype.addOrSet = async function(where, set, like) {
|
|
@@ -663,10 +667,10 @@ Sql.prototype.addOrSet = async function(where, set, like) {
|
|
|
663
667
|
/**
|
|
664
668
|
* @description 查询符合结果总数
|
|
665
669
|
* @param {Object} query 查询条件集合
|
|
666
|
-
* @param {Boolean} like 是否使用like匹配,
|
|
670
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
667
671
|
* @return {Promise|Number} 查询结果
|
|
668
672
|
*/
|
|
669
|
-
Sql.prototype.count = function(query, like
|
|
673
|
+
Sql.prototype.count = function(query, like) {
|
|
670
674
|
return this.countSql(this.toWhere(query, like));
|
|
671
675
|
};
|
|
672
676
|
|
|
@@ -675,10 +679,10 @@ Sql.prototype.count = function(query, like = true) {
|
|
|
675
679
|
* @param {Object} query 查询条件
|
|
676
680
|
* @param {String} sort 排序
|
|
677
681
|
* @param {String} view 返回的字段
|
|
678
|
-
* @param {Boolean} like 是否使用like匹配,
|
|
682
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
679
683
|
* @return {Promise|Object} 查询到的内容列表和符合条件总数
|
|
680
684
|
*/
|
|
681
|
-
Sql.prototype.getCount = async function(query, sort, view, like
|
|
685
|
+
Sql.prototype.getCount = async function(query, sort, view, like) {
|
|
682
686
|
return this.getCountSql(this.toWhere(query, like), sort, view);
|
|
683
687
|
};
|
|
684
688
|
|
|
@@ -944,7 +948,7 @@ Sql.prototype.model = function(model) {
|
|
|
944
948
|
* @param {Object} query 查询条件
|
|
945
949
|
* @param {String} sort 排序
|
|
946
950
|
* @param {String} view 返回的字段
|
|
947
|
-
* @param {Boolean} like
|
|
951
|
+
* @param {Boolean} like 是否使用like匹配, 为空使用默认方式
|
|
948
952
|
* @return {Promise|Array} 查询结果
|
|
949
953
|
*/
|
|
950
954
|
Sql.prototype.getObj = async function(query, sort, view, like) {
|