tspace-mysql 1.0.0 → 1.0.3

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 (42) hide show
  1. package/README.md +14 -15
  2. package/dist/cli/index.d.ts +2 -0
  3. package/dist/cli/index.js +10 -6
  4. package/dist/cli/migrate/make.d.ts +4 -0
  5. package/dist/cli/migrate/make.js +9 -9
  6. package/dist/cli/models/make.d.ts +4 -0
  7. package/dist/cli/models/make.js +14 -17
  8. package/dist/cli/models/model.d.ts +2 -0
  9. package/dist/cli/models/model.js +1 -1
  10. package/dist/cli/tables/make.d.ts +4 -0
  11. package/dist/cli/tables/make.js +21 -22
  12. package/dist/cli/tables/table.d.ts +2 -0
  13. package/dist/cli/tables/table.js +1 -1
  14. package/dist/lib/config/env.d.ts +8 -0
  15. package/dist/lib/config/env.js +1 -1
  16. package/dist/lib/connections/index.d.ts +2 -0
  17. package/dist/lib/connections/index.js +1 -1
  18. package/dist/lib/connections/options.d.ts +4 -0
  19. package/dist/lib/constants/index.d.ts +4 -0
  20. package/dist/lib/{utils/constant.js → constants/index.js} +0 -2
  21. package/dist/lib/index.d.ts +8 -0
  22. package/dist/lib/index.js +6 -2
  23. package/dist/lib/tspace/AbstractDB.d.ts +7 -0
  24. package/dist/lib/tspace/AbstractDatabase.d.ts +102 -0
  25. package/dist/lib/tspace/AbstractModel.d.ts +20 -0
  26. package/dist/lib/tspace/DB.d.ts +15 -0
  27. package/dist/lib/tspace/DB.js +10 -7
  28. package/dist/lib/tspace/Database.d.ts +155 -0
  29. package/dist/lib/tspace/Database.js +232 -168
  30. package/dist/lib/tspace/Interface.d.ts +25 -0
  31. package/dist/lib/tspace/Logger.d.ts +1 -0
  32. package/dist/lib/tspace/Logger.js +4 -3
  33. package/dist/lib/tspace/Model.d.ts +233 -0
  34. package/dist/lib/tspace/Model.js +247 -236
  35. package/dist/lib/tspace/ProxyHandler.d.ts +5 -0
  36. package/dist/lib/tspace/ProxyHandler.js +2 -2
  37. package/dist/lib/tspace/Schema.d.ts +45 -0
  38. package/dist/lib/tspace/Schema.js +9 -11
  39. package/dist/lib/tspace/index.d.ts +14 -0
  40. package/dist/lib/utils/index.d.ts +17 -0
  41. package/dist/lib/utils/index.js +8 -8
  42. package/package.json +3 -6
@@ -127,9 +127,12 @@ var Model = /** @class */ (function (_super) {
127
127
  return this;
128
128
  };
129
129
  Model.prototype.usePattern = function (pattern) {
130
- var allowPattern = [this.$utils().constants('PATTERN').snake_case, this.$utils().constants('PATTERN').camelCase];
130
+ var allowPattern = [
131
+ this.$utils().constants('PATTERN').snake_case,
132
+ this.$utils().constants('PATTERN').camelCase
133
+ ];
131
134
  if (!allowPattern.includes(pattern))
132
- throw new Error("allow pattern " + allowPattern + " only");
135
+ throw new Error("allow pattern ".concat(allowPattern, " only"));
133
136
  this.$db.set('PATTERN', pattern);
134
137
  return this;
135
138
  };
@@ -142,9 +145,9 @@ var Model = /** @class */ (function (_super) {
142
145
  return this;
143
146
  };
144
147
  Model.prototype.useTable = function (table) {
145
- this.$db.set('TABLE_NAME', "`" + table + "`");
146
- this.$db.get('SELECT', this.$utils().constants('SELECT') + " *");
147
- this.$db.get('FROM', this.$utils().constants('FROM') + "'");
148
+ this.$db.set('TABLE_NAME', "`".concat(table, "`"));
149
+ this.$db.get('SELECT', "".concat(this.$utils().constants('SELECT'), " *"));
150
+ this.$db.get('FROM', "".concat(this.$utils().constants('FROM'), "'"));
148
151
  return this;
149
152
  };
150
153
  Model.prototype.disabledSoftDelete = function () {
@@ -155,13 +158,13 @@ var Model = /** @class */ (function (_super) {
155
158
  this.$db.set('REGISTRY', __assign(__assign({}, func), { attach: this._attach, detach: this._detach }));
156
159
  return this;
157
160
  };
158
- Model.prototype.withQuery = function (name, callback) {
161
+ Model.prototype.withQuery = function (name, cb) {
159
162
  var relation = this.$db.get('WITH').find(function (data) { return data.name === name; });
160
163
  if (relation == null)
161
- throw new Error("relation " + name + " not be register !");
164
+ throw new Error("relation ".concat(name, " not be register !"));
162
165
  if (!Object.values(this.$utils().constants('RELATIONSHIP')).includes(relation.relation))
163
- throw new Error("unknow relationship in [" + this.$utils().constants('RELATIONSHIP') + "] !");
164
- relation.query = callback(new relation.model());
166
+ throw new Error("unknow relationship in [".concat(this.$utils().constants('RELATIONSHIP'), "] !"));
167
+ relation.query = cb(new relation.model());
165
168
  return this;
166
169
  };
167
170
  Model.prototype.with = function () {
@@ -174,9 +177,10 @@ var Model = /** @class */ (function (_super) {
174
177
  var _a;
175
178
  var relation = (_a = _this.$db.get('RELATION')) === null || _a === void 0 ? void 0 : _a.find(function (data) { return data.name === name; });
176
179
  if (relation == null)
177
- throw new Error("relation " + name + " not be register !");
178
- if (!Object.values(_this.$utils().constants('RELATIONSHIP')).includes(relation.relation))
179
- throw new Error("unknow relationship in [" + _this.$utils().constants('RELATIONSHIP') + "] !");
180
+ throw new Error("relation ".concat(name, " not be register !"));
181
+ if (!Object.values(_this.$utils().constants('RELATIONSHIP')).includes(relation.relation)) {
182
+ throw new Error("unknow relationship in [".concat(_this.$utils().constants('RELATIONSHIP'), "] !"));
183
+ }
180
184
  relation.query = new relation.model();
181
185
  return relation;
182
186
  });
@@ -198,10 +202,10 @@ var Model = /** @class */ (function (_super) {
198
202
  var operator = '=';
199
203
  id = this.$utils().escape(id);
200
204
  if (!this.$db.get('WHERE').includes(this.$utils().constants('WHERE'))) {
201
- this.$db.set('WHERE', this.$utils().constants('WHERE') + " " + column + " " + operator + " '" + id + "'");
205
+ this.$db.set('WHERE', "".concat(this.$utils().constants('WHERE'), " ").concat(column, " ").concat(operator, " '").concat(id, "'"));
202
206
  return this;
203
207
  }
204
- this.$db.set('WHERE', this.$db.get('WHERE') + " " + this.$utils().constants('AND') + " " + column + " " + operator + " '" + id + "'");
208
+ this.$db.set('WHERE', "".concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('AND'), " ").concat(column, " ").concat(operator, " '").concat(id, "'"));
205
209
  return this;
206
210
  };
207
211
  Model.prototype.hasOne = function (_a) {
@@ -284,6 +288,7 @@ var Model = /** @class */ (function (_super) {
284
288
  return __generator(this, function (_a) {
285
289
  switch (_a.label) {
286
290
  case 0:
291
+ this.$db.set('SOFT_DELETE', false);
287
292
  this.whereNotNull(this._isPatternSnakeCase() ? 'deleted_at' : 'deletedAt');
288
293
  sql = this._getSQLModel();
289
294
  return [4 /*yield*/, this._exec(sql, 'GET')];
@@ -296,12 +301,16 @@ var Model = /** @class */ (function (_super) {
296
301
  return __awaiter(this, void 0, void 0, function () {
297
302
  var updatedAt, deletedAt, query;
298
303
  return __generator(this, function (_a) {
299
- updatedAt = this._isPatternSnakeCase() ? 'updated_at' : 'updatedAt';
300
- deletedAt = this._isPatternSnakeCase() ? 'deleted_at' : 'deletedAt';
301
- query = this.$db.get('TIMESTAMP') ? deletedAt + " = NULL , " + updatedAt + " = '" + this.$utils().timestamp() + "'" : deletedAt + " = NULL";
302
- this.$db.set('UPDATE', this.$utils().constants('UPDATE') + " " + this.$db.get('TABLE_NAME') + " SET " + query);
303
- this.$db.set('SAVE', 'UPDATE');
304
- return [2 /*return*/, this.save()];
304
+ switch (_a.label) {
305
+ case 0:
306
+ updatedAt = this._isPatternSnakeCase() ? 'updated_at' : 'updatedAt';
307
+ deletedAt = this._isPatternSnakeCase() ? 'deleted_at' : 'deletedAt';
308
+ query = this.$db.get('TIMESTAMP') ? "".concat(deletedAt, " = NULL , ").concat(updatedAt, " = '").concat(this.$utils().timestamp(), "'") : "".concat(deletedAt, " = NULL");
309
+ this.$db.set('UPDATE', "".concat(this.$utils().constants('UPDATE'), " ").concat(this.$db.get('TABLE_NAME'), " SET ").concat(query));
310
+ this.$db.set('SAVE', 'UPDATE');
311
+ return [4 /*yield*/, this.save()];
312
+ case 1: return [2 /*return*/, _a.sent()];
313
+ }
305
314
  });
306
315
  });
307
316
  };
@@ -355,7 +364,7 @@ var Model = /** @class */ (function (_super) {
355
364
  return __generator(this, function (_a) {
356
365
  switch (_a.label) {
357
366
  case 0:
358
- this.$db.set('SELECT', this.$utils().constants('SELECT') + " " + column);
367
+ this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " ").concat(column));
359
368
  sql = this._getSQLModel();
360
369
  return [4 /*yield*/, this._queryStatementModel(sql)];
361
370
  case 1:
@@ -379,7 +388,7 @@ var Model = /** @class */ (function (_super) {
379
388
  return __generator(this, function (_b) {
380
389
  switch (_b.label) {
381
390
  case 0:
382
- this.$db.set('SELECT', this.$utils().constants('SELECT') + " " + this.$utils().constants('AVG') + "(" + column + ") " + this.$utils().constants('AS') + " avg");
391
+ this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('AVG'), "(").concat(column, ") ").concat(this.$utils().constants('AS'), " avg"));
383
392
  sql = this._getSQLModel();
384
393
  return [4 /*yield*/, this._queryStatementModel(sql)];
385
394
  case 1:
@@ -402,7 +411,7 @@ var Model = /** @class */ (function (_super) {
402
411
  return __generator(this, function (_b) {
403
412
  switch (_b.label) {
404
413
  case 0:
405
- this.$db.set('SELECT', this.$utils().constants('SELECT') + " " + this.$utils().constants('SUM') + "(" + column + ") " + this.$utils().constants('AS') + " sum");
414
+ this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('SUM'), "(").concat(column, ") ").concat(this.$utils().constants('AS'), " sum"));
406
415
  sql = this._getSQLModel();
407
416
  return [4 /*yield*/, this._queryStatementModel(sql)];
408
417
  case 1:
@@ -425,7 +434,7 @@ var Model = /** @class */ (function (_super) {
425
434
  return __generator(this, function (_b) {
426
435
  switch (_b.label) {
427
436
  case 0:
428
- this.$db.set('SELECT', this.$utils().constants('SELECT') + " " + this.$utils().constants('MAX') + "(" + column + ") " + this.$utils().constants('AS') + " max");
437
+ this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('MAX'), "(").concat(column, ") ").concat(this.$utils().constants('AS'), " max"));
429
438
  sql = this._getSQLModel();
430
439
  return [4 /*yield*/, this._queryStatementModel(sql)];
431
440
  case 1:
@@ -448,7 +457,7 @@ var Model = /** @class */ (function (_super) {
448
457
  return __generator(this, function (_b) {
449
458
  switch (_b.label) {
450
459
  case 0:
451
- this.$db.set('SELECT', this.$utils().constants('SELECT') + " " + this.$utils().constants('MIN') + "(" + column + ") " + this.$utils().constants('AS') + " min");
460
+ this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('MIN'), "(").concat(column, ") ").concat(this.$utils().constants('AS'), " min"));
452
461
  sql = this._getSQLModel();
453
462
  return [4 /*yield*/, this._queryStatementModel(sql)];
454
463
  case 1:
@@ -471,7 +480,7 @@ var Model = /** @class */ (function (_super) {
471
480
  return __generator(this, function (_b) {
472
481
  switch (_b.label) {
473
482
  case 0:
474
- this.$db.set('SELECT', this.$utils().constants('SELECT') + " " + this.$utils().constants('COUNT') + "(" + column + ") " + this.$utils().constants('AS') + " total");
483
+ this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('COUNT'), "(").concat(column, ") ").concat(this.$utils().constants('AS'), " total"));
475
484
  sql = this._getSQLModel();
476
485
  return [4 /*yield*/, this._queryStatementModel(sql)];
477
486
  case 1:
@@ -497,19 +506,19 @@ var Model = /** @class */ (function (_super) {
497
506
  throw new Error("Can't delete without where condition");
498
507
  if (!this.$db.get('SOFT_DELETE')) return [3 /*break*/, 2];
499
508
  deletedAt = this._isPatternSnakeCase() ? 'deleted_at' : 'deletedAt';
500
- query = deletedAt + " = '" + this.$utils().timestamp() + "'";
501
- sql = this.$utils().constants('UPDATE') + " " + this.$db.get('TABLE_NAME') + " " + this.$utils().constants('SET') + " " + query;
509
+ query = "".concat(deletedAt, " = '").concat(this.$utils().timestamp(), "'");
510
+ sql = "".concat(this.$utils().constants('UPDATE'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$utils().constants('SET'), " ").concat(query);
502
511
  if (this.$db.get('TIMESTAMP')) {
503
512
  updatedAt = this._isPatternSnakeCase() ? 'updated_at' : 'updatedAt';
504
- sql = sql + " , " + updatedAt + " = '" + this.$utils().timestamp() + "'";
513
+ sql = "".concat(sql, " , ").concat(updatedAt, " = '").concat(this.$utils().timestamp(), "'");
505
514
  }
506
- this.$db.set('UPDATE', sql + " " + this.$db.get('WHERE'));
515
+ this.$db.set('UPDATE', "".concat(sql, " ").concat(this.$db.get('WHERE')));
507
516
  return [4 /*yield*/, this._actionStatementModel({ sql: this.$db.get('UPDATE') })];
508
517
  case 1:
509
518
  result_1 = _c.sent();
510
519
  return [2 /*return*/, (_a = !!result_1) !== null && _a !== void 0 ? _a : false];
511
520
  case 2:
512
- this.$db.set('DELETE', this.$utils().constants('DELETE') + " " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$db.get('WHERE'));
521
+ this.$db.set('DELETE', "".concat(this.$utils().constants('DELETE'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$db.get('WHERE')));
513
522
  return [4 /*yield*/, this._actionStatementModel({ sql: this.$db.get('DELETE') })];
514
523
  case 3:
515
524
  result = _c.sent();
@@ -538,9 +547,9 @@ var Model = /** @class */ (function (_super) {
538
547
  case 2:
539
548
  sql = this._getSQLModel();
540
549
  if (!sql.includes(this.$utils().constants('LIMIT')))
541
- sql = sql + " " + this.$utils().constants('LIMIT') + " 1";
550
+ sql = "".concat(sql, " ").concat(this.$utils().constants('LIMIT'), " 1");
542
551
  else
543
- sql = sql.replace(this.$db.get('LIMIT'), this.$utils().constants('LIMIT') + " 1");
552
+ sql = sql.replace(this.$db.get('LIMIT'), "".concat(this.$utils().constants('LIMIT'), " 1"));
544
553
  return [4 /*yield*/, this._exec(sql, 'FIRST')];
545
554
  case 3: return [2 /*return*/, _b.sent()];
546
555
  }
@@ -558,7 +567,7 @@ var Model = /** @class */ (function (_super) {
558
567
  return __generator(this, function (_a) {
559
568
  switch (_a.label) {
560
569
  case 0:
561
- sql = this.$utils().constants('SELECT') + " * " + this.$utils().constants('FROM') + " " + this.$db.get('TABLE_NAME');
570
+ sql = "".concat(this.$utils().constants('SELECT'), " * ").concat(this.$utils().constants('FROM'), " ").concat(this.$db.get('TABLE_NAME'));
562
571
  return [4 /*yield*/, this._queryStatementModel(sql)];
563
572
  case 1:
564
573
  result = _a.sent();
@@ -578,7 +587,7 @@ var Model = /** @class */ (function (_super) {
578
587
  return __generator(this, function (_a) {
579
588
  switch (_a.label) {
580
589
  case 0:
581
- sql = this.$utils().constants('SELECT') + " * " + this.$utils().constants('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$utils().constants('WHERE') + " id = " + id;
590
+ sql = "".concat(this.$utils().constants('SELECT'), " * ").concat(this.$utils().constants('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$utils().constants('WHERE'), " id = ").concat(id);
582
591
  return [4 /*yield*/, this._queryStatementModel(sql)];
583
592
  case 1:
584
593
  result = _a.sent();
@@ -607,9 +616,9 @@ var Model = /** @class */ (function (_super) {
607
616
  case 2:
608
617
  sql = this._getSQLModel();
609
618
  if (!sql.includes(this.$utils().constants('LIMIT')))
610
- sql = sql + " " + this.$utils().constants('LIMIT') + " 1";
619
+ sql = "".concat(sql, " ").concat(this.$utils().constants('LIMIT'), " 1");
611
620
  else
612
- sql = sql.replace(this.$db.get('LIMIT'), this.$utils().constants('LIMIT') + " 1");
621
+ sql = sql.replace(this.$db.get('LIMIT'), "".concat(this.$utils().constants('LIMIT'), " 1"));
613
622
  return [4 /*yield*/, this._exec(sql, 'FIRST')];
614
623
  case 3: return [2 /*return*/, _b.sent()];
615
624
  }
@@ -679,6 +688,8 @@ var Model = /** @class */ (function (_super) {
679
688
  return __generator(this, function (_g) {
680
689
  switch (_g.label) {
681
690
  case 0:
691
+ limit = +limit;
692
+ page = +page;
682
693
  if ((_b = this.$logger) === null || _b === void 0 ? void 0 : _b.check('limit'))
683
694
  throw new Error("this [pagination] can't used [limit] method");
684
695
  if (!((_c = this.$db.get('EXCEPT')) === null || _c === void 0 ? void 0 : _c.length)) return [3 /*break*/, 2];
@@ -692,9 +703,9 @@ var Model = /** @class */ (function (_super) {
692
703
  this.$db.set('PAGE', page);
693
704
  sql = this._getSQLModel();
694
705
  if (!sql.includes(this.$utils().constants('LIMIT')))
695
- sql = sql + " " + this.$utils().constants('LIMIT') + " " + limit + " " + this.$utils().constants('OFFSET') + " " + offset;
706
+ sql = "".concat(sql, " ").concat(this.$utils().constants('LIMIT'), " ").concat(limit, " ").concat(this.$utils().constants('OFFSET'), " ").concat(offset);
696
707
  else
697
- sql = sql.replace(this.$db.get('LIMIT'), this.$utils().constants('LIMIT') + " " + limit + " " + this.$utils().constants('OFFSET') + " " + offset);
708
+ sql = sql.replace(this.$db.get('LIMIT'), "".concat(this.$utils().constants('LIMIT'), " ").concat(limit, " ").concat(this.$utils().constants('OFFSET'), " ").concat(offset));
698
709
  return [4 /*yield*/, this._exec(sql, 'PAGINATION')];
699
710
  case 3: return [2 /*return*/, _g.sent()];
700
711
  }
@@ -702,31 +713,12 @@ var Model = /** @class */ (function (_super) {
702
713
  });
703
714
  };
704
715
  Model.prototype.paginate = function (_a) {
705
- var _b, _c;
706
- var _d = _a === void 0 ? {} : _a, _e = _d.limit, limit = _e === void 0 ? 15 : _e, _f = _d.page, page = _f === void 0 ? 1 : _f;
716
+ var _b = _a === void 0 ? {} : _a, _c = _b.limit, limit = _c === void 0 ? 15 : _c, _d = _b.page, page = _d === void 0 ? 1 : _d;
707
717
  return __awaiter(this, void 0, void 0, function () {
708
- var offset, sql;
709
- return __generator(this, function (_g) {
710
- switch (_g.label) {
711
- case 0:
712
- if ((_b = this.$logger) === null || _b === void 0 ? void 0 : _b.check('limit'))
713
- throw new Error("this [pagination] can't used [limit] method");
714
- if (!((_c = this.$db.get('EXCEPT')) === null || _c === void 0 ? void 0 : _c.length)) return [3 /*break*/, 2];
715
- return [4 /*yield*/, this._exceptColumns()];
716
- case 1:
717
- _g.sent();
718
- _g.label = 2;
719
- case 2:
720
- offset = (page - 1) * limit;
721
- this.$db.set('PER_PAGE', limit);
722
- this.$db.set('PAGE', page);
723
- sql = this._getSQLModel();
724
- if (!sql.includes(this.$utils().constants('LIMIT')))
725
- sql = sql + " " + this.$utils().constants('LIMIT') + " " + limit + " " + this.$utils().constants('OFFSET') + " " + offset;
726
- else
727
- sql = sql.replace(this.$db.get('LIMIT'), this.$utils().constants('LIMIT') + " " + limit + " " + this.$utils().constants('OFFSET') + " " + offset);
728
- return [4 /*yield*/, this._exec(sql, 'PAGINATION')];
729
- case 3: return [2 /*return*/, _g.sent()];
718
+ return __generator(this, function (_e) {
719
+ switch (_e.label) {
720
+ case 0: return [4 /*yield*/, this.pagination({ limit: limit, page: page })];
721
+ case 1: return [2 /*return*/, _e.sent()];
730
722
  }
731
723
  });
732
724
  });
@@ -749,8 +741,8 @@ var Model = /** @class */ (function (_super) {
749
741
  _b.sent();
750
742
  _b.label = 2;
751
743
  case 2:
752
- this.$db.set('GROUP_BY', this.$utils().constants('GROUP_BY') + " " + column);
753
- this.$db.set('SELECT', this.$db.get('SELECT') + ", " + this.$utils().constants('GROUP_CONCAT') + "(id) " + this.$utils().constants('AS') + " data");
744
+ this.$db.set('GROUP_BY', "".concat(this.$utils().constants('GROUP_BY'), " ").concat(column));
745
+ this.$db.set('SELECT', "".concat(this.$db.get('SELECT'), ", ").concat(this.$utils().constants('GROUP_CONCAT'), "(id) ").concat(this.$utils().constants('AS'), " data"));
754
746
  sql = this._getSQLModel();
755
747
  return [4 /*yield*/, this._queryStatementModel(sql)];
756
748
  case 3:
@@ -761,7 +753,7 @@ var Model = /** @class */ (function (_super) {
761
753
  var splits = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.split(',')) !== null && _b !== void 0 ? _b : '0';
762
754
  splits.forEach(function (split) { return data = __spreadArray(__spreadArray([], __read(data), false), [split], false); });
763
755
  });
764
- sqlChild = this.$utils().constants('SELECT') + " * " + this.$utils().constants('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$utils().constants('WHERE') + " id " + this.$utils().constants('IN') + " (" + (data.map(function (a) { return "'" + a + "'"; }).join(',') || ['0']) + ")";
756
+ sqlChild = "".concat(this.$utils().constants('SELECT'), " * ").concat(this.$utils().constants('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$utils().constants('WHERE'), " id ").concat(this.$utils().constants('IN'), " (").concat(data.map(function (a) { return "'".concat(a, "'"); }).join(',') || ['0'], ")");
765
757
  return [4 /*yield*/, this._queryStatementModel(sqlChild)];
766
758
  case 4:
767
759
  childData = _b.sent();
@@ -789,7 +781,7 @@ var Model = /** @class */ (function (_super) {
789
781
  */
790
782
  Model.prototype.update = function (objects) {
791
783
  var query = this._queryUpdateModel(objects);
792
- this.$db.set('UPDATE', this.$utils().constants('UPDATE') + " " + this.$db.get('TABLE_NAME') + " " + query);
784
+ this.$db.set('UPDATE', "".concat(this.$utils().constants('UPDATE'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query));
793
785
  this.$db.set('SAVE', 'UPDATE');
794
786
  return this;
795
787
  };
@@ -800,7 +792,7 @@ var Model = /** @class */ (function (_super) {
800
792
  */
801
793
  Model.prototype.insert = function (objects) {
802
794
  var query = this._queryInsertModel(objects);
803
- this.$db.set('INSERT', this.$utils().constants('INSERT') + " " + this.$db.get('TABLE_NAME') + " " + query);
795
+ this.$db.set('INSERT', "".concat(this.$utils().constants('INSERT'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query));
804
796
  this.$db.set('SAVE', 'INSERT');
805
797
  return this;
806
798
  };
@@ -811,7 +803,7 @@ var Model = /** @class */ (function (_super) {
811
803
  */
812
804
  Model.prototype.create = function (objects) {
813
805
  var query = this._queryInsertModel(objects);
814
- this.$db.set('INSERT', this.$utils().constants('INSERT') + " " + this.$db.get('TABLE_NAME') + " " + query);
806
+ this.$db.set('INSERT', "".concat(this.$utils().constants('INSERT'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query));
815
807
  this.$db.set('SAVE', 'INSERT');
816
808
  return this;
817
809
  };
@@ -823,8 +815,8 @@ var Model = /** @class */ (function (_super) {
823
815
  Model.prototype.updateOrCreate = function (objects) {
824
816
  var queryUpdate = this._queryUpdateModel(objects);
825
817
  var queryInsert = this._queryInsertModel(objects);
826
- this.$db.set('INSERT', this.$utils().constants('INSERT') + " " + this.$db.get('TABLE_NAME') + " " + queryInsert);
827
- this.$db.set('UPDATE', this.$utils().constants('UPDATE') + " " + this.$db.get('TABLE_NAME') + " " + queryUpdate);
818
+ this.$db.set('INSERT', "".concat(this.$utils().constants('INSERT'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(queryInsert));
819
+ this.$db.set('UPDATE', "".concat(this.$utils().constants('UPDATE'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(queryUpdate));
828
820
  this.$db.set('SAVE', 'UPDATE_OR_INSERT');
829
821
  return this;
830
822
  };
@@ -847,7 +839,7 @@ var Model = /** @class */ (function (_super) {
847
839
  */
848
840
  Model.prototype.createMultiple = function (data) {
849
841
  var query = this._queryInsertMultipleModel(data);
850
- this.$db.set('INSERT', this.$utils().constants('INSERT') + " " + this.$db.get('TABLE_NAME') + " " + query);
842
+ this.$db.set('INSERT', "".concat(this.$utils().constants('INSERT'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query));
851
843
  this.$db.set('SAVE', 'INSERT_MULTIPLE');
852
844
  return this;
853
845
  };
@@ -858,7 +850,7 @@ var Model = /** @class */ (function (_super) {
858
850
  */
859
851
  Model.prototype.insertMultiple = function (data) {
860
852
  var query = this._queryInsertMultipleModel(data);
861
- this.$db.set('INSERT', this.$utils().constants('INSERT') + " " + this.$db.get('TABLE_NAME') + " " + query);
853
+ this.$db.set('INSERT', "".concat(this.$utils().constants('INSERT'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query));
862
854
  this.$db.set('SAVE', 'INSERT_MULTIPLE');
863
855
  return this;
864
856
  };
@@ -920,8 +912,8 @@ var Model = /** @class */ (function (_super) {
920
912
  Model.prototype._isPatternSnakeCase = function () {
921
913
  return this.$db.get('PATTERN') === this.$utils().constants('PATTERN').snake_case;
922
914
  };
923
- Model.prototype._classToTableName = function (className, belongsTo) {
924
- if (belongsTo === void 0) { belongsTo = false; }
915
+ Model.prototype._classToTableName = function (className, _a) {
916
+ var _b = _a === void 0 ? {} : _a, _c = _b.belongsTo, belongsTo = _c === void 0 ? false : _c;
925
917
  if (className == null)
926
918
  className = this.constructor.name;
927
919
  var tb = className.replace(/([A-Z])/g, function (str) { return '_' + str.toLowerCase(); }).slice(1);
@@ -931,9 +923,9 @@ var Model = /** @class */ (function (_super) {
931
923
  };
932
924
  Model.prototype._tableName = function () {
933
925
  var tb = this._classToTableName();
934
- this.$db.set('SELECT', this.$utils().constants('SELECT') + " *");
935
- this.$db.set('FROM', "" + this.$utils().constants('FROM'));
936
- this.$db.set('TABLE_NAME', "`" + tb + "`");
926
+ this.$db.set('SELECT', "".concat(this.$utils().constants('SELECT'), " *"));
927
+ this.$db.set('FROM', "".concat(this.$utils().constants('FROM')));
928
+ this.$db.set('TABLE_NAME', "`".concat(tb, "`"));
937
929
  return this;
938
930
  };
939
931
  Model.prototype._valueInRelation = function (data) {
@@ -947,15 +939,19 @@ var Model = /** @class */ (function (_super) {
947
939
  throw new Error('model missing');
948
940
  var patternId = this._isPatternSnakeCase() ? '_id' : 'Id';
949
941
  var pk = data.pk ? data.pk : 'id';
950
- var fk = data.fk ? data.fk : this._classToTableName(null, true) + patternId;
942
+ var fk = data.fk ? data.fk : this._classToTableName(null, { belongsTo: true }) + patternId;
951
943
  if (data.pk == null && data.fk == null && relation === this.$utils().constants('RELATIONSHIP').belongsTo) {
952
944
  fk = pk;
953
- pk = this._classToTableName(model, true) + patternId;
945
+ pk = this._classToTableName(model, { belongsTo: true }) + patternId;
954
946
  }
955
947
  return { name: name, as: as, relation: relation, table: table, pk: pk, fk: fk, model: model };
956
948
  };
957
949
  Model.prototype._getSQLModel = function () {
958
950
  var sql = [];
951
+ if (this.$db.get('SOFT_DELETE')) {
952
+ var deletedAt = this._isPatternSnakeCase() ? 'deleted_at' : 'deletedAt';
953
+ this.whereNull(deletedAt);
954
+ }
959
955
  if (this.$db.get('INSERT')) {
960
956
  sql = [
961
957
  this.$db.get('INSERT')
@@ -996,7 +992,7 @@ var Model = /** @class */ (function (_super) {
996
992
  return __generator(this, function (_a) {
997
993
  switch (_a.label) {
998
994
  case 0:
999
- sql = this.$utils().constants('SHOW') + " " + this.$utils().constants('COLUMNS') + " " + this.$utils().constants('FROM') + " " + this.$db.get('TABLE_NAME');
995
+ sql = "".concat(this.$utils().constants('SHOW'), " ").concat(this.$utils().constants('COLUMNS'), " ").concat(this.$utils().constants('FROM'), " ").concat(this.$db.get('TABLE_NAME'));
1000
996
  return [4 /*yield*/, this._queryStatementModel(sql)];
1001
997
  case 1:
1002
998
  rawColumns = _a.sent();
@@ -1030,7 +1026,7 @@ var Model = /** @class */ (function (_super) {
1030
1026
  };
1031
1027
  Model.prototype._exec = function (sql, type) {
1032
1028
  return __awaiter(this, void 0, void 0, function () {
1033
- var mains, emptyData, relations, relations_1, relations_1_1, relation, subs, e_1_1, resultData, err_3;
1029
+ var result, emptyData, relations, relations_1, relations_1_1, relation, dataFromChilds, e_1_1, resultData, err_3;
1034
1030
  var e_1, _a;
1035
1031
  return __generator(this, function (_b) {
1036
1032
  switch (_b.label) {
@@ -1038,9 +1034,9 @@ var Model = /** @class */ (function (_super) {
1038
1034
  _b.trys.push([0, 12, , 13]);
1039
1035
  return [4 /*yield*/, this._queryStatementModel(sql)];
1040
1036
  case 1:
1041
- mains = _b.sent();
1042
- emptyData = this._returnEmpty(type, mains);
1043
- if (!mains.length)
1037
+ result = _b.sent();
1038
+ emptyData = this._returnEmpty(type, result);
1039
+ if (!result.length)
1044
1040
  return [2 /*return*/, emptyData];
1045
1041
  relations = this.$db.get('WITH');
1046
1042
  if (!relations.length) return [3 /*break*/, 11];
@@ -1053,14 +1049,14 @@ var Model = /** @class */ (function (_super) {
1053
1049
  if (!!relations_1_1.done) return [3 /*break*/, 8];
1054
1050
  relation = relations_1_1.value;
1055
1051
  if (!(relation.relation === this.$utils().constants('RELATIONSHIP').belongsToMany)) return [3 /*break*/, 5];
1056
- return [4 /*yield*/, this._belongsToMany(type, mains, relation)];
1052
+ return [4 /*yield*/, this._belongsToMany(type, result, relation)];
1057
1053
  case 4:
1058
- mains = _b.sent();
1054
+ result = _b.sent();
1059
1055
  return [3 /*break*/, 7];
1060
- case 5: return [4 /*yield*/, this._relation(mains, relation)];
1056
+ case 5: return [4 /*yield*/, this._relation(result, relation)];
1061
1057
  case 6:
1062
- subs = _b.sent();
1063
- mains = this._relationFilter(mains, subs, relation);
1058
+ dataFromChilds = _b.sent();
1059
+ result = this._relationFilter(result, dataFromChilds, relation);
1064
1060
  _b.label = 7;
1065
1061
  case 7:
1066
1062
  relations_1_1 = relations_1.next();
@@ -1078,8 +1074,8 @@ var Model = /** @class */ (function (_super) {
1078
1074
  return [7 /*endfinally*/];
1079
1075
  case 11:
1080
1076
  if (this.$db.get('HIDDEN').length)
1081
- this._hiddenColumnModel(mains);
1082
- resultData = this._returnResult(type, mains);
1077
+ this._hiddenColumnModel(result);
1078
+ resultData = this._returnResult(type, result);
1083
1079
  return [2 /*return*/, resultData || emptyData];
1084
1080
  case 12:
1085
1081
  err_3 = _b.sent();
@@ -1089,17 +1085,17 @@ var Model = /** @class */ (function (_super) {
1089
1085
  });
1090
1086
  });
1091
1087
  };
1092
- Model.prototype._execGroup = function (mains, type) {
1088
+ Model.prototype._execGroup = function (dataParents, type) {
1093
1089
  var _a;
1094
1090
  if (type === void 0) { type = 'GET'; }
1095
1091
  return __awaiter(this, void 0, void 0, function () {
1096
- var emptyData, relations, relations_2, relations_2_1, relation, subs, e_2_1, resultData;
1092
+ var emptyData, relations, relations_2, relations_2_1, relation, dataChilds, e_2_1, resultData;
1097
1093
  var e_2, _b;
1098
1094
  return __generator(this, function (_c) {
1099
1095
  switch (_c.label) {
1100
1096
  case 0:
1101
- emptyData = this._returnEmpty(type, mains);
1102
- if (!mains.length)
1097
+ emptyData = this._returnEmpty(type, dataParents);
1098
+ if (!dataParents.length)
1103
1099
  return [2 /*return*/, emptyData];
1104
1100
  relations = this.$db.get('WITH');
1105
1101
  if (!relations.length) return [3 /*break*/, 8];
@@ -1111,12 +1107,13 @@ var Model = /** @class */ (function (_super) {
1111
1107
  case 2:
1112
1108
  if (!!relations_2_1.done) return [3 /*break*/, 5];
1113
1109
  relation = relations_2_1.value;
1114
- if (relation.relation === this.$utils().constants('RELATIONSHIP').belongsToMany)
1115
- return [2 /*return*/, this._belongsToMany(type, mains, relation)];
1116
- return [4 /*yield*/, this._relation(mains, relation)];
1110
+ if (relation.relation === this.$utils().constants('RELATIONSHIP').belongsToMany) {
1111
+ return [2 /*return*/, this._belongsToMany(type, dataParents, relation)];
1112
+ }
1113
+ return [4 /*yield*/, this._relation(dataParents, relation)];
1117
1114
  case 3:
1118
- subs = _c.sent();
1119
- mains = this._relationFilter(mains, subs, relation);
1115
+ dataChilds = _c.sent();
1116
+ dataParents = this._relationFilter(dataParents, dataChilds, relation);
1120
1117
  _c.label = 4;
1121
1118
  case 4:
1122
1119
  relations_2_1 = relations_2.next();
@@ -1134,170 +1131,172 @@ var Model = /** @class */ (function (_super) {
1134
1131
  return [7 /*endfinally*/];
1135
1132
  case 8:
1136
1133
  if ((_a = this.$db.get('HIDDEN')) === null || _a === void 0 ? void 0 : _a.length)
1137
- this._hiddenColumnModel(mains);
1138
- resultData = this._returnResult(type, mains);
1134
+ this._hiddenColumnModel(dataParents);
1135
+ resultData = this._returnResult(type, dataParents);
1139
1136
  return [2 /*return*/, resultData || emptyData];
1140
1137
  }
1141
1138
  });
1142
1139
  });
1143
1140
  };
1144
- Model.prototype._relationFilter = function (mains, subs, relations) {
1141
+ Model.prototype._relationFilter = function (dataParents, dataChilds, relations) {
1145
1142
  var _this = this;
1146
1143
  var _a = this._valueInRelation(relations), name = _a.name, as = _a.as, relation = _a.relation, pk = _a.pk, fk = _a.fk;
1147
1144
  var keyRelation = as !== null && as !== void 0 ? as : name;
1148
- mains.forEach(function (main) {
1145
+ dataParents.forEach(function (dataPerent) {
1149
1146
  if (relation === _this.$utils().constants('RELATIONSHIP').hasOne || relation === _this.$utils().constants('RELATIONSHIP').belongsTo)
1150
- main[keyRelation] = null;
1147
+ dataPerent[keyRelation] = null;
1151
1148
  else
1152
- main[keyRelation] = [];
1153
- if (subs.length) {
1154
- subs.forEach(function (sub) {
1155
- if (sub[fk] === main[pk]) {
1149
+ dataPerent[keyRelation] = [];
1150
+ if (dataChilds.length) {
1151
+ dataChilds.forEach(function (sub) {
1152
+ if (sub[fk] === dataPerent[pk]) {
1156
1153
  if (relation === _this.$utils().constants('RELATIONSHIP').hasOne || relation === _this.$utils().constants('RELATIONSHIP').belongsTo) {
1157
- main[keyRelation] = main[keyRelation] || sub;
1154
+ dataPerent[keyRelation] = dataPerent[keyRelation] || sub;
1158
1155
  }
1159
1156
  else {
1160
- if (main[keyRelation] == null)
1161
- main[keyRelation] = [];
1162
- main[keyRelation].push(sub);
1157
+ if (dataPerent[keyRelation] == null)
1158
+ dataPerent[keyRelation] = [];
1159
+ dataPerent[keyRelation].push(sub);
1163
1160
  }
1164
1161
  }
1165
1162
  });
1166
1163
  }
1167
1164
  });
1168
1165
  if (this.$db.get('WITH_EXISTS')) {
1169
- return mains.filter(function (main) {
1170
- if (Array.isArray(main[keyRelation]))
1171
- return main[keyRelation].length;
1172
- return main[keyRelation] != null;
1166
+ return dataParents.filter(function (dataPerent) {
1167
+ if (Array.isArray(dataPerent[keyRelation]))
1168
+ return dataPerent[keyRelation].length;
1169
+ return dataPerent[keyRelation] != null;
1173
1170
  });
1174
1171
  }
1175
- return mains;
1172
+ return dataParents;
1176
1173
  };
1177
- Model.prototype._relation = function (mains, relations) {
1174
+ Model.prototype._relation = function (parentData, relation) {
1178
1175
  return __awaiter(this, void 0, void 0, function () {
1179
- var _a, pk, fk, pkId, mainId, query, subs;
1176
+ var _a, pk, fk, pkId, dataPerentId, query, childData;
1180
1177
  return __generator(this, function (_b) {
1181
1178
  switch (_b.label) {
1182
1179
  case 0:
1183
- if (!Object.keys(relations).length)
1180
+ if (!Object.keys(relation).length)
1184
1181
  return [2 /*return*/, []];
1185
- _a = this._valueInRelation(relations), pk = _a.pk, fk = _a.fk;
1186
- pkId = mains.map(function (main) { return main[pk]; }).filter(function (data) { return data != null; });
1187
- mainId = Array.from(new Set(pkId)) || [];
1188
- if (!mainId.length && !this.$db.get('WITH_EXISTS'))
1182
+ _a = this._valueInRelation(relation), pk = _a.pk, fk = _a.fk;
1183
+ pkId = parentData.map(function (dataPerent) { return dataPerent[pk]; }).filter(function (data) { return data != null; });
1184
+ dataPerentId = Array.from(new Set(pkId)) || [];
1185
+ if (!dataPerentId.length && !this.$db.get('WITH_EXISTS'))
1189
1186
  throw new Error("can't relationship without primary or foreign key");
1190
- if (!mainId.length && this.$db.get('WITH_EXISTS'))
1187
+ if (!dataPerentId.length && this.$db.get('WITH_EXISTS'))
1191
1188
  return [2 /*return*/, []];
1192
- return [4 /*yield*/, relations.query];
1189
+ return [4 /*yield*/, relation.query];
1193
1190
  case 1:
1194
1191
  query = _b.sent();
1195
- return [4 /*yield*/, query.whereIn(fk, mainId).debug(this.$db.get('DEBUG')).get()];
1192
+ if (query == null)
1193
+ throw new Error("unknow callback queries in [relation : ".concat(relation.name, "]"));
1194
+ return [4 /*yield*/, query.whereIn(fk, dataPerentId).debug(this.$db.get('DEBUG')).get()];
1196
1195
  case 2:
1197
- subs = _b.sent();
1198
- return [2 /*return*/, subs];
1196
+ childData = _b.sent();
1197
+ return [2 /*return*/, childData];
1199
1198
  }
1200
1199
  });
1201
1200
  });
1202
1201
  };
1203
- Model.prototype._belongsToMany = function (type, mains, dataRelation) {
1202
+ Model.prototype._belongsToMany = function (type, dataFromParent, relation) {
1204
1203
  var _a, _b;
1205
1204
  return __awaiter(this, void 0, void 0, function () {
1206
- var _c, name_1, pk_1, fk_1, pkId, mainId, local, modelOther, other_1, pivotTable, otherPk_1, otherFk_1, sqlSubs, subs_1, otherId, otherArrId, otherSubs_1, err_4, _d, name_2, pk_2, fk_2, pkId, mainId, local, modelOther, other_2, pivotTable, otherPk_2, otherFk_2, sqlSubs, subs_2, otherId, otherArrId, otherSubs_2, err_5;
1205
+ var _c, name_1, pk_1, fk_1, pkId, dataPerentId, local, modelOther, other_1, pivotTable, otherPk_1, otherFk_1, sqldataChilds, dataChilds_1, otherId, otherArrId, otherdataChilds_1, err_4, _d, name_2, pk_2, fk_2, pkId, dataPerentId, local, modelOther, other_2, pivotTable, otherPk_2, otherFk_2, sqldataChilds, dataChilds_2, otherId, otherArrId, otherdataChilds_2, err_5;
1207
1206
  return __generator(this, function (_e) {
1208
1207
  switch (_e.label) {
1209
1208
  case 0:
1210
1209
  _e.trys.push([0, 3, , 9]);
1211
- _c = this._valueInRelation(dataRelation), name_1 = _c.name, pk_1 = _c.pk, fk_1 = _c.fk;
1212
- pkId = mains.map(function (main) { return main[pk_1]; }).filter(function (data) { return data != null; });
1213
- mainId = Array.from(new Set(pkId)).join(',') || [];
1214
- if (!mainId.length)
1210
+ _c = this._valueInRelation(relation), name_1 = _c.name, pk_1 = _c.pk, fk_1 = _c.fk;
1211
+ pkId = dataFromParent.map(function (dataPerent) { return dataPerent[pk_1]; }).filter(function (data) { return data != null; });
1212
+ dataPerentId = Array.from(new Set(pkId)).join(',') || [];
1213
+ if (!dataPerentId.length)
1215
1214
  throw new Error("can't relationship without primary or foreign key");
1216
1215
  local = this.$utils().columnRelation(this.constructor.name);
1217
- modelOther = new dataRelation.model();
1218
- other_1 = this._classToTableName(modelOther.constructor.name, true);
1219
- pivotTable = (_a = dataRelation.freezeTable) !== null && _a !== void 0 ? _a : local + "_" + other_1;
1216
+ modelOther = new relation.model();
1217
+ other_1 = this._classToTableName(modelOther.constructor.name, { belongsTo: true });
1218
+ pivotTable = (_a = relation.freezeTable) !== null && _a !== void 0 ? _a : "".concat(local, "_").concat(other_1);
1220
1219
  pk_1 = 'id';
1221
- fk_1 = this._isPatternSnakeCase() ? local + "_id" : local + "Id";
1220
+ fk_1 = this._isPatternSnakeCase() ? "".concat(local, "_id") : "".concat(local, "Id");
1222
1221
  otherPk_1 = 'id';
1223
- otherFk_1 = this._isPatternSnakeCase() ? other_1 + "_id" : other_1 + "Id";
1224
- sqlSubs = this.$utils().constants('SELECT') + " * " + this.$utils().constants('FROM') + " " + pivotTable + " " + this.$utils().constants('WHERE') + " " + fk_1 + " " + this.$utils().constants('IN') + " (" + mainId + ")";
1225
- return [4 /*yield*/, this._queryStatementModel(sqlSubs)];
1222
+ otherFk_1 = this._isPatternSnakeCase() ? "".concat(other_1, "_id") : "".concat(other_1, "Id");
1223
+ sqldataChilds = "".concat(this.$utils().constants('SELECT'), " * ").concat(this.$utils().constants('FROM'), " ").concat(pivotTable, " ").concat(this.$utils().constants('WHERE'), " ").concat(fk_1, " ").concat(this.$utils().constants('IN'), " (").concat(dataPerentId, ")");
1224
+ return [4 /*yield*/, this._queryStatementModel(sqldataChilds)];
1226
1225
  case 1:
1227
- subs_1 = _e.sent();
1228
- otherId = subs_1.map(function (sub) { return sub[otherFk_1]; }).filter(function (data) { return data != null; });
1226
+ dataChilds_1 = _e.sent();
1227
+ otherId = dataChilds_1.map(function (sub) { return sub[otherFk_1]; }).filter(function (data) { return data != null; });
1229
1228
  otherArrId = Array.from(new Set(otherId)) || [];
1230
1229
  return [4 /*yield*/, modelOther.whereIn(otherPk_1, otherArrId).get()];
1231
1230
  case 2:
1232
- otherSubs_1 = _e.sent();
1233
- subs_1.forEach(function (sub) {
1231
+ otherdataChilds_1 = _e.sent();
1232
+ dataChilds_1.forEach(function (sub) {
1234
1233
  sub[other_1] = [];
1235
- otherSubs_1.forEach(function (otherSub) {
1234
+ otherdataChilds_1.forEach(function (otherSub) {
1236
1235
  if (otherSub[otherPk_1] === sub[otherFk_1]) {
1237
1236
  sub[other_1] = otherSub;
1238
1237
  }
1239
1238
  });
1240
1239
  });
1241
- mains.forEach(function (main) {
1242
- if (main[name_1] == null)
1243
- main[name_1] = [];
1244
- subs_1.forEach(function (sub) {
1245
- if (sub[fk_1] === main[pk_1]) {
1246
- main[name_1].push(sub);
1240
+ dataFromParent.forEach(function (dataPerent) {
1241
+ if (dataPerent[name_1] == null)
1242
+ dataPerent[name_1] = [];
1243
+ dataChilds_1.forEach(function (sub) {
1244
+ if (sub[fk_1] === dataPerent[pk_1]) {
1245
+ dataPerent[name_1].push(sub);
1247
1246
  }
1248
1247
  });
1249
1248
  });
1250
1249
  if (this.$db.get('HIDDEN').length)
1251
- this._hiddenColumnModel(mains);
1252
- return [2 /*return*/, mains];
1250
+ this._hiddenColumnModel(dataFromParent);
1251
+ return [2 /*return*/, dataFromParent];
1253
1252
  case 3:
1254
1253
  err_4 = _e.sent();
1255
1254
  _e.label = 4;
1256
1255
  case 4:
1257
1256
  _e.trys.push([4, 7, , 8]);
1258
- _d = this._valueInRelation(dataRelation), name_2 = _d.name, pk_2 = _d.pk, fk_2 = _d.fk;
1259
- pkId = mains.map(function (main) { return main[pk_2]; }).filter(function (data) { return data != null; });
1260
- mainId = Array.from(new Set(pkId)).join(',') || [];
1261
- if (!mainId.length)
1257
+ _d = this._valueInRelation(relation), name_2 = _d.name, pk_2 = _d.pk, fk_2 = _d.fk;
1258
+ pkId = dataFromParent.map(function (dataPerent) { return dataPerent[pk_2]; }).filter(function (data) { return data != null; });
1259
+ dataPerentId = Array.from(new Set(pkId)).join(',') || [];
1260
+ if (!dataPerentId.length)
1262
1261
  throw new Error("can't relationship without primary or foreign key");
1263
1262
  local = this.$utils().columnRelation(this.constructor.name);
1264
- modelOther = new dataRelation.model();
1263
+ modelOther = new relation.model();
1265
1264
  other_2 = modelOther.constructor.name.toLocaleLowerCase();
1266
- pivotTable = (_b = dataRelation.freezeTable) !== null && _b !== void 0 ? _b : other_2 + "_" + local;
1265
+ pivotTable = (_b = relation.freezeTable) !== null && _b !== void 0 ? _b : "".concat(other_2, "_").concat(local);
1267
1266
  pk_2 = 'id';
1268
- fk_2 = this._isPatternSnakeCase() ? local + "_id" : local + "Id";
1267
+ fk_2 = this._isPatternSnakeCase() ? "".concat(local, "_id") : "".concat(local, "Id");
1269
1268
  otherPk_2 = 'id';
1270
- otherFk_2 = this._isPatternSnakeCase() ? other_2 + "_id" : other_2 + "Id";
1271
- sqlSubs = this.$utils().constants('SELECT') + " * " + this.$utils().constants('FROM') + " " + pivotTable + " " + this.$utils().constants('WHERE') + " " + fk_2 + " " + this.$utils().constants('IN') + " (" + mainId + ")";
1272
- return [4 /*yield*/, this._queryStatementModel(sqlSubs)];
1269
+ otherFk_2 = this._isPatternSnakeCase() ? "".concat(other_2, "_id") : "".concat(other_2, "Id");
1270
+ sqldataChilds = "".concat(this.$utils().constants('SELECT'), " * ").concat(this.$utils().constants('FROM'), " ").concat(pivotTable, " ").concat(this.$utils().constants('WHERE'), " ").concat(fk_2, " ").concat(this.$utils().constants('IN'), " (").concat(dataPerentId, ")");
1271
+ return [4 /*yield*/, this._queryStatementModel(sqldataChilds)];
1273
1272
  case 5:
1274
- subs_2 = _e.sent();
1275
- otherId = subs_2.map(function (sub) { return sub[otherFk_2]; }).filter(function (data) { return data != null; });
1273
+ dataChilds_2 = _e.sent();
1274
+ otherId = dataChilds_2.map(function (sub) { return sub[otherFk_2]; }).filter(function (data) { return data != null; });
1276
1275
  otherArrId = Array.from(new Set(otherId)) || [];
1277
1276
  return [4 /*yield*/, this._queryStatementModel(modelOther
1278
1277
  .whereIn(otherPk_2, otherArrId)
1279
1278
  .toString())];
1280
1279
  case 6:
1281
- otherSubs_2 = _e.sent();
1282
- subs_2.forEach(function (sub) {
1283
- otherSubs_2.forEach(function (otherSub) {
1280
+ otherdataChilds_2 = _e.sent();
1281
+ dataChilds_2.forEach(function (sub) {
1282
+ otherdataChilds_2.forEach(function (otherSub) {
1284
1283
  if (otherSub[otherPk_2] === sub[otherFk_2]) {
1285
1284
  sub[other_2] = otherSub;
1286
1285
  }
1287
1286
  });
1288
1287
  });
1289
- mains.forEach(function (main) {
1290
- if (main[name_2] == null)
1291
- main[name_2] = [];
1292
- subs_2.forEach(function (sub) {
1293
- if (sub[fk_2] === main[pk_2]) {
1294
- main[name_2].push(sub);
1288
+ dataFromParent.forEach(function (dataPerent) {
1289
+ if (dataPerent[name_2] == null)
1290
+ dataPerent[name_2] = [];
1291
+ dataChilds_2.forEach(function (sub) {
1292
+ if (sub[fk_2] === dataPerent[pk_2]) {
1293
+ dataPerent[name_2].push(sub);
1295
1294
  }
1296
1295
  });
1297
1296
  });
1298
1297
  if (this.$db.get('HIDDEN').length)
1299
- this._hiddenColumnModel(mains);
1300
- return [2 /*return*/, mains];
1298
+ this._hiddenColumnModel(dataFromParent);
1299
+ return [2 /*return*/, dataFromParent];
1301
1300
  case 7:
1302
1301
  err_5 = _e.sent();
1303
1302
  throw new Error(err_5.message);
@@ -1315,12 +1314,12 @@ var Model = /** @class */ (function (_super) {
1315
1314
  switch (_b.label) {
1316
1315
  case 0:
1317
1316
  currentPage = this.$db.get('PAGE');
1318
- this.select(this.$utils().constants('COUNT') + "(*) " + this.$utils().constants('AS') + " total");
1317
+ this.select("".concat(this.$utils().constants('COUNT'), "(*) ").concat(this.$utils().constants('AS'), " total"));
1319
1318
  sql = this._getSQLModel();
1320
1319
  return [4 /*yield*/, this._queryStatementModel(sql)];
1321
1320
  case 1:
1322
1321
  res = _b.sent();
1323
- total = res.shift().total || 0;
1322
+ total = (res === null || res === void 0 ? void 0 : res.shift().total) || 0;
1324
1323
  limit = this.$db.get('PER_PAGE');
1325
1324
  lastPage = Math.ceil(total / limit) || 0;
1326
1325
  lastPage = lastPage > 1 ? lastPage : 1;
@@ -1404,7 +1403,19 @@ var Model = /** @class */ (function (_super) {
1404
1403
  }
1405
1404
  switch (type) {
1406
1405
  case 'FIRST': return this._result((_c = data[0]) !== null && _c !== void 0 ? _c : {});
1407
- case 'GET': return this._result(data);
1406
+ case 'GET': {
1407
+ if (this.$db.get('CHUNK')) {
1408
+ var result = data.reduce(function (resultArray, item, index) {
1409
+ var chunkIndex = Math.floor(index / _this.$db.get('CHUNK'));
1410
+ if (!resultArray[chunkIndex])
1411
+ resultArray[chunkIndex] = [];
1412
+ resultArray[chunkIndex].push(item);
1413
+ return resultArray;
1414
+ }, []);
1415
+ return this._result(result);
1416
+ }
1417
+ return this._result(data);
1418
+ }
1408
1419
  case 'PAGINATION': return this._pagination(data);
1409
1420
  default: throw new Error('Missing method first get or pagination');
1410
1421
  }
@@ -1429,20 +1440,20 @@ var Model = /** @class */ (function (_super) {
1429
1440
  switch (_b.label) {
1430
1441
  case 0:
1431
1442
  if (!Array.isArray(dataId))
1432
- throw new Error("this " + dataId + " is not an array");
1443
+ throw new Error("this ".concat(dataId, " is not an array"));
1433
1444
  relation = (_a = this.$db.get('RELATION')) === null || _a === void 0 ? void 0 : _a.find(function (data) { return data.name === name; });
1434
1445
  if (!relation)
1435
- throw new Error("unknow name relation [" + name + "] in model");
1446
+ throw new Error("unknow name relation [".concat(name, "] in model"));
1436
1447
  thisTable = this.$utils().columnRelation(this.constructor.name);
1437
- relationTable = this._classToTableName(relation.model.name, true);
1448
+ relationTable = this._classToTableName(relation.model.name, { belongsTo: true });
1438
1449
  result = this.$db.get('RESULT');
1439
1450
  _b.label = 1;
1440
1451
  case 1:
1441
1452
  _b.trys.push([1, 3, , 8]);
1442
- pivotTable = thisTable + "_" + relationTable;
1453
+ pivotTable = "".concat(thisTable, "_").concat(relationTable);
1443
1454
  return [4 /*yield*/, new DB_1.default().table(pivotTable).createMultiple(dataId.map(function (id) {
1444
1455
  var _a;
1445
- return __assign((_a = {}, _a[_this._isPatternSnakeCase() ? relationTable + "_id" : relationTable + "Id"] = id, _a[_this._isPatternSnakeCase() ? thisTable + "_id" : thisTable + "Id"] = result === null || result === void 0 ? void 0 : result.id, _a), fields);
1456
+ return __assign((_a = {}, _a[_this._isPatternSnakeCase() ? "".concat(relationTable, "_id") : "".concat(relationTable, "Id")] = id, _a[_this._isPatternSnakeCase() ? "".concat(thisTable, "_id") : "".concat(thisTable, "Id")] = result === null || result === void 0 ? void 0 : result.id, _a), fields);
1446
1457
  })).save()];
1447
1458
  case 2:
1448
1459
  success = _b.sent();
@@ -1456,10 +1467,10 @@ var Model = /** @class */ (function (_super) {
1456
1467
  _b.label = 4;
1457
1468
  case 4:
1458
1469
  _b.trys.push([4, 6, , 7]);
1459
- pivotTable = relationTable + "_" + thisTable;
1470
+ pivotTable = "".concat(relationTable, "_").concat(thisTable);
1460
1471
  return [4 /*yield*/, new DB_1.default().table(pivotTable).createMultiple(dataId.map(function (id) {
1461
1472
  var _a;
1462
- return __assign((_a = {}, _a[_this._isPatternSnakeCase() ? relationTable + "_id" : relationTable + "Id"] = id, _a[_this._isPatternSnakeCase() ? thisTable + "_id" : thisTable + "Id"] = result.id, _a), fields);
1473
+ return __assign((_a = {}, _a[_this._isPatternSnakeCase() ? "".concat(relationTable, "_id") : "".concat(relationTable, "Id")] = id, _a[_this._isPatternSnakeCase() ? "".concat(thisTable, "_id") : "".concat(thisTable, "Id")] = result.id, _a), fields);
1463
1474
  })).save()];
1464
1475
  case 5:
1465
1476
  success = _b.sent();
@@ -1481,17 +1492,17 @@ var Model = /** @class */ (function (_super) {
1481
1492
  switch (_c.label) {
1482
1493
  case 0:
1483
1494
  if (!Array.isArray(dataId))
1484
- throw new Error("this " + dataId + " is not an array");
1495
+ throw new Error("this ".concat(dataId, " is not an array"));
1485
1496
  relation = this.$db.get('RELATION').find(function (data) { return data.name === name; });
1486
1497
  if (!relation)
1487
- throw new Error("unknow name relation [" + name + "] in model");
1498
+ throw new Error("unknow name relation [".concat(name, "] in model"));
1488
1499
  thisTable = this.$utils().columnRelation(this.constructor.name);
1489
- relationTable = this._classToTableName(relation.model.name, true);
1500
+ relationTable = this._classToTableName(relation.model.name, { belongsTo: true });
1490
1501
  result = this.$db.get('RESULT');
1491
1502
  _c.label = 1;
1492
1503
  case 1:
1493
1504
  _c.trys.push([1, 10, , 22]);
1494
- pivotTable = thisTable + "_" + relationTable;
1505
+ pivotTable = "".concat(thisTable, "_").concat(relationTable);
1495
1506
  _c.label = 2;
1496
1507
  case 2:
1497
1508
  _c.trys.push([2, 7, 8, 9]);
@@ -1501,8 +1512,8 @@ var Model = /** @class */ (function (_super) {
1501
1512
  if (!!dataId_1_1.done) return [3 /*break*/, 6];
1502
1513
  id = dataId_1_1.value;
1503
1514
  return [4 /*yield*/, new DB_1.default().table(pivotTable)
1504
- .where(this._isPatternSnakeCase() ? relationTable + "_id" : relationTable + "Id", id)
1505
- .where(this._isPatternSnakeCase() ? thisTable + "_id" : thisTable + "Id", result.id)
1515
+ .where(this._isPatternSnakeCase() ? "".concat(relationTable, "_id") : "".concat(relationTable, "Id"), id)
1516
+ .where(this._isPatternSnakeCase() ? "".concat(thisTable, "_id") : "".concat(thisTable, "Id"), result.id)
1506
1517
  .delete()];
1507
1518
  case 4:
1508
1519
  _c.sent();
@@ -1531,7 +1542,7 @@ var Model = /** @class */ (function (_super) {
1531
1542
  _c.label = 11;
1532
1543
  case 11:
1533
1544
  _c.trys.push([11, 20, , 21]);
1534
- pivotTable = relationTable + "_" + thisTable;
1545
+ pivotTable = "".concat(relationTable, "_").concat(thisTable);
1535
1546
  _c.label = 12;
1536
1547
  case 12:
1537
1548
  _c.trys.push([12, 17, 18, 19]);
@@ -1541,8 +1552,8 @@ var Model = /** @class */ (function (_super) {
1541
1552
  if (!!dataId_2_1.done) return [3 /*break*/, 16];
1542
1553
  id = dataId_2_1.value;
1543
1554
  return [4 /*yield*/, new DB_1.default().table(pivotTable)
1544
- .where(this._isPatternSnakeCase() ? relationTable + "_id" : relationTable + "Id", id)
1545
- .where(this._isPatternSnakeCase() ? thisTable + "_id" : thisTable + "Id", result.id)
1555
+ .where(this._isPatternSnakeCase() ? "".concat(relationTable, "_id") : "".concat(relationTable, "Id"), id)
1556
+ .where(this._isPatternSnakeCase() ? "".concat(thisTable, "_id") : "".concat(thisTable, "Id"), result.id)
1546
1557
  .delete()];
1547
1558
  case 14:
1548
1559
  _c.sent();
@@ -1580,11 +1591,11 @@ var Model = /** @class */ (function (_super) {
1580
1591
  }
1581
1592
  var keyValue = Object.entries(objects).map(function (_a) {
1582
1593
  var _b = __read(_a, 2), column = _b[0], value = _b[1];
1583
- return column + " = " + (value == null || value === 'NULL' ?
1594
+ return "".concat(column, " = ").concat(value == null || value === 'NULL' ?
1584
1595
  'NULL' :
1585
- "'" + _this.$utils().covertBooleanToNumber(value) + "'");
1596
+ "'".concat(_this.$utils().covertBooleanToNumber(value), "'"));
1586
1597
  });
1587
- return this.$utils().constants('SET') + " " + keyValue;
1598
+ return "".concat(this.$utils().constants('SET'), " ").concat(keyValue);
1588
1599
  };
1589
1600
  Model.prototype._queryInsertModel = function (objects) {
1590
1601
  var _a, _b;
@@ -1597,13 +1608,13 @@ var Model = /** @class */ (function (_super) {
1597
1608
  if (this.$db.get('UUID')) {
1598
1609
  objects = __assign(__assign({}, objects), (_b = {}, _b[this.$db.get('UUID_CUSTOM')] = this.$utils().generateUUID(), _b));
1599
1610
  }
1600
- var columns = Object.keys(objects).map(function (data) { return "" + data; });
1611
+ var columns = Object.keys(objects).map(function (data) { return "".concat(data); });
1601
1612
  var values = Object.values(objects).map(function (data) {
1602
- return "" + (data == null || data === 'NULL' ?
1613
+ return "".concat(data == null || data === 'NULL' ?
1603
1614
  'NULL' :
1604
- "'" + _this.$utils().covertBooleanToNumber(data) + "'");
1615
+ "'".concat(_this.$utils().covertBooleanToNumber(data), "'"));
1605
1616
  });
1606
- return "(" + columns + ") " + this.$utils().constants('VALUES') + " (" + values + ")";
1617
+ return "(".concat(columns, ") ").concat(this.$utils().constants('VALUES'), " (").concat(values, ")");
1607
1618
  };
1608
1619
  Model.prototype._queryInsertMultipleModel = function (data) {
1609
1620
  var e_9, _a;
@@ -1622,11 +1633,11 @@ var Model = /** @class */ (function (_super) {
1622
1633
  if (this.$db.get('UUID'))
1623
1634
  objects[this.$db.get('UUID_CUSTOM')] = this.$utils().generateUUID();
1624
1635
  var val = Object.values(objects).map(function (data) {
1625
- return "" + (data == null || data === 'NULL' ?
1636
+ return "".concat(data == null || data === 'NULL' ?
1626
1637
  'NULL' :
1627
- "'" + _this.$utils().covertBooleanToNumber(data) + "'");
1638
+ "'".concat(_this.$utils().covertBooleanToNumber(data), "'"));
1628
1639
  });
1629
- values.push("(" + val.join(',') + ")");
1640
+ values.push("(".concat(val.join(','), ")"));
1630
1641
  }
1631
1642
  }
1632
1643
  catch (e_9_1) { e_9 = { error: e_9_1 }; }
@@ -1636,8 +1647,8 @@ var Model = /** @class */ (function (_super) {
1636
1647
  }
1637
1648
  finally { if (e_9) throw e_9.error; }
1638
1649
  }
1639
- var columns = Object.keys((_b = data[0]) !== null && _b !== void 0 ? _b : []).map(function (data) { return "" + data; });
1640
- return "(" + columns + ") " + this.$utils().constants('VALUES') + " " + values.join(',');
1650
+ var columns = Object.keys((_b = data[0]) !== null && _b !== void 0 ? _b : []).map(function (data) { return "".concat(data); });
1651
+ return "(".concat(columns, ") ").concat(this.$utils().constants('VALUES'), " ").concat(values.join(','));
1641
1652
  };
1642
1653
  Model.prototype._registry = function (data) {
1643
1654
  var _this = this;
@@ -1663,7 +1674,7 @@ var Model = /** @class */ (function (_super) {
1663
1674
  throw new Error("Can't insert not exists without where condition");
1664
1675
  sql = '';
1665
1676
  check = false;
1666
- sql = this.$utils().constants('SELECT') + " " + this.$utils().constants('EXISTS') + "(" + this.$utils().constants('SELECT') + " * " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$db.get('WHERE') + " " + this.$utils().constants('LIMIT') + " 1) " + this.$utils().constants('AS') + " 'exists'";
1677
+ sql = "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('EXISTS'), "(").concat(this.$utils().constants('SELECT'), " * ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('LIMIT'), " 1) ").concat(this.$utils().constants('AS'), " 'exists'");
1667
1678
  return [4 /*yield*/, this._queryStatementModel(sql)];
1668
1679
  case 1:
1669
1680
  _b = __read.apply(void 0, [_e.sent(), 1]), result = _b[0].exists;
@@ -1684,7 +1695,7 @@ var Model = /** @class */ (function (_super) {
1684
1695
  });
1685
1696
  }
1686
1697
  if (!result_3) return [3 /*break*/, 5];
1687
- sql_1 = this.$db.get('SELECT') + " " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$utils().constants('WHERE') + " id = " + id;
1698
+ sql_1 = "".concat(this.$db.get('SELECT'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$utils().constants('WHERE'), " id = ").concat(id);
1688
1699
  return [4 /*yield*/, this._queryStatementModel(sql_1)];
1689
1700
  case 4:
1690
1701
  data = _e.sent();
@@ -1721,7 +1732,7 @@ var Model = /** @class */ (function (_super) {
1721
1732
  });
1722
1733
  }
1723
1734
  if (!result) return [3 /*break*/, 3];
1724
- sql = this.$db.get('SELECT') + " " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$utils().constants('WHERE') + " id = " + id;
1735
+ sql = "".concat(this.$db.get('SELECT'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$utils().constants('WHERE'), " id = ").concat(id);
1725
1736
  return [4 /*yield*/, this._queryStatementModel(sql)];
1726
1737
  case 2:
1727
1738
  data = _c.sent();
@@ -1763,7 +1774,7 @@ var Model = /** @class */ (function (_super) {
1763
1774
  }
1764
1775
  finally { if (e_10) throw e_10.error; }
1765
1776
  }
1766
- sql = this.$db.get('SELECT') + " " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$utils().constants('WHERE') + " id " + this.$utils().constants('IN') + " (" + arrayId + ")";
1777
+ sql = "".concat(this.$db.get('SELECT'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$utils().constants('WHERE'), " id ").concat(this.$utils().constants('IN'), " (").concat(arrayId, ")");
1767
1778
  return [4 /*yield*/, this._queryStatementModel(sql)];
1768
1779
  case 2:
1769
1780
  data = _d.sent();
@@ -1787,7 +1798,7 @@ var Model = /** @class */ (function (_super) {
1787
1798
  throw new Error("Can't update or insert without where condition");
1788
1799
  sql = '';
1789
1800
  check = false;
1790
- sql = this.$utils().constants('SELECT') + " " + this.$utils().constants('EXISTS') + "(" + this.$utils().constants('SELECT') + " * " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$db.get('WHERE') + " " + this.$utils().constants('LIMIT') + " 1) " + this.$utils().constants('AS') + " 'exists'";
1801
+ sql = "".concat(this.$utils().constants('SELECT'), " ").concat(this.$utils().constants('EXISTS'), "(").concat(this.$utils().constants('SELECT'), " * ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$db.get('WHERE'), " ").concat(this.$utils().constants('LIMIT'), " 1) ").concat(this.$utils().constants('AS'), " 'exists'");
1791
1802
  return [4 /*yield*/, this._queryStatementModel(sql)];
1792
1803
  case 1:
1793
1804
  _b = __read.apply(void 0, [_f.sent(), 1]), result = _b[0].exists;
@@ -1808,7 +1819,7 @@ var Model = /** @class */ (function (_super) {
1808
1819
  });
1809
1820
  }
1810
1821
  if (!result_5) return [3 /*break*/, 5];
1811
- sql_2 = this.$db.get('SELECT') + " " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$utils().constants('WHERE') + " id = " + id;
1822
+ sql_2 = "".concat(this.$db.get('SELECT'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$utils().constants('WHERE'), " id = ").concat(id);
1812
1823
  return [4 /*yield*/, this._queryStatementModel(sql_2)];
1813
1824
  case 4:
1814
1825
  data = _f.sent();
@@ -1816,11 +1827,11 @@ var Model = /** @class */ (function (_super) {
1816
1827
  this.$db.set('RESULT', resultData);
1817
1828
  return [2 /*return*/, resultData];
1818
1829
  case 5: return [2 /*return*/, null];
1819
- case 6: return [4 /*yield*/, this._actionStatementModel({ sql: this.$db.get('UPDATE') + " " + this.$db.get('WHERE') })];
1830
+ case 6: return [4 /*yield*/, this._actionStatementModel({ sql: "".concat(this.$db.get('UPDATE'), " ").concat(this.$db.get('WHERE')) })];
1820
1831
  case 7:
1821
1832
  result_6 = _f.sent();
1822
1833
  if (!result_6) return [3 /*break*/, 9];
1823
- return [4 /*yield*/, this._queryStatementModel(this.$db.get('SELECT') + " " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$db.get('WHERE'))];
1834
+ return [4 /*yield*/, this._queryStatementModel("".concat(this.$db.get('SELECT'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$db.get('WHERE')))];
1824
1835
  case 8:
1825
1836
  data = _f.sent();
1826
1837
  if ((data === null || data === void 0 ? void 0 : data.length) > 1) {
@@ -1860,11 +1871,11 @@ var Model = /** @class */ (function (_super) {
1860
1871
  case 0:
1861
1872
  if (!this.$db.get('WHERE') && !ignoreWhere)
1862
1873
  throw new Error("Can't update without where condition");
1863
- return [4 /*yield*/, this._actionStatementModel({ sql: this.$db.get('UPDATE') + " " + this.$db.get('WHERE') })];
1874
+ return [4 /*yield*/, this._actionStatementModel({ sql: "".concat(this.$db.get('UPDATE'), " ").concat(this.$db.get('WHERE')) })];
1864
1875
  case 1:
1865
1876
  result = _a.sent();
1866
1877
  if (!result) return [3 /*break*/, 3];
1867
- return [4 /*yield*/, this._queryStatementModel(this.$db.get('SELECT') + " " + this.$db.get('FROM') + " " + this.$db.get('TABLE_NAME') + " " + this.$db.get('WHERE'))];
1878
+ return [4 /*yield*/, this._queryStatementModel("".concat(this.$db.get('SELECT'), " ").concat(this.$db.get('FROM'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(this.$db.get('WHERE')))];
1868
1879
  case 2:
1869
1880
  data = _a.sent();
1870
1881
  if ((data === null || data === void 0 ? void 0 : data.length) > 1)
@@ -1895,12 +1906,12 @@ var Model = /** @class */ (function (_super) {
1895
1906
  if ((_a = Object.keys(attributes)) === null || _a === void 0 ? void 0 : _a.length) {
1896
1907
  if (this.$db.get('WHERE')) {
1897
1908
  query_1 = this._queryUpdateModel(attributes);
1898
- this.$db.set('UPDATE', this.$utils().constants('UPDATE') + " " + this.$db.get('TABLE_NAME') + " " + query_1);
1909
+ this.$db.set('UPDATE', "".concat(this.$utils().constants('UPDATE'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query_1));
1899
1910
  this.$db.set('SAVE', 'UPDATE');
1900
1911
  return [2 /*return*/];
1901
1912
  }
1902
1913
  query = this._queryInsertModel(attributes);
1903
- this.$db.set('INSERT', this.$utils().constants('INSERT') + " " + this.$db.get('TABLE_NAME') + " " + query);
1914
+ this.$db.set('INSERT', "".concat(this.$utils().constants('INSERT'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query));
1904
1915
  this.$db.set('SAVE', 'INSERT');
1905
1916
  }
1906
1917
  _b = this.$db.get('SAVE');
@@ -1922,7 +1933,7 @@ var Model = /** @class */ (function (_super) {
1922
1933
  case 8: return [2 /*return*/, _c.sent()];
1923
1934
  case 9: return [4 /*yield*/, this._updateOrInsertModel()];
1924
1935
  case 10: return [2 /*return*/, _c.sent()];
1925
- case 11: throw new Error("unknow this [" + this.$db.get('SAVE') + "]");
1936
+ case 11: throw new Error("unknow this [".concat(this.$db.get('SAVE'), "]"));
1926
1937
  }
1927
1938
  });
1928
1939
  });
@@ -1947,7 +1958,7 @@ var Model = /** @class */ (function (_super) {
1947
1958
  if (!(round < rounds)) return [3 /*break*/, 4];
1948
1959
  if (this.$db.get('TABLE_NAME') === '' || this.$db.get('TABLE_NAME') == null)
1949
1960
  throw new Error("unknow table");
1950
- sql = this.$utils().constants('SHOW') + " " + this.$utils().constants('FIELDS') + " " + this.$utils().constants('FROM') + " " + this.$db.get('TABLE_NAME');
1961
+ sql = "".concat(this.$utils().constants('SHOW'), " ").concat(this.$utils().constants('FIELDS'), " ").concat(this.$utils().constants('FROM'), " ").concat(this.$db.get('TABLE_NAME'));
1951
1962
  return [4 /*yield*/, this._queryStatementModel(sql)];
1952
1963
  case 2:
1953
1964
  fields = _d.sent();
@@ -1974,7 +1985,7 @@ var Model = /** @class */ (function (_super) {
1974
1985
  return [3 /*break*/, 1];
1975
1986
  case 4:
1976
1987
  query = this._queryInsertMultipleModel(data);
1977
- this.$db.set('INSERT', this.$utils().constants('INSERT') + " " + this.$db.get('TABLE_NAME') + " " + query);
1988
+ this.$db.set('INSERT', "".concat(this.$utils().constants('INSERT'), " ").concat(this.$db.get('TABLE_NAME'), " ").concat(query));
1978
1989
  this.$db.set('SAVE', 'INSERT_MULTIPLE');
1979
1990
  return [2 /*return*/, this.save()];
1980
1991
  }
@@ -1999,7 +2010,7 @@ var Model = /** @class */ (function (_super) {
1999
2010
  };
2000
2011
  };
2001
2012
  Model.prototype._setupModel = function () {
2002
- var modelData = {
2013
+ var db = {
2003
2014
  TRANSACTION: { query: [{
2004
2015
  table: '',
2005
2016
  id: ''
@@ -2015,6 +2026,7 @@ var Model = /** @class */ (function (_super) {
2015
2026
  SELECT: '',
2016
2027
  ONLY: [],
2017
2028
  EXCEPT: [],
2029
+ CHUNK: 0,
2018
2030
  COUNT: '',
2019
2031
  FROM: '',
2020
2032
  JOIN: '',
@@ -2046,17 +2058,16 @@ var Model = /** @class */ (function (_super) {
2046
2058
  };
2047
2059
  return {
2048
2060
  get: function (key) {
2049
- if (key) {
2050
- if (!modelData.hasOwnProperty(key))
2051
- throw new Error("can't get this [" + key + "]");
2052
- return modelData[key];
2053
- }
2054
- return modelData;
2061
+ if (key == null)
2062
+ return db;
2063
+ if (!db.hasOwnProperty(key))
2064
+ throw new Error("can't get this [".concat(key, "]"));
2065
+ return db[key];
2055
2066
  },
2056
2067
  set: function (key, value) {
2057
- if (!modelData.hasOwnProperty(key))
2058
- throw new Error("can't set this [" + key + "]");
2059
- modelData[key] = value;
2068
+ if (!db.hasOwnProperty(key))
2069
+ throw new Error("can't set this [".concat(key, "]"));
2070
+ db[key] = value;
2060
2071
  return;
2061
2072
  }
2062
2073
  };