baja-lite 1.3.36 → 1.3.38

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 (2) hide show
  1. package/package.json +1 -1
  2. package/sql.js +24 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.3.36",
3
+ "version": "1.3.38",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/util-man",
6
6
  "repository": {
package/sql.js CHANGED
@@ -1206,6 +1206,7 @@ class Build {
1206
1206
  * @param param
1207
1207
  */
1208
1208
  constructor(isCount, isSum, param = {}) {
1209
+ this.orderSeted = false;
1209
1210
  this.isCount = isCount;
1210
1211
  this.isSum = isSum;
1211
1212
  this.orderBy = param.sortName ? `${param.sortName} ${param.sortType ?? 'ASC'}` : '';
@@ -1346,6 +1347,7 @@ class Build {
1346
1347
  return '';
1347
1348
  }
1348
1349
  else {
1350
+ this.orderSeted = true;
1349
1351
  const orderBy = new Array();
1350
1352
  if (this.orderBy) {
1351
1353
  orderBy.push(this.orderBy);
@@ -1473,6 +1475,12 @@ class Build {
1473
1475
  return "''";
1474
1476
  };
1475
1477
  }
1478
+ get OrderSeted() {
1479
+ return this.orderSeted;
1480
+ }
1481
+ get OrderBy() {
1482
+ return this.orderBy;
1483
+ }
1476
1484
  }
1477
1485
  Build.page = 'COUNT(1) zccw1986 ';
1478
1486
  function replaceCdata(rawText) {
@@ -1691,14 +1699,26 @@ export class SqlCache {
1691
1699
  const buildParam = new Build(options.isCount === true, options.isSum === true, options);
1692
1700
  if (typeof sqlSource === 'function') {
1693
1701
  const _sql = sqlSource(options);
1694
- return mustache.render(_sql, buildParam, this.sqlFNMap);
1702
+ let sql = mustache.render(_sql, buildParam, this.sqlFNMap);
1703
+ if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1704
+ sql += ` ORDER BY ${buildParam.OrderBy}`;
1705
+ }
1706
+ return sql;
1695
1707
  }
1696
1708
  else if (typeof sqlSource === 'string') {
1697
- return mustache.render(sqlSource, buildParam, this.sqlFNMap);
1709
+ let sql = mustache.render(sqlSource, buildParam, this.sqlFNMap);
1710
+ if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1711
+ sql += ` ORDER BY ${buildParam.OrderBy}`;
1712
+ }
1713
+ return sql;
1698
1714
  }
1699
1715
  else if (typeof sqlSource === 'object') {
1700
1716
  const _sql = convert(sqlSource, options, matchSqlid, this.sqlMap);
1701
- return mustache.render(_sql, buildParam, this.sqlFNMap);
1717
+ let sql = mustache.render(_sql, buildParam, this.sqlFNMap);
1718
+ if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1719
+ sql += ` ORDER BY ${buildParam.OrderBy}`;
1720
+ }
1721
+ return sql;
1702
1722
  }
1703
1723
  return '';
1704
1724
  }
@@ -3517,7 +3537,7 @@ class StreamQuery {
3517
3537
  incr(key, value = 1) {
3518
3538
  const pkey = `p${this._prefix}${this._index++}`;
3519
3539
  const keyName = this[_fields][String(key)]?.C2();
3520
- this._updateColumns.push(`${keyName} = ${keyName} + :${pkey}`);
3540
+ this._updateColumns.push(`${keyName} = IFNULL(${keyName}, 0) + :${pkey}`);
3521
3541
  this._param[pkey] = value;
3522
3542
  return this;
3523
3543
  }