mm_mysql 1.7.4 → 1.7.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/sql.js +17 -12
  3. package/test.js +7 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_mysql",
3
- "version": "1.7.4",
3
+ "version": "1.7.5",
4
4
  "description": "这是超级美眉mysql帮助函数模块,用于便捷操作mysql,使用await方式,可以避免嵌套函数",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/sql.js CHANGED
@@ -389,7 +389,6 @@ Sql.prototype.groupCountSql = async function(where, groupby, view, sort) {
389
389
  return await this.groupMathSql(where, groupby, view, sort, "COUNT");
390
390
  };
391
391
 
392
-
393
392
  /**
394
393
  * @description 统计学
395
394
  * @param {Object} query 查询条件
@@ -456,18 +455,21 @@ Sql.prototype.toWhere = function(obj, like) {
456
455
  if (val && typeof(val) === "string") {
457
456
  val = val.trim("'");
458
457
  }
458
+ val = escape(val);
459
459
  if (k.endWith('_min')) {
460
- where += " and " + escapeId(k.replace('_min', '')) + " >= " + escape(val);
460
+ where += " and " + escapeId(k.replace('_min', '')) + " >= " + val;
461
461
  } else if (k.endWith('_max')) {
462
- where += " and " + escapeId(k.replace('_max', '')) + " <= " + escape(val);
462
+ where += " and " + escapeId(k.replace('_max', '')) + " <= " + val;
463
463
  } else if (k.endWith('_not')) {
464
- where += " and " + escapeId(k.replace('_not', '')) + " != " + escape(val);
464
+ where += " and " + escapeId(k.replace('_not', '')) + " != " + val;
465
465
  } else if (k.endWith('_has')) {
466
- where += " and " + escapeId(k.replace('_has', '')) + " in (" + val + ")";
466
+ where += " and " + escapeId(k.replace('_has', '')) + " in (" + val.trim("'") + ")";
467
+ } else if (k.endWith('_like')) {
468
+ where += " and " + escapeId(k) + " LIKE '%" + val.trim("'") + "%'";
467
469
  } else if (typeof(val) === "string" && !/^[0-9]+$/.test(val)) {
468
- where += " and " + escapeId(k) + " LIKE '%" + escape(val).trim("'") + "%'"
470
+ where += " and " + escapeId(k) + " LIKE '%" + val.trim("'") + "%'";
469
471
  } else {
470
- where += " and " + escapeId(k) + " = " + val
472
+ where += " and " + escapeId(k) + " = " + val;
471
473
  }
472
474
  }
473
475
  } else {
@@ -476,16 +478,19 @@ Sql.prototype.toWhere = function(obj, like) {
476
478
  if (val && typeof(val) === "string") {
477
479
  val = val.trim("'");
478
480
  }
481
+ val = escape(val);
479
482
  if (k.endWith('_min')) {
480
- where += " and " + escapeId(k.replace('_min', '')) + " >= " + escape(val);
483
+ where += " and " + escapeId(k.replace('_min', '')) + " >= " + val;
481
484
  } else if (k.endWith('_max')) {
482
- where += " and " + escapeId(k.replace('_max', '')) + " <= " + escape(val);
485
+ where += " and " + escapeId(k.replace('_max', '')) + " <= " + val;
483
486
  } else if (k.endWith('_not')) {
484
- where += " and " + escapeId(k.replace('_not', '')) + " != " + escape(val);
487
+ where += " and " + escapeId(k.replace('_not', '')) + " != " + val;
485
488
  } else if (k.endWith('_has')) {
486
- where += " and " + escapeId(k.replace('_has', '')) + " in (" + val.replace(/`/gi, "") + ")";
489
+ where += " and " + escapeId(k.replace('_has', '')) + " in (" + val.trim("'") + ")";
490
+ } else if (k.endWith('_like')) {
491
+ where += " and " + escapeId(k) + " LIKE '%" + val.trim("'") + "%'";
487
492
  } else {
488
- where += " and " + escapeId(k) + "=" + escape(val);
493
+ where += " and " + escapeId(k) + " = " + val;
489
494
  }
490
495
  }
491
496
  }
package/test.js CHANGED
@@ -81,7 +81,7 @@ async function test_tpl_get() {
81
81
  db.table = 'user_account';
82
82
  var query = {
83
83
  gm_min: 2,
84
- username: 'ad%m'
84
+ username: 'ad%m|882'
85
85
  };
86
86
  db.page = 1;
87
87
  db.size = 5;
@@ -91,15 +91,18 @@ async function test_tpl_get() {
91
91
  console.log('查询结果', ret);
92
92
  console.log('SQL语句', db.sql);
93
93
 
94
- // var o = ret.list[0];
94
+ var o = ret.list[0];
95
95
  // console.log("查询结果", o);
96
96
  // // o.user_id = await db.count() + 1;
97
- // o.gm = "'5";
97
+ o.gm = "'5";
98
98
  // // await db.add(o);
99
+ await db.set({
100
+ user_id: o.user_id
101
+ }, o);
99
102
  // await db.addOrSet({
100
103
  // user_id: o.user_id
101
104
  // }, o);
102
- // console.log(db.sql);
105
+ console.log(db.sql);
103
106
 
104
107
  ret = await db.groupSumSql(query_str, "mc", "gm");
105
108
  console.log('求和查询结果', ret);