baja-lite 1.0.5 → 1.0.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/cjs/sql.js CHANGED
@@ -37,7 +37,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  var _a, _b, _c;
38
38
  var _d, _e, _f, _g;
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.MethodCache = exports.excuteWithCache = exports.clearMethodCache = exports.MethodLock = exports.excuteWithLock = exports.GetRedisLock = exports.getRedisDB = exports.SqlService = exports.DeclareService = exports.DeclareClass = exports.DB = exports.Field = exports.SqlCache = exports.SqliteRemote = exports.SqliteRemoteConnection = exports.Sqlite = exports.Mysql = exports._defOption = exports.SqliteMemory = exports.ColumnMode = exports.SqlType = exports.SelectResult = exports.TemplateResult = exports.SelectMode = exports.DeleteMode = exports.InsertMode = exports.SyncMode = exports.DBType = exports.logger = exports._fs = exports._path = exports._EventBus = exports._GlobalSqlOption = exports._Hump = exports._primaryDB = exports._dao = exports._sqlCache = void 0;
40
+ exports.SqlService = exports.DB = exports.Field = exports.SqlCache = exports.SqliteRemote = exports.SqliteRemoteConnection = exports.Sqlite = exports.Mysql = exports._defOption = exports.SqliteMemory = exports.ColumnMode = exports.SqlType = exports.SelectResult = exports.TemplateResult = exports.SelectMode = exports.DeleteMode = exports.InsertMode = exports.SyncMode = exports.MapperIfUndefined = exports.DBType = exports.logger = exports._fs = exports._path = exports._EventBus = exports._GlobalSqlOption = exports._Hump = exports._primaryDB = exports._dao = exports._sqlCache = void 0;
41
+ exports.flatData = flatData;
42
+ exports.DeclareClass = DeclareClass;
43
+ exports.DeclareService = DeclareService;
44
+ exports.getRedisDB = getRedisDB;
45
+ exports.GetRedisLock = GetRedisLock;
46
+ exports.excuteWithLock = excuteWithLock;
47
+ exports.MethodLock = MethodLock;
48
+ exports.clearMethodCache = clearMethodCache;
49
+ exports.excuteWithCache = excuteWithCache;
50
+ exports.MethodCache = MethodCache;
41
51
  const error_1 = require("./error");
42
52
  const tslib_1 = __importDefault(require("tslib"));
43
53
  const sqlstring_1 = __importDefault(require("sqlstring"));
@@ -51,6 +61,8 @@ const object_1 = require("./object");
51
61
  const sql_formatter_1 = require("sql-formatter");
52
62
  const html_parse_stringify_1 = __importDefault(require("html-parse-stringify"));
53
63
  const convert_xml_1 = require("./convert-xml");
64
+ const list_1 = require("./list");
65
+ const lodash_get_1 = __importDefault(require("lodash.get"));
54
66
  // #region 常量
55
67
  const _daoDBName = Symbol('dbName');
56
68
  const _tableName = Symbol('tableName');
@@ -76,6 +88,8 @@ const _inTransaction = Symbol('inTransaction');
76
88
  const _daoDB = Symbol('daoDB');
77
89
  const _sqliteRemoteName = Symbol('sqliteRemoteName');
78
90
  const _SqlOption = Symbol('SqlOption');
91
+ const _resultMap = Symbol('resultMap');
92
+ const _resultMap_SQLID = Symbol('resultMap_SQLID');
79
93
  exports._Hump = Symbol('Hump');
80
94
  exports._GlobalSqlOption = Symbol('GlobalSqlOption');
81
95
  exports._EventBus = Symbol('EventBus');
@@ -87,6 +101,7 @@ exports.logger = process.env['NODE_ENV'] !== 'production' ? (0, pino_1.default)(
87
101
  target: 'pino-pretty'
88
102
  }
89
103
  }) : (0, pino_1.default)({ name: 'sql' });
104
+ globalThis[_resultMap_SQLID] = {};
90
105
  // #endregion
91
106
  // #region 可选配置
92
107
  var DBType;
@@ -98,6 +113,15 @@ var DBType;
98
113
  DBType[DBType["Redis"] = 4] = "Redis";
99
114
  DBType[DBType["RedisLock"] = 5] = "RedisLock";
100
115
  })(DBType || (exports.DBType = DBType = {}));
116
+ ;
117
+ var MapperIfUndefined;
118
+ (function (MapperIfUndefined) {
119
+ MapperIfUndefined[MapperIfUndefined["Null"] = 0] = "Null";
120
+ MapperIfUndefined[MapperIfUndefined["Skip"] = 1] = "Skip";
121
+ MapperIfUndefined[MapperIfUndefined["Zero"] = 2] = "Zero";
122
+ MapperIfUndefined[MapperIfUndefined["EmptyString"] = 3] = "EmptyString";
123
+ })(MapperIfUndefined || (exports.MapperIfUndefined = MapperIfUndefined = {}));
124
+ ;
101
125
  var SyncMode;
102
126
  (function (SyncMode) {
103
127
  /** 同步执行 */
@@ -174,17 +198,29 @@ var TemplateResult;
174
198
  TemplateResult[TemplateResult["NotSureOne"] = 1] = "NotSureOne";
175
199
  /** 返回多条记录 */
176
200
  TemplateResult[TemplateResult["Many"] = 2] = "Many";
201
+ /** 返回多条记录并封装ArrayList */
202
+ TemplateResult[TemplateResult["ManyList"] = 3] = "ManyList";
177
203
  /** 仅查询记录数量 */
178
- TemplateResult[TemplateResult["Count"] = 3] = "Count";
204
+ TemplateResult[TemplateResult["Count"] = 4] = "Count";
179
205
  })(TemplateResult || (exports.TemplateResult = TemplateResult = {}));
180
206
  var SelectResult;
181
207
  (function (SelectResult) {
182
- SelectResult[SelectResult["One_Row_One_Column_Assert"] = 0] = "One_Row_One_Column_Assert";
183
- SelectResult[SelectResult["One_Row_One_Column_NotSure"] = 1] = "One_Row_One_Column_NotSure";
184
- SelectResult[SelectResult["One_Row_Many_Column_Assert"] = 2] = "One_Row_Many_Column_Assert";
185
- SelectResult[SelectResult["One_Row_Many_Column_NotSure"] = 3] = "One_Row_Many_Column_NotSure";
186
- SelectResult[SelectResult["Many_Row_One_Column"] = 4] = "Many_Row_One_Column";
187
- SelectResult[SelectResult["Many_Row_Many_Column"] = 5] = "Many_Row_Many_Column";
208
+ /** 一行一列 确定非空 */
209
+ SelectResult[SelectResult["R_C_Assert"] = 0] = "R_C_Assert";
210
+ /** 一行一列 可能空 */
211
+ SelectResult[SelectResult["R_C_NotSure"] = 1] = "R_C_NotSure";
212
+ /** 一行多列 确定非空 */
213
+ SelectResult[SelectResult["R_CS_Assert"] = 2] = "R_CS_Assert";
214
+ /** 一行多列 可能空 */
215
+ SelectResult[SelectResult["R_CS_NotSure"] = 3] = "R_CS_NotSure";
216
+ /** 多行一列 */
217
+ SelectResult[SelectResult["RS_C"] = 4] = "RS_C";
218
+ /** 多行一列并封装ArrayList */
219
+ SelectResult[SelectResult["RS_C_List"] = 5] = "RS_C_List";
220
+ /** 多行多列 */
221
+ SelectResult[SelectResult["RS_CS"] = 6] = "RS_CS";
222
+ /** 多行多列并封装ArrayList */
223
+ SelectResult[SelectResult["RS_CS_List"] = 7] = "RS_CS_List";
188
224
  })(SelectResult || (exports.SelectResult = SelectResult = {}));
189
225
  var SqlType;
190
226
  (function (SqlType) {
@@ -1234,26 +1270,73 @@ function replaceCdata(rawText) {
1234
1270
  }
1235
1271
  return rawText;
1236
1272
  }
1273
+ function _flatData(result, i, length, keys, V) {
1274
+ var _d;
1275
+ const key = keys[i];
1276
+ if (i < length) {
1277
+ result[_d = key] ?? (result[_d] = {});
1278
+ i++;
1279
+ _flatData(result[key], i, length, keys, V);
1280
+ }
1281
+ else {
1282
+ result[key] = V;
1283
+ }
1284
+ }
1285
+ /**
1286
+ * ifUndefined默认是MapperIfUndefined.Skip
1287
+ */
1288
+ function flatData(options) {
1289
+ if (typeof options.mapper === 'string') {
1290
+ const name = options.mapper;
1291
+ options.mapper = globalThis[_resultMap][name];
1292
+ error_1.Throw.if(!options.mapper, `not found mapper!${name}`);
1293
+ }
1294
+ options.mapperIfUndefined ?? (options.mapperIfUndefined = MapperIfUndefined.Skip);
1295
+ options.mapper = options.mapper;
1296
+ const result = {};
1297
+ for (const [columnName, keys, def] of options.mapper) {
1298
+ let V = options.data[columnName];
1299
+ if (V === undefined) {
1300
+ if (options.mapperIfUndefined === MapperIfUndefined.Null) {
1301
+ V = null;
1302
+ }
1303
+ else if (options.mapperIfUndefined === MapperIfUndefined.Zero) {
1304
+ V = 0;
1305
+ }
1306
+ else if (options.mapperIfUndefined === MapperIfUndefined.EmptyString) {
1307
+ V = '';
1308
+ }
1309
+ else if (def !== undefined) {
1310
+ V = def;
1311
+ }
1312
+ else {
1313
+ continue;
1314
+ }
1315
+ }
1316
+ _flatData(result, 0, keys.length - 1, keys, V);
1317
+ }
1318
+ return result;
1319
+ }
1237
1320
  class SqlCache {
1238
1321
  constructor() {
1239
1322
  this.sqlMap = {};
1240
1323
  this.sqlFNMap = {};
1241
1324
  }
1242
- async init(options) {
1243
- if (options.sqlMap) {
1244
- this.sqlMap = options.sqlMap;
1245
- }
1246
- const queryTypes = ['sql', 'select', 'insert', 'update', 'delete'];
1247
- if (options.sqlDir) {
1248
- const sqlFis = globalThis[exports._fs].readdirSync(options.sqlDir);
1249
- for (const modeName of sqlFis) {
1250
- exports.logger.debug(`sql: ${modeName} start explain!`);
1325
+ async _read(jsMode, sqlDir, queryTypes, rootName) {
1326
+ const sqlFis = globalThis[exports._fs].readdirSync(sqlDir);
1327
+ for (const modeName of sqlFis) {
1328
+ const file = globalThis[exports._path].join(sqlDir, modeName);
1329
+ const stat = globalThis[exports._fs].statSync(file);
1330
+ if (stat.isDirectory()) {
1331
+ await this._read(jsMode, file, queryTypes, modeName);
1332
+ }
1333
+ else {
1251
1334
  const extname = globalThis[exports._path].extname(modeName);
1252
1335
  const name = globalThis[exports._path].basename(modeName, extname);
1253
- const file = globalThis[exports._path].join(options.sqlDir, modeName);
1254
1336
  let ct = 0;
1255
1337
  if (extname === '.mu') {
1256
- const parser = new MUParser(name, globalThis[exports._fs].readFileSync(file, { encoding: 'utf-8' }).toString());
1338
+ exports.logger.debug(`sql: ${file} start explain!`);
1339
+ const parser = new MUParser(rootName || name, globalThis[exports._fs].readFileSync(file, { encoding: 'utf-8' }).toString());
1257
1340
  let source = parser.next();
1258
1341
  while (source != null) {
1259
1342
  ct++;
@@ -1261,36 +1344,88 @@ class SqlCache {
1261
1344
  exports.logger.debug(`sql: ${source[0]} found!`);
1262
1345
  source = parser.next();
1263
1346
  }
1347
+ exports.logger.debug(`sql: ${file} explain over[${ct}]!`);
1264
1348
  }
1265
- else if (extname === '.js') {
1266
- const obj = (await Promise.resolve(`${globalThis[exports._path].join(options.sqlDir, modeName)}`).then(s => __importStar(require(s)))).default;
1349
+ else if (jsMode === true && extname === '.js') {
1350
+ exports.logger.debug(`sql: ${file} start explain!`);
1351
+ const obj = (await Promise.resolve(`${globalThis[exports._path].join(sqlDir, modeName)}`).then(s => __importStar(require(s)))).default;
1267
1352
  for (const [key, fn] of Object.entries(obj)) {
1268
1353
  ct++;
1269
- this.sqlMap[`${name}.${String(key)}`] = fn;
1354
+ this.sqlMap[`${rootName || name}.${String(key)}`] = fn;
1270
1355
  }
1356
+ exports.logger.debug(`sql: ${file} explain over[${ct}]!`);
1271
1357
  }
1272
1358
  else if (extname === '.xml') {
1359
+ exports.logger.debug(`sql: ${file} start explain!`);
1273
1360
  const root = html_parse_stringify_1.default.parse(replaceCdata(globalThis[exports._fs].readFileSync(file, { encoding: 'utf-8' }).toString()))[0];
1274
1361
  if (root) {
1275
1362
  const mappers = root.children;
1276
1363
  for (const mapper of mappers) {
1277
- console.log(mapper);
1278
1364
  if (mapper.type === 'tag' && mapper.name === 'mapper') {
1279
1365
  for (const am of mapper.children) {
1280
1366
  if (am.type === 'tag') {
1281
- error_1.Throw.if(!queryTypes.includes(am.name), `${name}错误,${am.name}不支持!`);
1367
+ error_1.Throw.if(!queryTypes.includes(am.name), `${rootName} ${name}错误,${am.name}不支持!`);
1282
1368
  am.id = am.attrs['id'];
1283
- error_1.Throw.if(!am.id, `${name}错误,没有为此块设置id:${am}`);
1284
- this.sqlMap[`${name}.${am.id}`] = am.children;
1369
+ error_1.Throw.if(!am.id, `${rootName} ${name}错误,没有为此块设置id:${am}`);
1370
+ if (am.name === 'resultMap') {
1371
+ ct++;
1372
+ globalThis[_resultMap] ?? (globalThis[_resultMap] = {});
1373
+ const keys = [];
1374
+ this.readResultMap(am.children, keys, []);
1375
+ globalThis[_resultMap][am.id] = keys;
1376
+ exports.logger.debug(`sql_resultMap: ${am.id} found!`);
1377
+ }
1378
+ else {
1379
+ this.sqlMap[`${rootName || name}.${am.id}`] = am.children;
1380
+ if (am.attrs['resultMap']) {
1381
+ globalThis[_resultMap_SQLID][`${rootName || name}.${am.id}`] = am.attrs['resultMap'];
1382
+ exports.logger.debug(`sql: autoMapper: ${rootName || name}.${am.id}-${am.attrs['resultMap']}`);
1383
+ }
1384
+ exports.logger.debug(`sql: ${rootName || name}.${am.id} found!`);
1385
+ ct++;
1386
+ }
1285
1387
  }
1286
1388
  }
1287
1389
  }
1288
1390
  }
1289
1391
  }
1392
+ exports.logger.debug(`sql: ${file} explain over[${ct}]!`);
1393
+ }
1394
+ }
1395
+ }
1396
+ }
1397
+ /**
1398
+ *
1399
+ * ```
1400
+ // 第一个元素=列名,第二个元素是属性路径,
1401
+ [
1402
+ ['dit_id', ['id']], // 列名ditid,对应属性id
1403
+ ['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
1404
+ ]
1405
+ * ```
1406
+ * @param am
1407
+ * @param keys
1408
+ */
1409
+ readResultMap(ams, keys, key) {
1410
+ for (const am of ams) {
1411
+ if (am.type === 'tag') {
1412
+ if (am.name === 'result' || am.name === 'id') {
1413
+ keys.push([am.attrs['column'], [...key, am.attrs['property']]]);
1414
+ }
1415
+ else {
1416
+ this.readResultMap(am.children, keys, [...key, am.attrs['property']]);
1290
1417
  }
1291
- exports.logger.debug(`sql: ${modeName} explain over[${ct}]!`);
1292
1418
  }
1293
1419
  }
1420
+ }
1421
+ async init(options) {
1422
+ if (options.sqlMap) {
1423
+ this.sqlMap = options.sqlMap;
1424
+ }
1425
+ const queryTypes = ['sql', 'select', 'insert', 'update', 'delete', 'resultMap'];
1426
+ if (options.sqlDir) {
1427
+ await this._read(options.jsMode === true, options.sqlDir, queryTypes, '');
1428
+ }
1294
1429
  if (options.sqlFNMap) {
1295
1430
  this.sqlFNMap = options.sqlFNMap;
1296
1431
  }
@@ -1305,6 +1440,21 @@ class SqlCache {
1305
1440
  }
1306
1441
  }
1307
1442
  }
1443
+ if (options.sqlMapperMap) {
1444
+ globalThis[_resultMap] = options.sqlFNMap;
1445
+ }
1446
+ if (options.sqlMapperDir) {
1447
+ const sqlFis = globalThis[exports._fs].readdirSync(options.sqlDir);
1448
+ globalThis[_resultMap] ?? (globalThis[_resultMap] = {});
1449
+ for (const modeName of sqlFis) {
1450
+ const extname = globalThis[exports._path].extname(modeName);
1451
+ const name = globalThis[exports._path].basename(modeName, extname);
1452
+ const file = globalThis[exports._path].join(options.sqlDir, modeName);
1453
+ if (extname === 'json') {
1454
+ globalThis[_resultMap][name] = JSON.parse(globalThis[exports._fs].readFileSync(file, { encoding: 'utf-8' }).toString());
1455
+ }
1456
+ }
1457
+ }
1308
1458
  }
1309
1459
  load(sqlids, options) {
1310
1460
  let sqlSource;
@@ -1316,19 +1466,21 @@ class SqlCache {
1316
1466
  }
1317
1467
  const matchSqlid = sqlids.map(i => i.split('.')[0]);
1318
1468
  error_1.Throw.if(!sqlSource, `指定的语句${sqlids.join('|')}不存在!`);
1469
+ const buildParam = new Build(options.isCount === true, options.isSum === true, options);
1319
1470
  if (typeof sqlSource === 'function') {
1320
1471
  const _sql = sqlSource(options);
1321
- const buildParam = new Build(options.isCount === true, options.isSum === true, options);
1322
1472
  const sql = mustache_1.default.render(_sql, buildParam, this.sqlFNMap);
1323
1473
  return (0, sql_formatter_1.format)(sql);
1324
1474
  }
1325
1475
  else if (typeof sqlSource === 'string') {
1326
- const buildParam = new Build(options.isCount === true, options.isSum === true, options);
1327
1476
  const sql = mustache_1.default.render(sqlSource, buildParam, this.sqlFNMap);
1328
1477
  return (0, sql_formatter_1.format)(sql);
1329
1478
  }
1330
1479
  else if (typeof sqlSource === 'object') {
1331
- const sql = (0, convert_xml_1.convert)(sqlSource, options, matchSqlid, this.sqlMap);
1480
+ const _sql = (0, convert_xml_1.convert)(sqlSource, options, matchSqlid, this.sqlMap);
1481
+ console.log(_sql);
1482
+ const sql = mustache_1.default.render(_sql, buildParam, this.sqlFNMap);
1483
+ console.log(sql);
1332
1484
  return (0, sql_formatter_1.format)(sql);
1333
1485
  }
1334
1486
  return '';
@@ -1942,7 +2094,6 @@ function DeclareClass(clz, FieldOptions) {
1942
2094
  tslib_1.default.__decorate([(0, exports.Field)(item)], clz.prototype, item.P, void 0);
1943
2095
  }
1944
2096
  }
1945
- exports.DeclareClass = DeclareClass;
1946
2097
  /**
1947
2098
  JS项目中,service注解代替,举例:
1948
2099
  ```
@@ -1959,7 +2110,6 @@ exports.DeclareClass = DeclareClass;
1959
2110
  function DeclareService(clz, config) {
1960
2111
  return tslib_1.default.__decorate([(0, exports.DB)(config)], clz);
1961
2112
  }
1962
- exports.DeclareService = DeclareService;
1963
2113
  /**
1964
2114
  ## 数据库服务
1965
2115
  ### 注解DB
@@ -2376,9 +2526,10 @@ class SqlService {
2376
2526
  )`;
2377
2527
  }).join(' OR ');
2378
2528
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2529
+ params.unshift(this[_deleteState]);
2379
2530
  sqls.push({
2380
2531
  sql: (0, sql_formatter_1.format)(`
2381
- UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ${sqlstring_1.default.escape(this[_deleteState])}
2532
+ UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2382
2533
  WHERE ${whereSql};
2383
2534
  `), params
2384
2535
  });
@@ -2397,7 +2548,8 @@ class SqlService {
2397
2548
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2398
2549
  sqls.push({
2399
2550
  sql: (0, sql_formatter_1.format)(`UPDATE ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.C2()} = b.${this[_fields][K]?.C2()}`).join(' AND ')}
2400
- SET a.${this[_fields][this[_stateFileName]]?.C2()} = ${sqlstring_1.default.escape(this[_deleteState])};`)
2551
+ SET a.${this[_fields][this[_stateFileName]]?.C2()} = ?;`),
2552
+ params: [this[_deleteState]]
2401
2553
  });
2402
2554
  }
2403
2555
  else {
@@ -2412,8 +2564,9 @@ class SqlService {
2412
2564
  const columnNames = (0, iterare_1.default)(delWhere).map(K => this[_fields][K]?.C2()).join(',');
2413
2565
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2414
2566
  sqls.push({
2415
- sql: (0, sql_formatter_1.format)(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ${sqlstring_1.default.escape(this[_deleteState])}
2416
- WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`)
2567
+ sql: (0, sql_formatter_1.format)(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2568
+ WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`),
2569
+ params: [this[_deleteState]]
2417
2570
  });
2418
2571
  }
2419
2572
  else {
@@ -2480,6 +2633,9 @@ class SqlService {
2480
2633
  case TemplateResult.Count: {
2481
2634
  return result[0].ct;
2482
2635
  }
2636
+ case TemplateResult.ManyList: {
2637
+ return new list_1.ArrayList(result[0]);
2638
+ }
2483
2639
  }
2484
2640
  }
2485
2641
  template(option) {
@@ -2556,153 +2712,135 @@ class SqlService {
2556
2712
  });
2557
2713
  }
2558
2714
  }
2559
- _select(templateResult, result, def, errorMsg, multiple, hump) {
2560
- if (multiple === true) {
2561
- switch (templateResult) {
2562
- case SelectResult.One_Row_One_Column_NotSure: {
2563
- try {
2564
- return result.map((r) => Object.values(r)[0]);
2565
- }
2566
- catch (error) {
2567
- }
2715
+ _select(templateResult, result, def, errorMsg, hump, mapper, mapperIfUndefined) {
2716
+ switch (templateResult) {
2717
+ case SelectResult.R_C_NotSure: {
2718
+ try {
2719
+ return Object.values(result[0])[0];
2568
2720
  }
2569
- case SelectResult.One_Row_One_Column_Assert: {
2570
- try {
2571
- return (0, iterare_1.default)(result).map((r) => Object.values(r)[0]).filter((r) => r !== null).toArray();
2572
- }
2573
- catch (error) {
2574
- }
2721
+ catch (error) {
2722
+ return def;
2575
2723
  }
2576
- case SelectResult.One_Row_Many_Column_NotSure: {
2577
- try {
2578
- if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2579
- return result.map((r) => (0, object_1.C2P2)(r[0]));
2580
- }
2581
- return result.map((r) => r[0]);
2582
- }
2583
- catch (error) {
2584
- }
2724
+ }
2725
+ case SelectResult.R_C_Assert: {
2726
+ try {
2727
+ return Object.values(result[0])[0];
2585
2728
  }
2586
- case SelectResult.One_Row_Many_Column_Assert: {
2587
- try {
2588
- if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2589
- return (0, iterare_1.default)(result).map((r) => (0, object_1.C2P2)(r[0])).filter((r) => r !== null).toArray();
2590
- }
2591
- return (0, iterare_1.default)(result).map((r) => r[0]).filter((r) => r !== null).toArray();
2592
- }
2593
- catch (error) {
2594
- }
2729
+ catch (error) {
2730
+ if (def !== undefined)
2731
+ return def;
2732
+ error_1.Throw.now(errorMsg ?? 'not found data!');
2595
2733
  }
2596
- case SelectResult.Many_Row_One_Column: {
2597
- try {
2598
- return result.map((rx) => rx.map((r) => Object.values(r)[0]));
2599
- }
2600
- catch (error) {
2601
- }
2734
+ }
2735
+ case SelectResult.R_CS_NotSure: {
2736
+ if (mapper) {
2737
+ return flatData({ data: result[0], mapper, mapperIfUndefined });
2602
2738
  }
2603
- case SelectResult.Many_Row_Many_Column: {
2604
- if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2605
- return (0, iterare_1.default)(result).map((r) => r.map((rr) => (0, object_1.C2P2)(rr))).toArray();
2606
- }
2607
- else {
2608
- return result;
2609
- }
2739
+ else if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2740
+ return (0, object_1.C2P2)(result[0]) ?? null;
2741
+ }
2742
+ else {
2743
+ return result[0] ?? null;
2610
2744
  }
2611
2745
  }
2612
- }
2613
- else {
2614
- switch (templateResult) {
2615
- case SelectResult.One_Row_One_Column_NotSure: {
2616
- try {
2617
- return Object.values(result[0])[0];
2618
- }
2619
- catch (error) {
2620
- return def;
2621
- }
2746
+ case SelectResult.R_CS_Assert: {
2747
+ const data = result[0];
2748
+ error_1.Throw.if(data === null || data === undefined, errorMsg ?? 'not found data!');
2749
+ if (mapper) {
2750
+ return flatData({ data, mapper, mapperIfUndefined });
2622
2751
  }
2623
- case SelectResult.One_Row_One_Column_Assert: {
2624
- try {
2625
- return Object.values(result[0])[0];
2626
- }
2627
- catch (error) {
2628
- if (def !== undefined)
2629
- return def;
2630
- error_1.Throw.now(errorMsg ?? 'not found data!');
2631
- }
2752
+ else if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2753
+ return (0, object_1.C2P2)(data) ?? null;
2632
2754
  }
2633
- case SelectResult.One_Row_Many_Column_NotSure: {
2634
- if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2635
- return (0, object_1.C2P2)(result[0]) ?? null;
2636
- }
2637
- else {
2638
- return result[0] ?? null;
2639
- }
2755
+ else {
2756
+ return data ?? null;
2640
2757
  }
2641
- case SelectResult.One_Row_Many_Column_Assert: {
2642
- const data = result[0];
2643
- error_1.Throw.if(data === null || data === undefined, errorMsg ?? 'not found data!');
2644
- if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2645
- return (0, object_1.C2P2)(data) ?? null;
2646
- }
2647
- else {
2648
- return data ?? null;
2649
- }
2758
+ }
2759
+ case SelectResult.RS_C: {
2760
+ try {
2761
+ return result.map((r) => Object.values(r)[0]);
2650
2762
  }
2651
- case SelectResult.Many_Row_One_Column: {
2652
- try {
2653
- return result.map((r) => Object.values(r)[0]);
2654
- }
2655
- catch (error) {
2656
- return def;
2657
- }
2763
+ catch (error) {
2764
+ return result;
2658
2765
  }
2659
- case SelectResult.Many_Row_Many_Column: {
2660
- if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2661
- return (0, iterare_1.default)(result).map((r) => (0, object_1.C2P2)(r)).toArray();
2662
- }
2663
- else {
2664
- return result;
2665
- }
2766
+ }
2767
+ case SelectResult.RS_CS: {
2768
+ if (mapper) {
2769
+ return (0, iterare_1.default)(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray();
2770
+ }
2771
+ else if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2772
+ return (0, iterare_1.default)(result).map((r) => (0, object_1.C2P2)(r)).toArray();
2773
+ }
2774
+ else {
2775
+ return result;
2776
+ }
2777
+ }
2778
+ case SelectResult.RS_C_List: {
2779
+ try {
2780
+ return new list_1.ArrayList(result.map((r) => Object.values(r)[0]));
2781
+ }
2782
+ catch (error) {
2783
+ return new list_1.ArrayList();
2784
+ }
2785
+ }
2786
+ case SelectResult.RS_CS_List: {
2787
+ if (mapper) {
2788
+ return new list_1.ArrayList((0, iterare_1.default)(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray());
2789
+ }
2790
+ else if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
2791
+ return new list_1.ArrayList((0, iterare_1.default)(result).map((r) => (0, object_1.C2P2)(r)).toArray());
2792
+ }
2793
+ else {
2794
+ return new list_1.ArrayList();
2666
2795
  }
2667
2796
  }
2668
2797
  }
2669
2798
  }
2670
2799
  select(option) {
2671
2800
  error_1.Throw.if(!option.sqlId && !option.sql, 'not found sql!');
2672
- option.selectResult ?? (option.selectResult = SelectResult.Many_Row_Many_Column);
2801
+ option.selectResult ?? (option.selectResult = SelectResult.RS_CS);
2673
2802
  option.defValue ?? (option.defValue = null);
2803
+ if (option.sqlId && globalThis[_resultMap_SQLID][option.sqlId] && !option.mapper) {
2804
+ option.mapper = globalThis[_resultMap_SQLID][option.sqlId];
2805
+ }
2674
2806
  const _params = Object.assign({}, option.context, option.params);
2675
2807
  option.sql ?? (option.sql = globalThis[exports._sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: option.isCount, ..._params }));
2676
2808
  const params = [];
2677
- const sql = option.sql?.replace(/\:(\w+)/g, (txt, key) => {
2678
- if (_params.hasOwnProperty(key)) {
2679
- const V = _params[key];
2680
- params.push(V);
2681
- return sqlstring_1.default.escape(_params[key]);
2809
+ const sql = option.sql?.replace(/\:([A-Za-z0-9._]+)/g, (txt, key) => {
2810
+ let V = (0, lodash_get_1.default)(_params, key);
2811
+ if (V) {
2812
+ if (V !== undefined) {
2813
+ params.push(V);
2814
+ }
2815
+ return '?';
2682
2816
  }
2683
2817
  const _key = (0, object_1.C2P)(key);
2684
- if (_params.hasOwnProperty(_key)) {
2685
- const V = _params[_key];
2686
- params.push(V);
2687
- return sqlstring_1.default.escape(_params[_key]);
2818
+ V = (0, lodash_get_1.default)(_params, _key);
2819
+ if (V) {
2820
+ if (V !== undefined) {
2821
+ params.push(V);
2822
+ }
2823
+ return '?';
2688
2824
  }
2689
2825
  const __key = (0, object_1.P2C)(key);
2690
- if (_params.hasOwnProperty(__key)) {
2691
- const V = _params[__key];
2692
- params.push(V);
2693
- return sqlstring_1.default.escape(_params[__key]);
2826
+ V = (0, lodash_get_1.default)(_params, __key);
2827
+ if (V) {
2828
+ if (V !== undefined) {
2829
+ params.push(V);
2830
+ }
2831
+ return '?';
2694
2832
  }
2695
2833
  return txt;
2696
2834
  });
2697
2835
  if (option.sync === SyncMode.Sync) {
2698
2836
  const result = option.conn.query(SyncMode.Sync, sql, params);
2699
- return this._select(option.selectResult, result, option.defValue, option.errorMsg, option.multiple, option.hump);
2837
+ return this._select(option.selectResult, result, option.defValue, option.errorMsg, option.hump, option.mapper, option.mapperIfUndefined);
2700
2838
  }
2701
2839
  else {
2702
2840
  return new Promise(async (resolve, reject) => {
2703
2841
  try {
2704
2842
  const result = await option.conn.query(SyncMode.Async, sql, params);
2705
- resolve(this._select(option.selectResult, result, option.defValue, option.errorMsg, option.multiple));
2843
+ resolve(this._select(option.selectResult, result, option.defValue, option.errorMsg, option.hump, option.mapper, option.mapperIfUndefined));
2706
2844
  }
2707
2845
  catch (error) {
2708
2846
  reject(error);
@@ -2716,22 +2854,28 @@ class SqlService {
2716
2854
  option.sql ?? (option.sql = globalThis[exports._sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, ..._params }));
2717
2855
  const params = [];
2718
2856
  const sql = option.sql?.replace(/\:(\w+)/g, (txt, key) => {
2719
- if (_params.hasOwnProperty(key)) {
2720
- const V = _params[key];
2721
- params.push(V);
2722
- return sqlstring_1.default.escape(_params[key]);
2857
+ let V = (0, lodash_get_1.default)(_params, key);
2858
+ if (V) {
2859
+ if (V !== undefined) {
2860
+ params.push(V);
2861
+ }
2862
+ return '?';
2723
2863
  }
2724
2864
  const _key = (0, object_1.C2P)(key);
2725
- if (_params.hasOwnProperty(_key)) {
2726
- const V = _params[_key];
2727
- params.push(V);
2728
- return sqlstring_1.default.escape(_params[_key]);
2865
+ V = (0, lodash_get_1.default)(_params, _key);
2866
+ if (V) {
2867
+ if (V !== undefined) {
2868
+ params.push(V);
2869
+ }
2870
+ return '?';
2729
2871
  }
2730
2872
  const __key = (0, object_1.P2C)(key);
2731
- if (_params.hasOwnProperty(__key)) {
2732
- const V = _params[__key];
2733
- params.push(V);
2734
- return sqlstring_1.default.escape(_params[__key]);
2873
+ V = (0, lodash_get_1.default)(_params, __key);
2874
+ if (V) {
2875
+ if (V !== undefined) {
2876
+ params.push(V);
2877
+ }
2878
+ return '?';
2735
2879
  }
2736
2880
  return txt;
2737
2881
  });
@@ -2812,7 +2956,7 @@ class SqlService {
2812
2956
  ...option,
2813
2957
  sql: sqlCount,
2814
2958
  sync: SyncMode.Sync,
2815
- selectResult: SelectResult.One_Row_One_Column_Assert
2959
+ selectResult: SelectResult.R_C_Assert
2816
2960
  });
2817
2961
  result.size = (0, math_1.calc)(result.total)
2818
2962
  .add(option.pageSize - 1)
@@ -2825,7 +2969,7 @@ class SqlService {
2825
2969
  ...option,
2826
2970
  sql: sqlSum,
2827
2971
  sync: SyncMode.Sync,
2828
- selectResult: SelectResult.One_Row_Many_Column_Assert
2972
+ selectResult: SelectResult.R_CS_Assert
2829
2973
  });
2830
2974
  }
2831
2975
  if (sql) {
@@ -2833,7 +2977,7 @@ class SqlService {
2833
2977
  ...option,
2834
2978
  sql,
2835
2979
  sync: SyncMode.Sync,
2836
- selectResult: SelectResult.Many_Row_Many_Column
2980
+ selectResult: SelectResult.RS_CS
2837
2981
  });
2838
2982
  }
2839
2983
  return result;
@@ -2846,7 +2990,7 @@ class SqlService {
2846
2990
  ...option,
2847
2991
  sql: sqlCount,
2848
2992
  sync: SyncMode.Async,
2849
- selectResult: SelectResult.One_Row_One_Column_Assert
2993
+ selectResult: SelectResult.R_C_Assert
2850
2994
  });
2851
2995
  result.size = (0, math_1.calc)(result.total)
2852
2996
  .add(option.pageSize - 1)
@@ -2859,7 +3003,7 @@ class SqlService {
2859
3003
  ...option,
2860
3004
  sql: sqlSum,
2861
3005
  sync: SyncMode.Async,
2862
- selectResult: SelectResult.One_Row_Many_Column_Assert
3006
+ selectResult: SelectResult.R_CS_Assert
2863
3007
  });
2864
3008
  }
2865
3009
  if (sql) {
@@ -2867,7 +3011,7 @@ class SqlService {
2867
3011
  ...option,
2868
3012
  sql,
2869
3013
  sync: SyncMode.Async,
2870
- selectResult: SelectResult.Many_Row_Many_Column
3014
+ selectResult: SelectResult.RS_CS
2871
3015
  });
2872
3016
  }
2873
3017
  resolve(result);
@@ -3110,8 +3254,9 @@ class StreamQuery {
3110
3254
  this.if_proceed = condition;
3111
3255
  return this;
3112
3256
  }
3113
- eq(key, value, { name } = {}) { return this._(key, value, '=', { name }); }
3114
- eqT(t, { name } = {}) {
3257
+ eq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3258
+ eqT(t, { name: paramName = '', breakExcuteIfSkip = false } = {}) {
3259
+ let exe = false;
3115
3260
  if (t) {
3116
3261
  t = this._service[_transformer](t, {
3117
3262
  skipNull: true,
@@ -3120,8 +3265,8 @@ class StreamQuery {
3120
3265
  });
3121
3266
  const keys = Object.keys(t);
3122
3267
  if (keys.length > 0) {
3123
- if (name && this._paramKeys[name]) {
3124
- for (const [key, pname] of Object.entries(this._paramKeys[name])) {
3268
+ if (paramName && this._paramKeys[paramName]) {
3269
+ for (const [key, pname] of Object.entries(this._paramKeys[paramName])) {
3125
3270
  this._param[pname] = t[key];
3126
3271
  }
3127
3272
  }
@@ -3131,75 +3276,79 @@ class StreamQuery {
3131
3276
  const pkey = `p${this._prefix}${this._index++}`;
3132
3277
  this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} = :${pkey} `);
3133
3278
  this._param[pkey] = value;
3134
- if (name) {
3279
+ if (paramName) {
3135
3280
  paramKeys[key] = pkey;
3136
3281
  }
3137
3282
  }
3138
- if (name) {
3139
- this._paramKeys[name] = paramKeys;
3283
+ if (paramName) {
3284
+ this._paramKeys[paramName] = paramKeys;
3140
3285
  }
3141
3286
  }
3287
+ exe = true;
3142
3288
  }
3143
3289
  }
3290
+ if (breakExcuteIfSkip === true && exe === false) {
3291
+ this.if_exec = false;
3292
+ }
3144
3293
  return this;
3145
3294
  }
3146
- notEq(key, value, { name } = {}) { return this._(key, value, '<>', { name }); }
3295
+ notEq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '<>', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3147
3296
  eqWith(key1, key2) { return this._key(key1, key2, '='); }
3148
3297
  notEqWith(key1, key2) { return this._key(key1, key2, '<>'); }
3149
- regexp(key, regexp, { name } = {}) { return this._(key, regexp, 'REGEXP', { name }); }
3150
- notRegexp(key, regexp, { name } = {}) { return this._(key, regexp, 'REGEXP', { name, not: 'NOT' }); }
3298
+ regexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3299
+ notRegexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, not: 'NOT', breakExcuteIfSkip }); }
3151
3300
  /** (key1 << 8) + key2 = value */
3152
- shiftEq(key1, key2, value, { name } = {}) { return this._shift(key1, key2, value, '=', { name }); }
3301
+ shiftEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._shift(key1, key2, value, '=', { paramName, breakExcuteIfSkip }); }
3153
3302
  /** (key1 << 8) + key2 <> value */
3154
- shiftNotEq(key1, key2, value, { name } = {}) { return this._shift(key1, key2, value, '<>', { name }); }
3155
- grate(key, value, { name } = {}) { return this._(key, value, '>', { name }); }
3156
- grateEq(key, value, { name } = {}) { return this._(key, value, '>=', { name }); }
3303
+ shiftNotEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._shift(key1, key2, value, '<>', { paramName, breakExcuteIfSkip }); }
3304
+ grate(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '>', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3305
+ grateEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '>=', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3157
3306
  grateWith(key1, key2) { return this._key(key1, key2, '>'); }
3158
3307
  grateEqWith(key1, key2) { return this._key(key1, key2, '>='); }
3159
- less(key, value, { name } = {}) { return this._(key, value, '<', { name }); }
3160
- lessEq(key, value, { name } = {}) { return this._(key, value, '<=', { name }); }
3308
+ less(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '<', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3309
+ lessEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '<=', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3161
3310
  lessWith(key1, key2) { return this._key(key1, key2, '<'); }
3162
3311
  lessEqWith(key1, key2) { return this._key(key1, key2, '<='); }
3163
- like(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', right: '%', force }); }
3164
- notLike(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', right: '%', not: 'NOT', force }); }
3165
- leftLike(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', force }); }
3166
- notLeftLike(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', not: 'NOT', force }); }
3167
- rightLike(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', force }); }
3168
- notRightLike(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', not: 'NOT', force }); }
3169
- PreciseLike(key, value, { name, force } = {}) { return this._like(key, value, { name, force }); }
3170
- notPreciseLike(key, value, { name, force } = {}) { return this._like(key, value, { name, not: 'NOT', force }); }
3171
- glob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', right: '%', force, op: 'GLOB' }); }
3172
- notGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', right: '%', not: 'NOT', force, op: 'GLOB' }); }
3173
- leftGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', force, op: 'GLOB' }); }
3174
- notLeftGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', not: 'NOT', force, op: 'GLOB' }); }
3175
- rightGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', force, op: 'GLOB' }); }
3176
- notRightGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', not: 'NOT', force, op: 'GLOB' }); }
3177
- PreciseGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, force, op: 'GLOB' }); }
3178
- notPreciseGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, not: 'NOT', force, op: 'GLOB' }); }
3179
- in(key, value, { name, force } = {}) { return this._in(key, value, { name, force }); }
3180
- notIn(key, value, { name, force } = {}) { return this._in(key, value, { name, not: 'NOT', force }); }
3312
+ like(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip }); }
3313
+ notLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', not: 'NOT', breakExcuteIfSkip }); }
3314
+ leftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip }); }
3315
+ notLeftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip }); }
3316
+ rightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip }); }
3317
+ notRightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip }); }
3318
+ PreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3319
+ notPreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3320
+ glob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3321
+ notGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3322
+ leftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3323
+ notLeftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3324
+ rightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3325
+ notRightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3326
+ PreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip, op: 'GLOB' }); }
3327
+ notPreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3328
+ in(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._in(key, value, { paramName, breakExcuteIfSkip }); }
3329
+ notIn(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._in(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3181
3330
  isNULL(key) { return this._null(key); }
3182
3331
  isNotNULL(key) { return this._null(key, 'NOT'); }
3183
- between(key, value1, value2, { name } = {}) { return this._between(key, value1, value2, { name }); }
3184
- notBetween(key, value1, value2, { name } = {}) { return this._between(key, value1, value2, { name, not: 'NOT' }); }
3185
- pow(key, value, { name } = {}) { return this._pow(key, value, { name }); }
3186
- notPow(key, value, { name } = {}) { return this._pow(key, value, { name, not: 'NOT' }); }
3187
- powWith(key, values, { name } = {}) { return this._pow(key, (0, math_1.add)(...values.map(value => Math.pow(2, +value))), { name }); }
3188
- notPowWith(key, values, { name } = {}) { return this._pow(key, (0, math_1.add)(...values.map(value => Math.pow(2, +value))), { name, not: 'NOT' }); }
3332
+ between(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._between(key, value1, value2, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3333
+ notBetween(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._between(key, value1, value2, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3334
+ pow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, value, { paramName, breakExcuteIfSkip }); }
3335
+ notPow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, value, { paramName, not: 'NOT', breakExcuteIfSkip }); }
3336
+ powWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, (0, math_1.add)(...values.map(value => Math.pow(2, +value))), { paramName, breakExcuteIfSkip }); }
3337
+ notPowWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, (0, math_1.add)(...values.map(value => Math.pow(2, +value))), { paramName, not: 'NOT', breakExcuteIfSkip }); }
3189
3338
  /** MATCH(key1, key2, key3) AGAINST (value) */
3190
- match(value, keys, { name } = {}) { return this._match(value, keys, { name }); }
3339
+ match(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3191
3340
  /** NOT MATCH(key1, key2, key3) AGAINST (value) */
3192
- notMatch(value, keys, { name } = {}) { return this._match(value, keys, { name, not: 'NOT' }); }
3341
+ notMatch(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3193
3342
  /** MATCH(key1, key2, key3) AGAINST (value) IN BOOLEAN MODE*/
3194
- matchBoolean(value, keys, { name } = {}) { return this._match(value, keys, { name, append: 'IN BOOLEAN MODE' }); }
3343
+ matchBoolean(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'IN BOOLEAN MODE' }); }
3195
3344
  /** NOT MATCH(key1, key2, key3) AGAINST (value) IN BOOLEAN MODE */
3196
- notMatchBoolean(value, keys, { name } = {}) { return this._match(value, keys, { name, not: 'NOT', append: 'IN BOOLEAN MODE' }); }
3345
+ notMatchBoolean(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, not: 'NOT', append: 'IN BOOLEAN MODE' }); }
3197
3346
  /** MATCH(key1, key2, key3) AGAINST (value) WITH QUERY EXPANSION*/
3198
- matchQuery(value, keys, { name } = {}) { return this._match(value, keys, { name, append: 'WITH QUERY EXPANSION' }); }
3347
+ matchQuery(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'WITH QUERY EXPANSION' }); }
3199
3348
  /** NOT MATCH(key1, key2, key3) AGAINST (value) WITH QUERY EXPANSION*/
3200
- notMatchQuery(value, keys, { name } = {}) { return this._match(value, keys, { name, not: 'NOT', append: 'WITH QUERY EXPANSION' }); }
3201
- includes(key, value, { name } = {}) { return this._includes(key, value, { name }); }
3202
- notIncludes(key, value, { name } = {}) { return this._includes(key, value, { name, not: 'NOT' }); }
3349
+ notMatchQuery(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, not: 'NOT', append: 'WITH QUERY EXPANSION' }); }
3350
+ includes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._includes(key, value, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3351
+ notIncludes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._includes(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3203
3352
  and(fn) {
3204
3353
  if (fn instanceof StreamQuery) {
3205
3354
  this._andQuerys.push(fn);
@@ -3266,7 +3415,7 @@ class StreamQuery {
3266
3415
  excuteSelect(option) {
3267
3416
  option ?? (option = {});
3268
3417
  option.sync ?? (option.sync = SyncMode.Async);
3269
- option.selectResult ?? (option.selectResult = SelectResult.Many_Row_Many_Column);
3418
+ option.selectResult ?? (option.selectResult = SelectResult.RS_CS);
3270
3419
  const { where, params } = this._where();
3271
3420
  let sql = `
3272
3421
  SELECT
@@ -3274,6 +3423,8 @@ class StreamQuery {
3274
3423
  FROM ${this._table}
3275
3424
  ${where ? ' WHERE ' : ''}
3276
3425
  ${where}
3426
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3427
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3277
3428
  `;
3278
3429
  if (this._startRow && this._pageSize) {
3279
3430
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -3283,25 +3434,113 @@ class StreamQuery {
3283
3434
  }
3284
3435
  if (option.sync === SyncMode.Async) {
3285
3436
  switch (option.selectResult) {
3286
- case SelectResult.Many_Row_Many_Column: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.Many_Row_Many_Column, errorMsg: option.errorMsg, sql, params });
3287
- case SelectResult.Many_Row_One_Column: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.Many_Row_One_Column, errorMsg: option.errorMsg, sql, params });
3288
- case SelectResult.One_Row_Many_Column_Assert: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_Many_Column_Assert, errorMsg: option.errorMsg, sql, params });
3289
- case SelectResult.One_Row_One_Column_Assert: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_One_Column_Assert, errorMsg: option.errorMsg, sql, params });
3290
- case SelectResult.One_Row_Many_Column_NotSure: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_Many_Column_NotSure, errorMsg: option.errorMsg, sql, params });
3291
- case SelectResult.One_Row_One_Column_NotSure: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_One_Column_NotSure, errorMsg: option.errorMsg, sql, params });
3437
+ case SelectResult.RS_CS: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_CS, sql, params });
3438
+ case SelectResult.RS_C: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_C, sql, params });
3439
+ case SelectResult.RS_CS_List: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_CS_List, sql, params });
3440
+ case SelectResult.RS_C_List: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_C_List, sql, params });
3441
+ case SelectResult.R_CS_Assert: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_CS_Assert, sql, params });
3442
+ case SelectResult.R_C_Assert: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_C_Assert, sql, params });
3443
+ case SelectResult.R_CS_NotSure: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_CS_NotSure, sql, params });
3444
+ case SelectResult.R_C_NotSure: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_C_NotSure, sql, params });
3292
3445
  }
3293
3446
  }
3294
3447
  else {
3295
3448
  switch (option.selectResult) {
3296
- case SelectResult.Many_Row_Many_Column: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.Many_Row_Many_Column, errorMsg: option.errorMsg, sql, params });
3297
- case SelectResult.Many_Row_One_Column: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.Many_Row_One_Column, errorMsg: option.errorMsg, sql, params });
3298
- case SelectResult.One_Row_Many_Column_Assert: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_Many_Column_Assert, errorMsg: option.errorMsg, sql, params });
3299
- case SelectResult.One_Row_One_Column_Assert: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_One_Column_Assert, errorMsg: option.errorMsg, sql, params });
3300
- case SelectResult.One_Row_Many_Column_NotSure: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_Many_Column_NotSure, errorMsg: option.errorMsg, sql, params });
3301
- case SelectResult.One_Row_One_Column_NotSure: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_One_Column_NotSure, errorMsg: option.errorMsg, sql, params });
3449
+ case SelectResult.RS_CS: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_CS, sql, params });
3450
+ case SelectResult.RS_C: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_C, sql, params });
3451
+ case SelectResult.RS_CS_List: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_CS_List, sql, params });
3452
+ case SelectResult.RS_C_List: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_C_List, sql, params });
3453
+ case SelectResult.R_CS_Assert: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_CS_Assert, sql, params });
3454
+ case SelectResult.R_C_Assert: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_C_Assert, sql, params });
3455
+ case SelectResult.R_CS_NotSure: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_CS_NotSure, sql, params });
3456
+ case SelectResult.R_C_NotSure: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_C_NotSure, sql, params });
3302
3457
  }
3303
3458
  }
3304
3459
  }
3460
+ excutePage(option) {
3461
+ option ?? (option = {});
3462
+ option.sync ?? (option.sync = SyncMode.Async);
3463
+ const { where, params } = this._where();
3464
+ const result = {
3465
+ records: [],
3466
+ size: 0,
3467
+ total: 0
3468
+ };
3469
+ let sql = `
3470
+ SELECT
3471
+ ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3472
+ FROM ${this._table}
3473
+ ${where ? ' WHERE ' : ''}
3474
+ ${where}
3475
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3476
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3477
+ `;
3478
+ if (this._startRow && this._pageSize) {
3479
+ sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
3480
+ }
3481
+ else if (this._startRow) {
3482
+ sql += `LIMIT ${this._startRow}`;
3483
+ }
3484
+ const sqlCount = `
3485
+ SELECT COUNT(1)
3486
+ FROM ${this._table}
3487
+ ${where ? ' WHERE ' : ''}
3488
+ ${where}
3489
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3490
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3491
+ `;
3492
+ if (option.sync === SyncMode.Sync) {
3493
+ result.total = this._service.select({
3494
+ ...option,
3495
+ params,
3496
+ sql: sqlCount,
3497
+ sync: SyncMode.Sync,
3498
+ selectResult: SelectResult.R_C_Assert
3499
+ });
3500
+ result.size = (0, math_1.calc)(result.total)
3501
+ .add(this._pageSize - 1)
3502
+ .div(this._pageSize)
3503
+ .round(0, 2)
3504
+ .over();
3505
+ result.records = this._service.select({
3506
+ ...option,
3507
+ params,
3508
+ sql,
3509
+ sync: SyncMode.Sync,
3510
+ selectResult: SelectResult.RS_CS
3511
+ });
3512
+ return result;
3513
+ }
3514
+ else {
3515
+ return new Promise(async (resolve, reject) => {
3516
+ try {
3517
+ result.total = await this._service.select({
3518
+ ...option,
3519
+ params,
3520
+ sql: sqlCount,
3521
+ sync: SyncMode.Async,
3522
+ selectResult: SelectResult.R_C_Assert
3523
+ });
3524
+ result.size = (0, math_1.calc)(result.total)
3525
+ .add(this._pageSize - 1)
3526
+ .div(this._pageSize)
3527
+ .round(0, 2)
3528
+ .over();
3529
+ result.records = await this._service.select({
3530
+ ...option,
3531
+ params,
3532
+ sql,
3533
+ sync: SyncMode.Async,
3534
+ selectResult: SelectResult.RS_CS
3535
+ });
3536
+ resolve(result);
3537
+ }
3538
+ catch (error) {
3539
+ reject(error);
3540
+ }
3541
+ });
3542
+ }
3543
+ }
3305
3544
  excuteUpdate(option) {
3306
3545
  option ?? (option = {});
3307
3546
  option.sync ?? (option.sync = SyncMode.Async);
@@ -3365,16 +3604,25 @@ class StreamQuery {
3365
3604
  }
3366
3605
  return { where: wheres.join(' '), params: this._param };
3367
3606
  }
3368
- _(key, value, op, { not = '', name = '' } = {}) {
3369
- if (name !== undefined && this._paramKeys.hasOwnProperty(name)) {
3370
- this._param[this._paramKeys[name]] = value;
3607
+ _(key, value, op, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3608
+ if (value === null
3609
+ || value === undefined
3610
+ || ((0, string_1.emptyString)(`${value ?? ''}`) && skipEmptyString === true)) {
3611
+ if (breakExcuteIfSkip === true) {
3612
+ this.if_exec = false;
3613
+ }
3614
+ return this;
3615
+ }
3616
+ if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3617
+ this._param[this._paramKeys[paramName]] = value;
3371
3618
  }
3372
3619
  else {
3620
+ paramName;
3373
3621
  const pkey = `p${this._prefix}${this._index++}`;
3374
3622
  this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} ${op} :${pkey} `);
3375
3623
  this._param[pkey] = value;
3376
- if (name) {
3377
- this._paramKeys[name] = pkey;
3624
+ if (paramName) {
3625
+ this._paramKeys[paramName] = pkey;
3378
3626
  }
3379
3627
  }
3380
3628
  return this;
@@ -3387,112 +3635,158 @@ class StreamQuery {
3387
3635
  this._wheres.push(`AND ${this[_fields][String(key1)]?.C2()} ${not} ${op} ${this[_fields][String(key2)]?.C2()} `);
3388
3636
  return this;
3389
3637
  }
3390
- _between(key, value1, value2, { not = '', name = '' } = {}) {
3391
- if (name && this._paramKeys[name]) {
3392
- this._param[this._paramKeys[name][0]] = value1;
3393
- this._param[this._paramKeys[name][1]] = value2;
3638
+ _between(key, value1, value2, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3639
+ if (value1 === null
3640
+ || value1 === undefined
3641
+ || ((0, string_1.emptyString)(`${value1 ?? ''}`) && skipEmptyString === true)
3642
+ || value2 === null
3643
+ || value2 === undefined
3644
+ || ((0, string_1.emptyString)(`${value2 ?? ''}`) && skipEmptyString === true)) {
3645
+ if (breakExcuteIfSkip === true) {
3646
+ this.if_exec = false;
3647
+ }
3648
+ return this;
3649
+ }
3650
+ if (paramName && this._paramKeys[paramName]) {
3651
+ this._param[this._paramKeys[paramName][0]] = value1;
3652
+ this._param[this._paramKeys[paramName][1]] = value2;
3394
3653
  }
3395
3654
  else {
3396
3655
  const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
3397
3656
  this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} BETWEEN :${pkey1} AND :${pkey2}`);
3398
3657
  this._param[pkey1] = value1;
3399
3658
  this._param[pkey2] = value2;
3400
- if (name) {
3401
- this._paramKeys[name] = [pkey1, pkey2];
3659
+ if (paramName) {
3660
+ this._paramKeys[paramName] = [pkey1, pkey2];
3402
3661
  }
3403
3662
  }
3404
3663
  return this;
3405
3664
  }
3406
- _in(key, value, { not = '', name = '', force = false } = {}) {
3665
+ _in(key, value, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3407
3666
  if (value && value.length > 0) {
3408
- if (name !== undefined && this._paramKeys.hasOwnProperty(name)) {
3409
- this._param[this._paramKeys[name]] = value;
3667
+ if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3668
+ this._param[this._paramKeys[paramName]] = value;
3410
3669
  }
3411
3670
  else {
3412
3671
  const pkey = `p${this._prefix}${this._index++}`;
3413
3672
  this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} IN (:${pkey}) `);
3414
3673
  this._param[pkey] = value;
3415
- if (name) {
3416
- this._paramKeys[name] = pkey;
3674
+ if (paramName) {
3675
+ this._paramKeys[paramName] = pkey;
3417
3676
  }
3418
3677
  }
3419
3678
  }
3420
- else if (force !== true) {
3679
+ else if (breakExcuteIfSkip !== true) {
3421
3680
  this.if_exec = false;
3422
3681
  }
3423
3682
  return this;
3424
3683
  }
3425
- _shift(key1, key2, value, op, { not = '', name = '' } = {}) {
3426
- if (name !== undefined && this._paramKeys.hasOwnProperty(name)) {
3427
- this._param[this._paramKeys[name]] = value;
3684
+ _shift(key1, key2, value, op, { not = '', paramName = '', breakExcuteIfSkip = false } = {}) {
3685
+ if (value === null
3686
+ || value === undefined
3687
+ || (0, string_1.emptyString)(`${value ?? ''}`)) {
3688
+ if (breakExcuteIfSkip === true) {
3689
+ this.if_exec = false;
3690
+ }
3691
+ return this;
3692
+ }
3693
+ if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3694
+ this._param[this._paramKeys[paramName]] = value;
3428
3695
  }
3429
3696
  else {
3430
3697
  const pkey = `p${this._prefix}${this._index++}`;
3431
3698
  this._wheres.push(`AND (${this[_fields][String(key1)]?.C2()} << 8) + ${this[_fields][String(key2)]?.C2()} ${not} ${op} :${pkey} `);
3432
3699
  this._param[pkey] = value;
3433
- if (name) {
3434
- this._paramKeys[name] = pkey;
3700
+ if (paramName) {
3701
+ this._paramKeys[paramName] = pkey;
3435
3702
  }
3436
3703
  }
3437
3704
  return this;
3438
3705
  }
3439
- _match(value, keys, { name, not, append } = {}) {
3440
- if (name !== undefined && this._paramKeys.hasOwnProperty(name)) {
3441
- this._param[this._paramKeys[name]] = value;
3706
+ _match(value, keys, { paramName = '', not = '', append = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3707
+ if (value === null
3708
+ || value === undefined
3709
+ || (0, string_1.emptyString)(`${value ?? ''}`)) {
3710
+ if (breakExcuteIfSkip === true) {
3711
+ this.if_exec = false;
3712
+ }
3713
+ return this;
3714
+ }
3715
+ if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3716
+ this._param[this._paramKeys[paramName]] = value;
3442
3717
  }
3443
3718
  else {
3444
3719
  const pkey = `p${this._prefix}${this._index++}`;
3445
- this._wheres.push(`AND MATCH(${keys.map(key => this[_fields][String(key)]?.C2()).join(',')}) AGAINST (:${pkey} ${append ?? ''})`);
3720
+ this._wheres.push(`AND ${not} MATCH(${keys.map(key => this[_fields][String(key)]?.C2()).join(',')}) AGAINST (:${pkey} ${append ?? ''})`);
3446
3721
  this._param[pkey] = value;
3447
- if (name) {
3448
- this._paramKeys[name] = pkey;
3722
+ if (paramName) {
3723
+ this._paramKeys[paramName] = pkey;
3449
3724
  }
3450
3725
  }
3451
3726
  return this;
3452
3727
  }
3453
- _pow(key, value, { name } = {}) {
3454
- if (name !== undefined && this._paramKeys.hasOwnProperty(name)) {
3455
- this._param[this._paramKeys[name]] = value;
3728
+ _pow(key, value, { not = '', paramName = '', breakExcuteIfSkip = false } = {}) {
3729
+ if (value === null
3730
+ || value === undefined
3731
+ || (0, string_1.emptyString)(`${value ?? ''}`)) {
3732
+ if (breakExcuteIfSkip === true) {
3733
+ this.if_exec = false;
3734
+ }
3735
+ return this;
3736
+ }
3737
+ if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3738
+ this._param[this._paramKeys[paramName]] = value;
3456
3739
  }
3457
3740
  else {
3458
3741
  const pkey = `p${this._prefix}${this._index++}`;
3459
- this._wheres.push(`AND NOT POW(2, ${this[_fields][String(key)]?.C2()}) & :${pkey}`);
3742
+ this._wheres.push(`AND ${not} POW(2, ${this[_fields][String(key)]?.C2()}) & :${pkey}`);
3460
3743
  this._param[pkey] = value;
3461
- if (name) {
3462
- this._paramKeys[name] = pkey;
3744
+ if (paramName) {
3745
+ this._paramKeys[paramName] = pkey;
3463
3746
  }
3464
3747
  }
3465
3748
  return this;
3466
3749
  }
3467
- _like(key, value, { not = '', left = '', right = '', name = '', op = 'LIKE', force = false } = {}) {
3468
- if (value !== null && value !== undefined && value !== '') {
3469
- if (name !== undefined && this._paramKeys.hasOwnProperty(name)) {
3470
- this._param[this._paramKeys[name]] = value;
3471
- }
3472
- else {
3473
- const pkey = `p${this._prefix}${this._index++}`;
3474
- this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} ${op} CONCAT('${left}', :${pkey}, '${right}') `);
3475
- this._param[pkey] = value;
3476
- if (name) {
3477
- this._paramKeys[name] = pkey;
3478
- }
3750
+ _like(key, value, { not = '', left = '', right = '', paramName = '', op = 'LIKE', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3751
+ if (value === null
3752
+ || value === undefined
3753
+ || ((0, string_1.emptyString)(`${value ?? ''}`) && skipEmptyString === true)) {
3754
+ if (breakExcuteIfSkip === true) {
3755
+ this.if_exec = false;
3479
3756
  }
3757
+ return this;
3480
3758
  }
3481
- else if (force !== true) {
3482
- this.if_exec = false;
3759
+ if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3760
+ this._param[this._paramKeys[paramName]] = value;
3761
+ }
3762
+ else {
3763
+ const pkey = `p${this._prefix}${this._index++}`;
3764
+ this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} ${op} CONCAT('${left}', :${pkey}, '${right}') `);
3765
+ this._param[pkey] = value;
3766
+ if (paramName) {
3767
+ this._paramKeys[paramName] = pkey;
3768
+ }
3483
3769
  }
3484
3770
  return this;
3485
3771
  }
3486
- _includes(key, value, { not = '', name = '' } = {}) {
3487
- if (name !== undefined && this._paramKeys.hasOwnProperty(name)) {
3488
- this._param[this._paramKeys[name]] = value;
3772
+ _includes(key, value, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = true } = {}) {
3773
+ if (value === null
3774
+ || value === undefined
3775
+ || ((0, string_1.emptyString)(`${value ?? ''}`) && skipEmptyString === true)) {
3776
+ if (breakExcuteIfSkip === true) {
3777
+ this.if_exec = false;
3778
+ }
3779
+ return this;
3780
+ }
3781
+ if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3782
+ this._param[this._paramKeys[paramName]] = value;
3489
3783
  }
3490
3784
  else {
3491
3785
  const pkey = `p${this._prefix}${this._index++}`;
3492
- this._wheres.push(`AND LOCATE(${this[_fields][String(key)]?.C2()}, :${pkey}) ${not ? '=' : ''} 0`);
3786
+ this._wheres.push(`AND LOCATE(${this[_fields][String(key)]?.C2()}, :${pkey}) ${not ? '=' : '>'} 0`);
3493
3787
  this._param[pkey] = value;
3494
- if (name) {
3495
- this._paramKeys[name] = pkey;
3788
+ if (paramName) {
3789
+ this._paramKeys[paramName] = pkey;
3496
3790
  }
3497
3791
  }
3498
3792
  return this;
@@ -3966,6 +4260,12 @@ __decorate([
3966
4260
  __metadata("design:paramtypes", [Object]),
3967
4261
  __metadata("design:returntype", Object)
3968
4262
  ], StreamQuery.prototype, "excuteSelect", null);
4263
+ __decorate([
4264
+ IF_EXEC(null),
4265
+ __metadata("design:type", Function),
4266
+ __metadata("design:paramtypes", [Object]),
4267
+ __metadata("design:returntype", Object)
4268
+ ], StreamQuery.prototype, "excutePage", null);
3969
4269
  __decorate([
3970
4270
  IF_EXEC(0),
3971
4271
  __metadata("design:type", Function),
@@ -3993,7 +4293,6 @@ function getRedisDB(db) {
3993
4293
  error_1.Throw.if(!rd, 'not found redis!');
3994
4294
  return rd;
3995
4295
  }
3996
- exports.getRedisDB = getRedisDB;
3997
4296
  /**
3998
4297
  redlock
3999
4298
  */
@@ -4027,7 +4326,6 @@ async function GetRedisLock(key, lockMaxActive) {
4027
4326
  }
4028
4327
  }
4029
4328
  }
4030
- exports.GetRedisLock = GetRedisLock;
4031
4329
  ;
4032
4330
  async function excuteWithLock(config, fn__) {
4033
4331
  const key = `[lock]${typeof config.key === 'function' ? config.key() : config.key}`;
@@ -4061,7 +4359,6 @@ async function excuteWithLock(config, fn__) {
4061
4359
  };
4062
4360
  return await fn();
4063
4361
  }
4064
- exports.excuteWithLock = excuteWithLock;
4065
4362
  /** 与缓存共用时,需要在缓存之前:有缓存则返回缓存,否则加锁执行并缓存,后续队列全部返回缓存,跳过执行 */
4066
4363
  function MethodLock(config) {
4067
4364
  return function (target, _propertyKey, descriptor) {
@@ -4072,7 +4369,6 @@ function MethodLock(config) {
4072
4369
  };
4073
4370
  };
4074
4371
  }
4075
- exports.MethodLock = MethodLock;
4076
4372
  async function setMethodCache(config, devid) {
4077
4373
  const db = getRedisDB();
4078
4374
  if (config.result !== null && config.result !== undefined) {
@@ -4114,7 +4410,6 @@ async function clearMethodCache(key) {
4114
4410
  await clearChild(key);
4115
4411
  }
4116
4412
  }
4117
- exports.clearMethodCache = clearMethodCache;
4118
4413
  async function clearChild(key, skipDel = false) {
4119
4414
  const db = getRedisDB();
4120
4415
  if (skipDel === false) {
@@ -4161,7 +4456,6 @@ async function excuteWithCache(config, fn) {
4161
4456
  return result;
4162
4457
  }
4163
4458
  }
4164
- exports.excuteWithCache = excuteWithCache;
4165
4459
  function MethodCache(config) {
4166
4460
  return function (target, _propertyKey, descriptor) {
4167
4461
  const fn = descriptor.value;
@@ -4188,7 +4482,6 @@ function MethodCache(config) {
4188
4482
  };
4189
4483
  };
4190
4484
  }
4191
- exports.MethodCache = MethodCache;
4192
4485
  class MUParser {
4193
4486
  constructor(modelName, file) {
4194
4487
  this.linNumber = 0;