tspace-mysql 1.9.0 → 1.9.1

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 (108) hide show
  1. package/README.md +4357 -133
  2. package/dist/lib/config/index.d.ts +2 -2
  3. package/dist/lib/config/index.js +24 -16
  4. package/dist/lib/config/index.js.map +1 -1
  5. package/dist/lib/constants/index.d.ts +10 -1
  6. package/dist/lib/constants/index.js +11 -2
  7. package/dist/lib/constants/index.js.map +1 -1
  8. package/dist/lib/core/Abstracts/AbstractBuilder.d.ts +11 -7
  9. package/dist/lib/core/Abstracts/AbstractBuilder.js +11 -13
  10. package/dist/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
  11. package/dist/lib/core/Abstracts/AbstractDB.d.ts +4 -1
  12. package/dist/lib/core/Abstracts/AbstractDB.js.map +1 -1
  13. package/dist/lib/core/Abstracts/AbstractView.js.map +1 -1
  14. package/dist/lib/core/Blueprint.d.ts +30 -10
  15. package/dist/lib/core/Blueprint.js +39 -14
  16. package/dist/lib/core/Blueprint.js.map +1 -1
  17. package/dist/lib/core/Builder.d.ts +263 -9
  18. package/dist/lib/core/Builder.js +610 -347
  19. package/dist/lib/core/Builder.js.map +1 -1
  20. package/dist/lib/core/Cache/DBCache.js +19 -20
  21. package/dist/lib/core/Cache/DBCache.js.map +1 -1
  22. package/dist/lib/core/Cache/MemoryCache.js +3 -3
  23. package/dist/lib/core/Cache/MemoryCache.js.map +1 -1
  24. package/dist/lib/core/Cache/RedisCache.js +27 -17
  25. package/dist/lib/core/Cache/RedisCache.js.map +1 -1
  26. package/dist/lib/core/Cache/index.js +5 -4
  27. package/dist/lib/core/Cache/index.js.map +1 -1
  28. package/dist/lib/core/Contracts/AlterTable.d.ts +152 -0
  29. package/dist/lib/core/Contracts/AlterTable.js +243 -0
  30. package/dist/lib/core/Contracts/AlterTable.js.map +1 -0
  31. package/dist/lib/core/Contracts/Audit.js +2 -5
  32. package/dist/lib/core/Contracts/Audit.js.map +1 -1
  33. package/dist/lib/core/DB.d.ts +101 -9
  34. package/dist/lib/core/DB.js +168 -29
  35. package/dist/lib/core/DB.js.map +1 -1
  36. package/dist/lib/core/Decorator.d.ts +144 -16
  37. package/dist/lib/core/Decorator.js +156 -14
  38. package/dist/lib/core/Decorator.js.map +1 -1
  39. package/dist/lib/core/Driver/index.d.ts +43 -9
  40. package/dist/lib/core/Driver/index.js +9 -7
  41. package/dist/lib/core/Driver/index.js.map +1 -1
  42. package/dist/lib/core/Driver/mariadb/MariadbDriver.js +74 -27
  43. package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
  44. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +45 -9
  45. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js +165 -21
  46. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -1
  47. package/dist/lib/core/Driver/mongodb/MongodbDriver.d.ts +24 -0
  48. package/dist/lib/core/Driver/mongodb/MongodbDriver.js +255 -0
  49. package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -0
  50. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.d.ts +141 -0
  51. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js +563 -0
  52. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js.map +1 -0
  53. package/dist/lib/core/Driver/mysql/MysqlDriver.js +105 -95
  54. package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
  55. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +45 -9
  56. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js +165 -21
  57. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -1
  58. package/dist/lib/core/Driver/postgres/PostgresDriver.js +97 -72
  59. package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
  60. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +50 -9
  61. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js +296 -41
  62. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -1
  63. package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +20 -0
  64. package/dist/lib/core/Driver/sqlite/SqliteDriver.js +192 -0
  65. package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -0
  66. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.d.ts +144 -0
  67. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js +689 -0
  68. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js.map +1 -0
  69. package/dist/lib/core/JoinModel.js +2 -2
  70. package/dist/lib/core/JoinModel.js.map +1 -1
  71. package/dist/lib/core/Meta.d.ts +17 -11
  72. package/dist/lib/core/Meta.js +25 -19
  73. package/dist/lib/core/Meta.js.map +1 -1
  74. package/dist/lib/core/Model.d.ts +450 -108
  75. package/dist/lib/core/Model.js +1031 -587
  76. package/dist/lib/core/Model.js.map +1 -1
  77. package/dist/lib/{tools/index.d.ts → core/Package.d.ts} +11 -3
  78. package/dist/lib/{tools/index.js → core/Package.js} +20 -7
  79. package/dist/lib/core/Package.js.map +1 -0
  80. package/dist/lib/core/Pool.js +42 -30
  81. package/dist/lib/core/Pool.js.map +1 -1
  82. package/dist/lib/core/Queue.d.ts +240 -0
  83. package/dist/lib/core/Queue.js +686 -0
  84. package/dist/lib/core/Queue.js.map +1 -0
  85. package/dist/lib/core/RelationManager.js +27 -25
  86. package/dist/lib/core/RelationManager.js.map +1 -1
  87. package/dist/lib/core/Repository.d.ts +73 -207
  88. package/dist/lib/core/Repository.js +120 -235
  89. package/dist/lib/core/Repository.js.map +1 -1
  90. package/dist/lib/core/Schema.d.ts +218 -0
  91. package/dist/lib/core/Schema.js +370 -65
  92. package/dist/lib/core/Schema.js.map +1 -1
  93. package/dist/lib/core/StateManager.d.ts +25 -12
  94. package/dist/lib/core/StateManager.js +10 -5
  95. package/dist/lib/core/StateManager.js.map +1 -1
  96. package/dist/lib/core/UtilityTypes.d.ts +85 -56
  97. package/dist/lib/core/UtilityTypes.js.map +1 -1
  98. package/dist/lib/core/index.d.ts +4 -0
  99. package/dist/lib/core/index.js +6 -2
  100. package/dist/lib/core/index.js.map +1 -1
  101. package/dist/lib/types/decorator/index.d.ts +1 -1
  102. package/dist/lib/types/index.d.ts +69 -22
  103. package/dist/lib/types/repository/index.d.ts +68 -37
  104. package/dist/lib/utils/index.d.ts +11 -1
  105. package/dist/lib/utils/index.js +58 -2
  106. package/dist/lib/utils/index.js.map +1 -1
  107. package/package.json +14 -6
  108. package/dist/lib/tools/index.js.map +0 -1
@@ -24,7 +24,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
24
24
  }
25
25
  /**
26
26
  * The 'driver' method is used to get current driver
27
- * @returns {string} driver
27
+ * @returns {TDriver} driver
28
28
  */
29
29
  driver() {
30
30
  return this.$driver;
@@ -37,16 +37,83 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
37
37
  return this.$database;
38
38
  }
39
39
  /**
40
- * The 'rowLock' method is used to row level locks
40
+ * The 'rowLock' method is used to row level locks (`FOR UPDATE` or `FOR SHARE`) to the query.
41
41
  *
42
42
  * @param {string} mode
43
43
  * @returns {this} this
44
44
  */
45
- rowLock(mode) {
45
+ rowLock(mode, opts = {}) {
46
46
  if (!["FOR_UPDATE", "FOR_SHARE"].includes(mode)) {
47
47
  throw new Error(`Invalid lock mode: ${mode}`);
48
48
  }
49
- this.$state.set("ROW_LEVEL_LOCK", mode);
49
+ if (opts.skipLocked && opts.nowait) {
50
+ throw new Error("Cannot use skipLocked and nowait together");
51
+ }
52
+ this.$state.set("ROW_LEVEL_LOCK", {
53
+ mode,
54
+ skipLocked: !!opts.skipLocked,
55
+ nowait: !!opts.nowait
56
+ });
57
+ return this;
58
+ }
59
+ /**
60
+ * The 'forUpdate' method is used to applies a row-level exclusive lock (`FOR UPDATE`) to the query.
61
+ *
62
+ * This lock prevents other transactions from modifying or acquiring
63
+ * conflicting locks on the selected rows until the current transaction
64
+ * is committed or rolled back.
65
+ *
66
+ * Commonly used in queue systems or critical sections to safely
67
+ * select and update rows without race conditions.
68
+ *
69
+ * @param {Object} [opts] - Locking options
70
+ * @param {boolean} [opts.skipLocked=false] - If true, skips rows that are already locked by other transactions.
71
+ * Useful for building non-blocking workers (e.g., job queues).
72
+ * @param {boolean} [opts.nowait=false] - If true, throws an error immediately if the lock cannot be acquired.
73
+ *
74
+ * @throws {Error} If both `skipLocked` and `nowait` are enabled at the same time.
75
+ *
76
+ * @returns {this} Returns the query builder instance for chaining.
77
+ */
78
+ forUpdate(opts = {}) {
79
+ if (opts.skipLocked && opts.nowait) {
80
+ throw new Error("Cannot use skipLocked and nowait together");
81
+ }
82
+ this.$state.set("ROW_LEVEL_LOCK", {
83
+ mode: 'FOR_UPDATE',
84
+ skipLocked: !!opts.skipLocked,
85
+ nowait: !!opts.nowait
86
+ });
87
+ return this;
88
+ }
89
+ /**
90
+ * The 'forShare' method is used to applies a row-level exclusive lock (`FOR SHARE`) to the query.
91
+ *
92
+ * This lock prevents other transactions from modifying or acquiring
93
+ * conflicting locks on the selected rows until the current transaction
94
+ * is committed or rolled back.
95
+ *
96
+ * Commonly used in queue systems or critical sections to safely
97
+ * select and update rows without race conditions.
98
+ *
99
+ * @param {Object} [opts] - Locking options
100
+ * @param {boolean} [opts.skipLocked=false] - If true, skips rows that are already locked by other transactions.
101
+ * Useful for building non-blocking workers (e.g., job queues).
102
+ * @param {boolean} [opts.nowait=false] - If true, throws an error immediately if the lock cannot be acquired.
103
+ *
104
+ * @throws {Error} If both `skipLocked` and `nowait` are enabled at the same time.
105
+ *
106
+ * @returns {this} Returns the query builder instance for chaining.
107
+ */
108
+ forShare(opts = {}) {
109
+ if (opts.skipLocked && opts.nowait) {
110
+ throw new Error("Cannot use skipLocked and nowait together");
111
+ }
112
+ this.$state.set("ROW_LEVEL_LOCK", {
113
+ mode: 'FOR_SHARE',
114
+ skipLocked: !!opts.skipLocked,
115
+ nowait: !!opts.nowait
116
+ });
50
117
  return this;
51
118
  }
52
119
  /**
@@ -155,8 +222,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
155
222
  return column;
156
223
  if (column.includes("`*`"))
157
224
  return column.replace("`*`", "*");
158
- if (column.includes(this.$constants("RAW")))
159
- return column?.replace(this.$constants("RAW"), "").replace(/'/g, "");
225
+ if (column.includes(this.$constants("RAW"))) {
226
+ return column?.replace(this.$constants("RAW"), "");
227
+ }
160
228
  return column;
161
229
  });
162
230
  select = [...this.$state.get("SELECT"), ...select];
@@ -321,7 +389,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
321
389
  */
322
390
  sleep(second) {
323
391
  this.CTEs('sleep', (query) => {
324
- return query.selectRaw(this._queryBuilder().sleep(second)).from('');
392
+ return query
393
+ .selectRaw(`${this._queryBuilder().sleep(second)} ${this.$constants("AS")} delay`)
394
+ .from(null);
325
395
  });
326
396
  this.from(this.$state.get("TABLE_NAME"), {
327
397
  push: [`${this.$constants("RAW")}sleep`]
@@ -389,8 +459,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
389
459
  return this.whereObject(column);
390
460
  }
391
461
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
392
- value = this.$utils.escape(value);
393
- value = this.$utils.transfromBooleanToNumber(value);
394
462
  if (value === null) {
395
463
  return this.whereNull(column);
396
464
  }
@@ -399,12 +467,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
399
467
  }
400
468
  this.$state.set("WHERE", [
401
469
  ...this.$state.get("WHERE"),
402
- [
403
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
404
- `${this.bindColumn(String(column))}`,
405
- `${operator}`,
406
- `${this.$utils.transfromValueHasRaw(value)}`,
407
- ].join(" "),
470
+ {
471
+ column: this.bindColumn(String(column)),
472
+ operator: operator,
473
+ value: this.$utils.formatQueryValue(value),
474
+ }
408
475
  ]);
409
476
  return this;
410
477
  }
@@ -421,8 +488,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
421
488
  */
422
489
  orWhere(column, operator, value) {
423
490
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
424
- value = this.$utils.escape(value);
425
- value = this.$utils.transfromBooleanToNumber(value);
426
491
  if (value === null) {
427
492
  return this.orWhereNull(column);
428
493
  }
@@ -431,12 +496,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
431
496
  }
432
497
  this.$state.set("WHERE", [
433
498
  ...this.$state.get("WHERE"),
434
- [
435
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
436
- `${this.bindColumn(String(column))}`,
437
- `${operator}`,
438
- `${this.$utils.transfromValueHasRaw(value)}`,
439
- ].join(" "),
499
+ {
500
+ column: this.bindColumn(String(column)),
501
+ operator: operator,
502
+ value: this.$utils.formatQueryValue(value),
503
+ condition: 'OR'
504
+ }
440
505
  ]);
441
506
  return this;
442
507
  }
@@ -451,12 +516,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
451
516
  whereDay(column, day) {
452
517
  this.$state.set("WHERE", [
453
518
  ...this.$state.get("WHERE"),
454
- [
455
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
456
- `DAY(${this.bindColumn(String(column))})`,
457
- `=`,
458
- `'${`00${this.$utils.escape(day)}`.slice(-2)}'`,
459
- ].join(" "),
519
+ {
520
+ column: `DAY(${this.bindColumn(String(column))})`,
521
+ operator: '=',
522
+ value: `'${`00${this.$utils.escape(day)}`.slice(-2)}'`,
523
+ }
460
524
  ]);
461
525
  return this;
462
526
  }
@@ -471,12 +535,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
471
535
  whereMonth(column, month) {
472
536
  this.$state.set("WHERE", [
473
537
  ...this.$state.get("WHERE"),
474
- [
475
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
476
- `MONTH(${this.bindColumn(String(column))})`,
477
- `=`,
478
- `'${`00${this.$utils.escape(month)}`.slice(-2)}'`,
479
- ].join(" "),
538
+ {
539
+ column: `MONTH(${this.bindColumn(String(column))})`,
540
+ operator: '=',
541
+ value: `'${`00${this.$utils.formatQueryValue(month)}`.slice(-2)}'`,
542
+ }
480
543
  ]);
481
544
  return this;
482
545
  }
@@ -491,12 +554,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
491
554
  whereYear(column, year) {
492
555
  this.$state.set("WHERE", [
493
556
  ...this.$state.get("WHERE"),
494
- [
495
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
496
- `YEAR(${this.bindColumn(String(column))})`,
497
- `=`,
498
- `'${`0000${this.$utils.escape(year)}`.slice(-4)}'`,
499
- ].join(" "),
557
+ {
558
+ column: `YEAR(${this.bindColumn(String(column))})`,
559
+ operator: '=',
560
+ value: `'${`0000${this.$utils.formatQueryValue(year)}`.slice(-2)}'`,
561
+ }
500
562
  ]);
501
563
  return this;
502
564
  }
@@ -511,10 +573,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
511
573
  whereRaw(sql) {
512
574
  this.$state.set("WHERE", [
513
575
  ...this.$state.get("WHERE"),
514
- [
515
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
516
- `${sql}`,
517
- ].join(" "),
576
+ {
577
+ value: sql,
578
+ }
518
579
  ]);
519
580
  return this;
520
581
  }
@@ -529,10 +590,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
529
590
  orWhereRaw(sql) {
530
591
  this.$state.set("WHERE", [
531
592
  ...this.$state.get("WHERE"),
532
- [
533
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
534
- `${sql}`,
535
- ].join(" "),
593
+ {
594
+ value: sql,
595
+ condition: 'OR'
596
+ }
536
597
  ]);
537
598
  return this;
538
599
  }
@@ -618,16 +679,13 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
618
679
  * @returns {this}
619
680
  */
620
681
  whereJSON(column, { key, value, operator }) {
621
- value = this.$utils.escape(value);
622
- value = this.$utils.transfromBooleanToNumber(value);
623
682
  this.$state.set("WHERE", [
624
683
  ...this.$state.get("WHERE"),
625
- [
626
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
627
- `${this.bindColumn(column)}->>'$.${key}'`,
628
- `${operator == null ? "=" : operator.toLocaleUpperCase()}`,
629
- `${this.$utils.transfromValueHasRaw(value)}`,
630
- ].join(" "),
684
+ {
685
+ column: `${this.bindColumn(String(column))}->>'$.${key}'`,
686
+ operator: `${operator == null ? "=" : operator.toLocaleUpperCase()}`,
687
+ value: `${this.$utils.formatQueryValue(value)}`
688
+ }
631
689
  ]);
632
690
  return this;
633
691
  }
@@ -654,13 +712,14 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
654
712
  * @returns {this}
655
713
  */
656
714
  whereExists(sql) {
715
+ if (sql instanceof Builder && !sql.$state.get("SELECT").length) {
716
+ sql.select1();
717
+ }
657
718
  this.$state.set("WHERE", [
658
719
  ...this.$state.get("WHERE"),
659
- [
660
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
661
- `${this.$constants("EXISTS")}`,
662
- `(${sql})`,
663
- ].join(" "),
720
+ {
721
+ value: `${this.$constants("EXISTS")} (${sql})`
722
+ }
664
723
  ]);
665
724
  return this;
666
725
  }
@@ -675,11 +734,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
675
734
  whereNotExists(sql) {
676
735
  this.$state.set("WHERE", [
677
736
  ...this.$state.get("WHERE"),
678
- [
679
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
680
- `${this.$constants("NOT")} ${this.$constants("EXISTS")}`,
681
- `(${sql})`,
682
- ].join(" "),
737
+ {
738
+ value: `${this.$constants("NOT")} ${this.$constants("EXISTS")} (${sql})`
739
+ }
683
740
  ]);
684
741
  return this;
685
742
  }
@@ -694,11 +751,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
694
751
  orWhereExists(sql) {
695
752
  this.$state.set("WHERE", [
696
753
  ...this.$state.get("WHERE"),
697
- [
698
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
699
- `${this.$constants("EXISTS")}`,
700
- `(${sql})`,
701
- ].join(" "),
754
+ {
755
+ value: `${this.$constants("EXISTS")} (${sql})`,
756
+ condition: 'OR'
757
+ }
702
758
  ]);
703
759
  return this;
704
760
  }
@@ -713,11 +769,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
713
769
  orWhereNotExists(sql) {
714
770
  this.$state.set("WHERE", [
715
771
  ...this.$state.get("WHERE"),
716
- [
717
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
718
- `${this.$constants("NOT")} ${this.$constants("EXISTS")}`,
719
- `(${sql})`,
720
- ].join(" "),
772
+ {
773
+ value: `${this.$constants("NOT")} ${this.$constants("EXISTS")} (${sql})`,
774
+ condition: 'OR'
775
+ }
721
776
  ]);
722
777
  return this;
723
778
  }
@@ -729,10 +784,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
729
784
  whereId(id, column = "id") {
730
785
  this.$state.set("WHERE", [
731
786
  ...this.$state.get("WHERE"),
732
- [
733
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
734
- `${this.bindColumn(column)} = ${this.$utils.escape(id)}`,
735
- ].join(" "),
787
+ {
788
+ column: this.bindColumn(String(column)),
789
+ operator: '=',
790
+ value: this.$utils.escape(id),
791
+ }
736
792
  ]);
737
793
  return this;
738
794
  }
@@ -745,10 +801,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
745
801
  const column = "email";
746
802
  this.$state.set("WHERE", [
747
803
  ...this.$state.get("WHERE"),
748
- [
749
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
750
- `${this.bindColumn(column)} = ${this.$utils.escape(email)}`,
751
- ].join(" "),
804
+ {
805
+ column: this.bindColumn(String(column)),
806
+ operator: '=',
807
+ value: this.$utils.escape(email),
808
+ }
752
809
  ]);
753
810
  return this;
754
811
  }
@@ -761,10 +818,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
761
818
  whereUser(userId, column = "user_id") {
762
819
  this.$state.set("WHERE", [
763
820
  ...this.$state.get("WHERE"),
764
- [
765
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
766
- `${this.bindColumn(column)} = ${this.$utils.escape(userId)}`,
767
- ].join(" "),
821
+ {
822
+ column: this.bindColumn(String(column)),
823
+ operator: '=',
824
+ value: this.$utils.escape(userId),
825
+ }
768
826
  ]);
769
827
  return this;
770
828
  }
@@ -779,19 +837,19 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
779
837
  whereIn(column, array) {
780
838
  if (!Array.isArray(array))
781
839
  array = [array];
782
- const values = array.length
783
- ? `${array
784
- .map((value) => this.$utils.transfromValueHasRaw(this.$utils.escape(value)))
785
- .join(",")}`
786
- : this.$constants(this.$constants("NULL"));
840
+ if (!array.length) {
841
+ array = [DB_1.DB.raw(this.$constants("NULL"))];
842
+ }
787
843
  this.$state.set("WHERE", [
788
844
  ...this.$state.get("WHERE"),
789
- [
790
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
791
- `${this.bindColumn(column)}`,
792
- `${this.$constants("IN")}`,
793
- `(${values})`,
794
- ].join(" "),
845
+ {
846
+ column: this.bindColumn(String(column)),
847
+ operator: `${this.$constants("IN")}`,
848
+ value: array
849
+ .map((value) => {
850
+ return this.$utils.formatQueryValue(value);
851
+ })
852
+ }
795
853
  ]);
796
854
  return this;
797
855
  }
@@ -806,19 +864,20 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
806
864
  orWhereIn(column, array) {
807
865
  if (!Array.isArray(array))
808
866
  array = [array];
809
- const values = array.length
810
- ? `${array
811
- .map((value) => this.$utils.transfromValueHasRaw(this.$utils.escape(value)))
812
- .join(",")}`
813
- : this.$constants(this.$constants("NULL"));
867
+ if (!array.length) {
868
+ array = [DB_1.DB.raw(this.$constants("NULL"))];
869
+ }
814
870
  this.$state.set("WHERE", [
815
871
  ...this.$state.get("WHERE"),
816
- [
817
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
818
- `${this.bindColumn(column)}`,
819
- `${this.$constants("IN")}`,
820
- `(${values})`,
821
- ].join(" "),
872
+ {
873
+ column: this.bindColumn(String(column)),
874
+ operator: `${this.$constants("IN")}`,
875
+ condition: 'OR',
876
+ value: array
877
+ .map((value) => {
878
+ return this.$utils.formatQueryValue(value);
879
+ })
880
+ }
822
881
  ]);
823
882
  return this;
824
883
  }
@@ -833,19 +892,16 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
833
892
  whereNotIn(column, array) {
834
893
  if (!Array.isArray(array))
835
894
  array = [array];
836
- const values = array.length
837
- ? `${array
838
- .map((value) => this.$utils.transfromValueHasRaw(this.$utils.escape(value)))
839
- .join(",")}`
840
- : this.$constants(this.$constants("NULL"));
841
895
  this.$state.set("WHERE", [
842
896
  ...this.$state.get("WHERE"),
843
- [
844
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
845
- `${this.bindColumn(column)}`,
846
- `${this.$constants("NOT_IN")}`,
847
- `(${values})`,
848
- ].join(" "),
897
+ {
898
+ column: this.bindColumn(String(column)),
899
+ operator: `${this.$constants("NOT_IN")}`,
900
+ value: array
901
+ .map((value) => {
902
+ return this.$utils.formatQueryValue(value);
903
+ })
904
+ }
849
905
  ]);
850
906
  return this;
851
907
  }
@@ -860,19 +916,17 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
860
916
  orWhereNotIn(column, array) {
861
917
  if (!Array.isArray(array))
862
918
  array = [array];
863
- const values = array.length
864
- ? `${array
865
- .map((value) => this.$utils.transfromValueHasRaw(this.$utils.escape(value)))
866
- .join(",")}`
867
- : this.$constants(this.$constants("NULL"));
868
919
  this.$state.set("WHERE", [
869
920
  ...this.$state.get("WHERE"),
870
- [
871
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
872
- `${this.bindColumn(column)}`,
873
- `${this.$constants("NOT_IN")}`,
874
- `(${values})`,
875
- ].join(" "),
921
+ {
922
+ column: this.bindColumn(String(column)),
923
+ operator: `${this.$constants("IN")}`,
924
+ condition: 'OR',
925
+ value: array
926
+ .map((value) => {
927
+ return this.$utils.formatQueryValue(value);
928
+ })
929
+ }
876
930
  ]);
877
931
  return this;
878
932
  }
@@ -892,12 +946,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
892
946
  }
893
947
  this.$state.set("WHERE", [
894
948
  ...this.$state.get("WHERE"),
895
- [
896
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
897
- `${this.bindColumn(column)}`,
898
- options.operator,
899
- `(${subQuery})`,
900
- ].join(" "),
949
+ {
950
+ column: this.bindColumn(String(column)),
951
+ operator: options.operator,
952
+ value: `(${subQuery})`
953
+ }
901
954
  ]);
902
955
  return this;
903
956
  }
@@ -917,13 +970,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
917
970
  }
918
971
  this.$state.set("WHERE", [
919
972
  ...this.$state.get("WHERE"),
920
- [
921
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
922
- `${this.bindColumn(column)}`,
923
- options.operator,
924
- ,
925
- `(${subQuery})`,
926
- ].join(" "),
973
+ {
974
+ column: this.bindColumn(String(column)),
975
+ operator: options.operator,
976
+ value: `(${subQuery})`
977
+ }
927
978
  ]);
928
979
  return this;
929
980
  }
@@ -943,12 +994,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
943
994
  }
944
995
  this.$state.set("WHERE", [
945
996
  ...this.$state.get("WHERE"),
946
- [
947
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
948
- `${this.bindColumn(column)}`,
949
- options.operator,
950
- `(${subQuery})`,
951
- ].join(" "),
997
+ {
998
+ column: this.bindColumn(String(column)),
999
+ operator: options.operator,
1000
+ condition: 'OR',
1001
+ value: `(${subQuery})`
1002
+ }
952
1003
  ]);
953
1004
  return this;
954
1005
  }
@@ -968,12 +1019,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
968
1019
  }
969
1020
  this.$state.set("WHERE", [
970
1021
  ...this.$state.get("WHERE"),
971
- [
972
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
973
- `${this.bindColumn(column)}`,
974
- options.operator,
975
- `(${subQuery})`,
976
- ].join(" "),
1022
+ {
1023
+ column: this.bindColumn(String(column)),
1024
+ operator: options.operator,
1025
+ condition: 'OR',
1026
+ value: `(${subQuery})`
1027
+ }
977
1028
  ]);
978
1029
  return this;
979
1030
  }
@@ -987,30 +1038,20 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
987
1038
  */
988
1039
  whereBetween(column, array) {
989
1040
  if (!array.length) {
990
- this.$state.set("WHERE", [
991
- ...this.$state.get("WHERE"),
992
- [
993
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
994
- `${this.bindColumn(column)}`,
995
- `${this.$constants("BETWEEN")}`,
996
- `${this.$constants(this.$constants("NULL"))}`,
997
- `${this.$constants("AND")}`,
998
- `${this.$constants(this.$constants("NULL"))}`,
999
- ].join(" "),
1000
- ]);
1001
- return this;
1041
+ return this.whereBetween(column, [DB_1.DB.raw('NULL'), DB_1.DB.raw('NULL')]);
1002
1042
  }
1003
1043
  const [value1, value2] = array;
1004
1044
  this.$state.set("WHERE", [
1005
1045
  ...this.$state.get("WHERE"),
1006
- [
1007
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1008
- `${this.bindColumn(column)}`,
1009
- `${this.$constants("BETWEEN")}`,
1010
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1011
- `${this.$constants("AND")}`,
1012
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1013
- ].join(" "),
1046
+ {
1047
+ column: this.bindColumn(String(column)),
1048
+ operator: `${this.$constants("BETWEEN")}`,
1049
+ value: [
1050
+ `${this.$utils.formatQueryValue(value1)}`,
1051
+ `${this.$constants("AND")}`,
1052
+ `${this.$utils.formatQueryValue(value2)}`,
1053
+ ].join(" ")
1054
+ }
1014
1055
  ]);
1015
1056
  return this;
1016
1057
  }
@@ -1024,30 +1065,21 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1024
1065
  */
1025
1066
  orWhereBetween(column, array) {
1026
1067
  if (!array.length) {
1027
- this.$state.set("WHERE", [
1028
- ...this.$state.get("WHERE"),
1029
- [
1030
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1031
- `${this.bindColumn(column)}`,
1032
- `${this.$constants("BETWEEN")}`,
1033
- `${this.$constants(this.$constants("NULL"))}`,
1034
- `${this.$constants("AND")}`,
1035
- `${this.$constants(this.$constants("NULL"))}`,
1036
- ].join(" "),
1037
- ]);
1038
- return this;
1068
+ return this.orWhereBetween(column, ['NULL', 'NULL']);
1039
1069
  }
1040
1070
  const [value1, value2] = array;
1041
1071
  this.$state.set("WHERE", [
1042
1072
  ...this.$state.get("WHERE"),
1043
- [
1044
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1045
- `${this.bindColumn(column)}`,
1046
- `${this.$constants("BETWEEN")}`,
1047
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1048
- `${this.$constants("AND")}`,
1049
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1050
- ].join(" "),
1073
+ {
1074
+ column: this.bindColumn(String(column)),
1075
+ operator: `${this.$constants("BETWEEN")}`,
1076
+ condition: 'OR',
1077
+ value: [
1078
+ `${this.$utils.formatQueryValue(value1)}`,
1079
+ `${this.$constants("AND")}`,
1080
+ `${this.$utils.formatQueryValue(value2)}`,
1081
+ ].join(" ")
1082
+ }
1051
1083
  ]);
1052
1084
  return this;
1053
1085
  }
@@ -1063,30 +1095,20 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1063
1095
  if (!Array.isArray(array))
1064
1096
  throw new Error("Value is't array");
1065
1097
  if (!array.length) {
1066
- this.$state.set("WHERE", [
1067
- ...this.$state.get("WHERE"),
1068
- [
1069
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1070
- `${this.bindColumn(column)}`,
1071
- `${this.$constants("NOT_BETWEEN")}`,
1072
- `${this.$constants(this.$constants("NULL"))}`,
1073
- `${this.$constants("AND")}`,
1074
- `${this.$constants(this.$constants("NULL"))}`,
1075
- ].join(" "),
1076
- ]);
1077
- return this;
1098
+ return this.whereNotBetween(column, ['NULL', 'NULL']);
1078
1099
  }
1079
1100
  const [value1, value2] = array;
1080
1101
  this.$state.set("WHERE", [
1081
1102
  ...this.$state.get("WHERE"),
1082
- [
1083
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1084
- `${this.bindColumn(column)}`,
1085
- `${this.$constants("NOT_BETWEEN")}`,
1086
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1087
- `${this.$constants("AND")}`,
1088
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1089
- ].join(" "),
1103
+ {
1104
+ column: this.bindColumn(String(column)),
1105
+ operator: `${this.$constants("NOT_BETWEEN")}`,
1106
+ value: [
1107
+ `${this.$utils.formatQueryValue(value1)}`,
1108
+ `${this.$constants("AND")}`,
1109
+ `${this.$utils.formatQueryValue(value2)}`,
1110
+ ].join(" ")
1111
+ }
1090
1112
  ]);
1091
1113
  return this;
1092
1114
  }
@@ -1102,30 +1124,21 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1102
1124
  if (!Array.isArray(array))
1103
1125
  throw new Error("Value is't array");
1104
1126
  if (!array.length) {
1105
- this.$state.set("WHERE", [
1106
- ...this.$state.get("WHERE"),
1107
- [
1108
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1109
- `${this.bindColumn(column)}`,
1110
- `${this.$constants("NOT_BETWEEN")}`,
1111
- `${this.$constants(this.$constants("NULL"))}`,
1112
- `${this.$constants("AND")}`,
1113
- `${this.$constants(this.$constants("NULL"))}`,
1114
- ].join(" "),
1115
- ]);
1116
- return this;
1127
+ return this.orWhereNotBetween(column, ['NULL', 'NULL']);
1117
1128
  }
1118
1129
  const [value1, value2] = array;
1119
1130
  this.$state.set("WHERE", [
1120
1131
  ...this.$state.get("WHERE"),
1121
- [
1122
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1123
- `${this.bindColumn(column)}`,
1124
- `${this.$constants("NOT_BETWEEN")}`,
1125
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1126
- `${this.$constants("AND")}`,
1127
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1128
- ].join(" "),
1132
+ {
1133
+ column: this.bindColumn(String(column)),
1134
+ operator: `${this.$constants("NOT_BETWEEN")}`,
1135
+ condition: 'OR',
1136
+ value: [
1137
+ `${this.$utils.formatQueryValue(value1)}`,
1138
+ `${this.$constants("AND")}`,
1139
+ `${this.$utils.formatQueryValue(value2)}`,
1140
+ ].join(" ")
1141
+ }
1129
1142
  ]);
1130
1143
  return this;
1131
1144
  }
@@ -1139,11 +1152,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1139
1152
  whereNull(column) {
1140
1153
  this.$state.set("WHERE", [
1141
1154
  ...this.$state.get("WHERE"),
1142
- [
1143
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1144
- `${this.bindColumn(column)}`,
1145
- `${this.$constants("IS_NULL")}`,
1146
- ].join(" "),
1155
+ {
1156
+ column: this.bindColumn(String(column)),
1157
+ operator: `${this.$constants("IS_NULL")}`,
1158
+ }
1147
1159
  ]);
1148
1160
  return this;
1149
1161
  }
@@ -1157,11 +1169,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1157
1169
  orWhereNull(column) {
1158
1170
  this.$state.set("WHERE", [
1159
1171
  ...this.$state.get("WHERE"),
1160
- [
1161
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1162
- `${this.bindColumn(column)}`,
1163
- `${this.$constants("IS_NULL")}`,
1164
- ].join(" "),
1172
+ {
1173
+ column: this.bindColumn(String(column)),
1174
+ operator: `${this.$constants("IS_NULL")}`,
1175
+ condition: 'OR'
1176
+ }
1165
1177
  ]);
1166
1178
  return this;
1167
1179
  }
@@ -1175,11 +1187,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1175
1187
  whereNotNull(column) {
1176
1188
  this.$state.set("WHERE", [
1177
1189
  ...this.$state.get("WHERE"),
1178
- [
1179
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1180
- `${this.bindColumn(column)}`,
1181
- `${this.$constants("IS_NOT_NULL")}`,
1182
- ].join(" "),
1190
+ {
1191
+ column: this.bindColumn(String(column)),
1192
+ operator: `${this.$constants("IS_NOT_NULL")}`,
1193
+ }
1183
1194
  ]);
1184
1195
  return this;
1185
1196
  }
@@ -1193,11 +1204,10 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1193
1204
  orWhereNotNull(column) {
1194
1205
  this.$state.set("WHERE", [
1195
1206
  ...this.$state.get("WHERE"),
1196
- [
1197
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1198
- `${this.bindColumn(column)}`,
1199
- `${this.$constants("IS_NOT_NULL")}`,
1200
- ].join(" "),
1207
+ {
1208
+ column: this.bindColumn(String(column)),
1209
+ operator: `${this.$constants("IS_NOT_NULL")}`,
1210
+ }
1201
1211
  ]);
1202
1212
  return this;
1203
1213
  }
@@ -1214,17 +1224,13 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1214
1224
  */
1215
1225
  whereSensitive(column, operator, value) {
1216
1226
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
1217
- value = this.$utils.escape(value);
1218
- value = this.$utils.transfromBooleanToNumber(value);
1219
1227
  this.$state.set("WHERE", [
1220
1228
  ...this.$state.get("WHERE"),
1221
- [
1222
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1223
- `${this.$constants("BINARY")}`,
1224
- `${this.bindColumn(column)}`,
1225
- `${operator}`,
1226
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value))}`,
1227
- ].join(" "),
1229
+ {
1230
+ column: `${this.$constants("BINARY")} ${this.bindColumn(String(column))}`,
1231
+ operator: `${this.$constants("IS_NULL")}`,
1232
+ value: `${this.$utils.formatQueryValue(value)}`,
1233
+ }
1228
1234
  ]);
1229
1235
  return this;
1230
1236
  }
@@ -1255,17 +1261,14 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1255
1261
  */
1256
1262
  orWhereSensitive(column, operator, value) {
1257
1263
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
1258
- value = this.$utils.escape(value);
1259
- value = this.$utils.transfromBooleanToNumber(value);
1260
1264
  this.$state.set("WHERE", [
1261
1265
  ...this.$state.get("WHERE"),
1262
- [
1263
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1264
- `${this.$constants("BINARY")}`,
1265
- `${this.bindColumn(column)}`,
1266
- `${operator}`,
1267
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value))}`,
1268
- ].join(" "),
1266
+ {
1267
+ column: `${this.$constants("BINARY")} ${this.bindColumn(String(column))}`,
1268
+ operator,
1269
+ condition: 'OR',
1270
+ value: `${this.$utils.formatQueryValue(value)}`,
1271
+ }
1269
1272
  ]);
1270
1273
  return this;
1271
1274
  }
@@ -1289,10 +1292,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1289
1292
  const query = where.join(" ");
1290
1293
  this.$state.set("WHERE", [
1291
1294
  ...this.$state.get("WHERE"),
1292
- [
1293
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1294
- `(${query})`,
1295
- ].join(" "),
1295
+ ...where
1296
1296
  ]);
1297
1297
  return this;
1298
1298
  }
@@ -1323,13 +1323,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1323
1323
  const where = repository?.$state.get("WHERE") || [];
1324
1324
  if (!where.length)
1325
1325
  return this;
1326
- const query = where.join(" ");
1327
1326
  this.$state.set("WHERE", [
1328
1327
  ...this.$state.get("WHERE"),
1329
- [
1330
- this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1331
- `(${query})`,
1332
- ].join(" "),
1328
+ ...where
1333
1329
  ]);
1334
1330
  return this;
1335
1331
  }
@@ -1355,8 +1351,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1355
1351
  */
1356
1352
  whereAny(columns, operator, value) {
1357
1353
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
1358
- value = this.$utils.escape(value);
1359
- value = this.$utils.transfromBooleanToNumber(value);
1360
1354
  this.whereQuery((query) => {
1361
1355
  for (const index in columns) {
1362
1356
  const column = columns[index];
@@ -1383,8 +1377,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1383
1377
  */
1384
1378
  whereAll(columns, operator, value) {
1385
1379
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
1386
- value = this.$utils.escape(value);
1387
- value = this.$utils.transfromBooleanToNumber(value);
1388
1380
  this.whereQuery((query) => {
1389
1381
  for (const column of columns)
1390
1382
  query.where(column, operator, value);
@@ -1412,7 +1404,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1412
1404
  return `${this.$constants("WHEN")} ${when} ${this.$constants("THEN")} ${then}`;
1413
1405
  });
1414
1406
  const whereClause = [
1415
- this.$state.get("WHERE").length ? this.$constants("AND") : "",
1416
1407
  "(",
1417
1408
  this.$constants("CASE"),
1418
1409
  ...query,
@@ -1422,7 +1413,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1422
1413
  ]
1423
1414
  .filter(Boolean)
1424
1415
  .join(" ");
1425
- this.$state.set("WHERE", [...this.$state.get("WHERE"), whereClause]);
1416
+ this.whereRaw(whereClause);
1426
1417
  return this;
1427
1418
  }
1428
1419
  /**
@@ -1445,7 +1436,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1445
1436
  return `${this.$constants("WHEN")} ${when} ${this.$constants("THEN")} ${then}`;
1446
1437
  });
1447
1438
  const whereClause = [
1448
- this.$state.get("WHERE").length ? this.$constants("OR") : "",
1449
1439
  "(",
1450
1440
  this.$constants("CASE"),
1451
1441
  ...query,
@@ -1455,17 +1445,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1455
1445
  ]
1456
1446
  .filter(Boolean)
1457
1447
  .join(" ");
1458
- this.$state.set("WHERE", [...this.$state.get("WHERE"), whereClause]);
1448
+ this.orWhereRaw(whereClause);
1459
1449
  return this;
1460
1450
  }
1461
1451
  whereReference(tableAndLocalKey, tableAndForeignKey) {
1462
- this.$state.set("WHERE", [
1463
- ...this.$state.get("WHERE"),
1464
- [
1465
- this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1466
- `${tableAndLocalKey} = ${tableAndForeignKey}`,
1467
- ].join(" "),
1468
- ]);
1452
+ this.whereRaw(`${tableAndLocalKey} = ${tableAndForeignKey}`);
1469
1453
  return this;
1470
1454
  }
1471
1455
  /**
@@ -1613,10 +1597,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1613
1597
  ...this.$state.get("ORDER_BY"),
1614
1598
  `${orderBy} ${order.toUpperCase()}`,
1615
1599
  ]);
1616
- this.$state.set("ORDER_BY", [
1617
- ...this.$state.get("ORDER_BY"),
1618
- `\`${column}\` ${order.toUpperCase()}`,
1619
- ]);
1620
1600
  return this;
1621
1601
  }
1622
1602
  /**
@@ -2364,11 +2344,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2364
2344
  *
2365
2345
  */
2366
2346
  async getFKs(table) {
2367
- const sql = this._queryBuilder().getFKs({
2347
+ const fks = await this.rawQuery(this._queryBuilder().getFKs({
2368
2348
  database: this.$database,
2369
2349
  table: table ?? String(this.$state.get("TABLE_NAME")),
2370
- });
2371
- return await this.rawQuery(sql);
2350
+ }));
2351
+ return fks;
2372
2352
  }
2373
2353
  /**
2374
2354
  * The `hasFK` method is used to determine whether a specific foreign key
@@ -2381,12 +2361,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2381
2361
  *
2382
2362
  */
2383
2363
  async hasFK({ constraint, table }) {
2384
- const sql = this._queryBuilder().hasFK({
2364
+ const result = await this.rawQuery(this._queryBuilder().hasFK({
2385
2365
  database: this.$database,
2386
2366
  table: table ?? String(this.$state.get("TABLE_NAME")),
2387
2367
  constraint
2388
- });
2389
- const result = await this.rawQuery(sql);
2368
+ }));
2390
2369
  return Boolean(result[0]?.IS_EXISTS ?? false);
2391
2370
  }
2392
2371
  /**
@@ -2405,11 +2384,49 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2405
2384
  *
2406
2385
  */
2407
2386
  async getChildFKs(table) {
2408
- const sql = this._queryBuilder().getChildFKs({
2387
+ const childFks = await this.rawQuery(this._queryBuilder().getChildFKs({
2409
2388
  database: this.$database,
2410
2389
  table: table ?? String(this.$state.get("TABLE_NAME")),
2411
- });
2412
- return await this.rawQuery(sql);
2390
+ }));
2391
+ return childFks;
2392
+ }
2393
+ /**
2394
+ * Adds a foreign key constraint to a table.
2395
+ *
2396
+ * This method checks whether the specified foreign key constraint already exists
2397
+ * on the table before attempting to create it. If the constraint exists, an error
2398
+ * will be thrown to prevent duplication.
2399
+ *
2400
+ * @async
2401
+ * @method addFK
2402
+ * @param {Object} params - Parameters for creating the foreign key.
2403
+ * @param {string} params.table - The name of the table where the foreign key will be added.
2404
+ * @param {string} params.tableRef - The referenced table name.
2405
+ * @param {string} params.key - The column in the current table that will act as the foreign key.
2406
+ * @param {string} params.constraint - The name of the foreign key constraint.
2407
+ * @param {Object} params.foreign - Foreign key configuration.
2408
+ * @param {string} params.foreign.references - The referenced column in the referenced table.
2409
+ * @param {string} params.foreign.onDelete - Action when a referenced row is deleted (e.g. CASCADE, SET NULL).
2410
+ * @param {string} params.foreign.onUpdate - Action when a referenced row is updated (e.g. CASCADE, RESTRICT).
2411
+ *
2412
+ * @throws {Error} If the specified foreign key constraint already exists.
2413
+ *
2414
+ * @returns {Promise<void>} Resolves when the foreign key constraint is successfully created.
2415
+ */
2416
+ async addFK({ table, tableRef, key, constraint, foreign }) {
2417
+ const exists = await this.hasFK({ constraint, table });
2418
+ if (exists) {
2419
+ throw new Error('The specified foreign key constraint already exists.');
2420
+ }
2421
+ await this.rawQuery(this._queryBuilder()
2422
+ .addFK({
2423
+ table: table ?? this.getTableName(),
2424
+ tableRef,
2425
+ key,
2426
+ constraint,
2427
+ foreign
2428
+ }));
2429
+ return;
2413
2430
  }
2414
2431
  /**
2415
2432
  * The `dropFK` method is used to remove a foreign key constraint from the database.
@@ -2422,11 +2439,15 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2422
2439
  * @returns {Promise<void>}
2423
2440
  */
2424
2441
  async dropFK({ constraint, table }) {
2425
- const sql = this._queryBuilder().dropFK({
2426
- table: table ?? String(this.$state.get("TABLE_NAME")),
2442
+ const exists = await this.hasFK({ constraint, table });
2443
+ if (!exists) {
2444
+ throw new Error('The specified foreign key constraint was not found.');
2445
+ }
2446
+ await this.rawQuery(this._queryBuilder()
2447
+ .dropFK({
2448
+ table: table ?? this.getTableName(),
2427
2449
  constraint
2428
- });
2429
- await this.rawQuery(sql);
2450
+ }));
2430
2451
  return;
2431
2452
  }
2432
2453
  /**
@@ -2445,11 +2466,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2445
2466
  *
2446
2467
  */
2447
2468
  async getIndexes(table) {
2448
- const sql = this._queryBuilder().getIndexes({
2469
+ const indexes = await this.rawQuery(this._queryBuilder().getIndexes({
2449
2470
  database: this.$database,
2450
- table: table ?? String(this.$state.get("TABLE_NAME")),
2451
- });
2452
- return await this.rawQuery(sql);
2471
+ table: table ?? this.getTableName()
2472
+ }));
2473
+ return indexes;
2453
2474
  }
2454
2475
  /**
2455
2476
  * The `hasIndex` method is used to determine whether a specific index exists
@@ -2461,15 +2482,226 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2461
2482
  * @returns {Promise<boolean>}
2462
2483
  *
2463
2484
  */
2464
- async hasIndex({ index, table }) {
2465
- const sql = this._queryBuilder().hasIndex({
2485
+ async hasIndex({ name, table }) {
2486
+ const result = await this.rawQuery(this._queryBuilder().hasIndex({
2466
2487
  database: this.$database,
2467
- table: table ?? String(this.$state.get("TABLE_NAME")),
2468
- index
2469
- });
2470
- const result = await this.rawQuery(sql);
2488
+ table: table ?? this.getTableName(),
2489
+ name
2490
+ }));
2491
+ return Boolean(result[0]?.IS_EXISTS ?? false);
2492
+ }
2493
+ /**
2494
+ * Adds an index to a table.
2495
+ *
2496
+ * This method checks whether the specified index already exists on the table
2497
+ * before attempting to create it. If the index exists, an error will be thrown
2498
+ * to prevent duplication.
2499
+ *
2500
+ * @async
2501
+ * @method addIndex
2502
+ * @param {Object} params - Parameters for creating the index.
2503
+ * @param {string} params.name - The name of the index.
2504
+ * @param {string} [params.table] - The table where the index will be created. Defaults to the current model table.
2505
+ * @param {string[]} params.columns - The columns included in the index.
2506
+ *
2507
+ * @throws {Error} If the specified index already exists.
2508
+ *
2509
+ * @returns {Promise<void>} Resolves when the index has been successfully created.
2510
+ */
2511
+ async addIndex({ name, table, columns }) {
2512
+ const exists = await this.hasIndex({ name, table });
2513
+ if (exists) {
2514
+ throw new Error('The specified index already exists.');
2515
+ }
2516
+ await this.rawQuery(this._queryBuilder().addIndex({
2517
+ table: table ?? this.getTableName(),
2518
+ name,
2519
+ columns
2520
+ }));
2521
+ return;
2522
+ }
2523
+ /**
2524
+ * Drops an index from a table.
2525
+ *
2526
+ * This method checks whether the specified index exists on the table
2527
+ * before attempting to drop it. If the index does not exist, an error
2528
+ * will be thrown.
2529
+ *
2530
+ * @async
2531
+ * @method dropIndex
2532
+ * @param {Object} params - Parameters for dropping the index.
2533
+ * @param {string} params.name - The name of the index to drop.
2534
+ * @param {string} [params.table] - The table from which the index will be removed. Defaults to the current model table.
2535
+ *
2536
+ * @throws {Error} If the specified index was not found.
2537
+ *
2538
+ * @returns {Promise<void>} Resolves when the index has been successfully dropped.
2539
+ */
2540
+ async dropIndex({ name, table }) {
2541
+ const exists = await this.hasIndex({ name, table });
2542
+ if (!exists) {
2543
+ throw new Error('The specified index was not found');
2544
+ }
2545
+ await this.rawQuery(this._queryBuilder().dropIndex({
2546
+ table: table ?? this.getTableName(),
2547
+ name,
2548
+ }));
2549
+ return;
2550
+ }
2551
+ /**
2552
+ * Checks whether a unique constraint exists on a table.
2553
+ *
2554
+ * This method queries the database metadata to determine if the specified
2555
+ * unique constraint exists on the given table.
2556
+ *
2557
+ * @async
2558
+ * @method hasUnique
2559
+ * @param {Object} params - Parameters for checking the unique constraint.
2560
+ * @param {string} params.name - The name of the unique constraint.
2561
+ * @param {string} [params.table] - The table to check. Defaults to the current model table.
2562
+ *
2563
+ * @returns {Promise<boolean>} Returns `true` if the unique constraint exists, otherwise `false`.
2564
+ */
2565
+ async hasUnique({ name, table }) {
2566
+ const result = await this.rawQuery(this._queryBuilder().hasUnique({
2567
+ database: this.$database,
2568
+ table: table ?? this.getTableName(),
2569
+ name
2570
+ }));
2471
2571
  return Boolean(result[0]?.IS_EXISTS ?? false);
2472
2572
  }
2573
+ /**
2574
+ * Adds a unique constraint to a table.
2575
+ *
2576
+ * This method checks whether the specified unique constraint already exists
2577
+ * on the table before attempting to create it. If the constraint already exists,
2578
+ * an error will be thrown to prevent duplication.
2579
+ *
2580
+ * @async
2581
+ * @method addUnique
2582
+ * @param {Object} params - Parameters for creating the unique constraint.
2583
+ * @param {string} params.name - The name of the unique constraint.
2584
+ * @param {string} [params.table] - The table where the unique constraint will be added. Defaults to the current model table.
2585
+ * @param {string[]} params.columns - The columns that will be included in the unique constraint.
2586
+ *
2587
+ * @throws {Error} If the specified unique constraint already exists.
2588
+ *
2589
+ * @returns {Promise<void>} Resolves when the unique constraint has been successfully created.
2590
+ */
2591
+ async addUnique({ name, table, columns }) {
2592
+ const exists = await this.hasUnique({ name, table });
2593
+ if (exists) {
2594
+ throw new Error('The specified unique constraint already exists.');
2595
+ }
2596
+ await this.rawQuery(this._queryBuilder().addUnique({
2597
+ table: table ?? this.getTableName(),
2598
+ name,
2599
+ columns
2600
+ }));
2601
+ return;
2602
+ }
2603
+ /**
2604
+ * Drops a unique constraint from a table.
2605
+ *
2606
+ * This method checks whether the specified unique constraint exists
2607
+ * on the table before attempting to remove it. If the constraint does
2608
+ * not exist, an error will be thrown.
2609
+ *
2610
+ * @async
2611
+ * @method dropUnique
2612
+ * @param {Object} params - Parameters for dropping the unique constraint.
2613
+ * @param {string} params.name - The name of the unique constraint to drop.
2614
+ * @param {string} [params.table] - The table from which the unique constraint will be removed. Defaults to the current model table.
2615
+ *
2616
+ * @throws {Error} If the specified unique constraint was not found.
2617
+ *
2618
+ * @returns {Promise<void>} Resolves when the unique constraint has been successfully dropped.
2619
+ */
2620
+ async dropUnique({ name, table }) {
2621
+ const exists = await this.hasUnique({ name, table });
2622
+ if (!exists) {
2623
+ throw new Error('The specified unique constraint was not found.');
2624
+ }
2625
+ await this.rawQuery(this._queryBuilder().dropUnique({
2626
+ table: table ?? this.getTableName(),
2627
+ name,
2628
+ }));
2629
+ return;
2630
+ }
2631
+ /**
2632
+ * Checks whether a primary key constraint exists on a table.
2633
+ *
2634
+ * This method queries the database metadata to determine if the specified
2635
+ * table contains a primary key constraint.
2636
+ *
2637
+ * @async
2638
+ * @method hasPrimaryKey
2639
+ * @param {Object} [params={}] - Parameters for checking the primary key.
2640
+ * @param {string} [params.table] - The table to check. Defaults to the current model table.
2641
+ *
2642
+ * @returns {Promise<boolean>} Returns `true` if the table has a primary key constraint,
2643
+ * otherwise `false`.
2644
+ */
2645
+ async hasPrimaryKey({ table } = {}) {
2646
+ const result = await this.rawQuery(this._queryBuilder().hasPrimaryKey({
2647
+ database: this.$database,
2648
+ table: table ?? this.getTableName()
2649
+ }));
2650
+ return Boolean(result[0]?.IS_EXISTS ?? false);
2651
+ }
2652
+ /**
2653
+ * Adds a primary key constraint to a table.
2654
+ *
2655
+ * This method checks whether the table already has a primary key
2656
+ * before attempting to create one. If a primary key already exists,
2657
+ * an error will be thrown.
2658
+ *
2659
+ * @async
2660
+ * @method addPrimaryKey
2661
+ * @param {Object} params - Parameters for creating the primary key.
2662
+ * @param {string} [params.table] - The table where the primary key will be added. Defaults to the current model table.
2663
+ * @param {string[]} params.columns - The column(s) that will form the primary key.
2664
+ *
2665
+ * @throws {Error} If the table already has a primary key constraint.
2666
+ *
2667
+ * @returns {Promise<void>} Resolves when the primary key has been successfully created.
2668
+ */
2669
+ async addPrimaryKey({ table, columns }) {
2670
+ const exists = await this.hasPrimaryKey({ table });
2671
+ if (exists) {
2672
+ throw new Error('The specified primary constraint already exists.');
2673
+ }
2674
+ await this.rawQuery(this._queryBuilder().addPrimaryKey({
2675
+ table: table ?? String(this.getTableName()),
2676
+ columns
2677
+ }));
2678
+ return;
2679
+ }
2680
+ /**
2681
+ * Drops the primary key constraint from a table.
2682
+ *
2683
+ * This method checks whether the table has a primary key before
2684
+ * attempting to remove it. If no primary key exists, an error will be thrown.
2685
+ *
2686
+ * @async
2687
+ * @method dropPrimaryKey
2688
+ * @param {Object} [params={}] - Parameters for dropping the primary key.
2689
+ * @param {string} [params.table] - The table from which the primary key will be removed. Defaults to the current model table.
2690
+ *
2691
+ * @throws {Error} If the specified primary key constraint was not found.
2692
+ *
2693
+ * @returns {Promise<void>} Resolves when the primary key constraint has been successfully removed.
2694
+ */
2695
+ async dropPrimaryKey({ table } = {}) {
2696
+ const exists = await this.hasPrimaryKey({ table });
2697
+ if (!exists) {
2698
+ throw new Error('The specified primary constraint was not found.');
2699
+ }
2700
+ await this.rawQuery(this._queryBuilder().dropPrimaryKey({
2701
+ table: table ?? String(this.getTableName())
2702
+ }));
2703
+ return;
2704
+ }
2473
2705
  /**
2474
2706
  * The 'bindColumn' method is used to concat table and column -> `users`.`id`
2475
2707
  * @param {string} column
@@ -2683,11 +2915,11 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2683
2915
  * The 'find' method is used to retrieve a single record from a database table by its primary key.
2684
2916
  *
2685
2917
  * This method allows you to quickly fetch a specific record by specifying the primary key value, which is typically an integer id.
2686
- * @param {number} id
2918
+ * @param {number | string} primaryKey
2687
2919
  * @returns {promise<any>}
2688
2920
  */
2689
- async find(id) {
2690
- this.where("id", id);
2921
+ async find(primaryKey) {
2922
+ this.where("id", primaryKey);
2691
2923
  return await this.first();
2692
2924
  }
2693
2925
  /**
@@ -2717,7 +2949,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2717
2949
  const result = await this._queryStatement(sql);
2718
2950
  if (!result.length)
2719
2951
  return {
2720
- //@ts-ignore
2721
2952
  meta: {
2722
2953
  total: 0,
2723
2954
  limit,
@@ -2726,6 +2957,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2726
2957
  last_page: 0,
2727
2958
  next_page: 0,
2728
2959
  prev_page: 0,
2960
+ page: {
2961
+ prev: 0,
2962
+ next: 0,
2963
+ current: currentPage,
2964
+ last: 0,
2965
+ },
2729
2966
  },
2730
2967
  data: [],
2731
2968
  };
@@ -2739,7 +2976,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2739
2976
  lastPage = lastPage > 1 ? lastPage : 1;
2740
2977
  const count = result?.length ?? 0;
2741
2978
  return {
2742
- //@ts-ignore
2743
2979
  meta: {
2744
2980
  total: total,
2745
2981
  limit: limit,
@@ -2748,6 +2984,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
2748
2984
  last_page: lastPage,
2749
2985
  next_page: nextPage,
2750
2986
  prev_page: prevPage,
2987
+ page: {
2988
+ prev: prevPage,
2989
+ next: nextPage,
2990
+ current: currentPage,
2991
+ last: lastPage,
2992
+ },
2751
2993
  },
2752
2994
  data: result ?? [],
2753
2995
  };
@@ -3264,6 +3506,18 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3264
3506
  .map((table) => String(Object.values(table)[0]))
3265
3507
  .filter((d) => d != null || d !== "");
3266
3508
  }
3509
+ /**
3510
+ * The `getTable` method is used to retrieve a list of all table names
3511
+ * in the current database.
3512
+ *
3513
+ * @returns {Promise<string[]>} A promise that resolves to an array of table names.
3514
+ *
3515
+ * @async
3516
+ */
3517
+ async hasTable(table) {
3518
+ const result = await this._queryStatement(this._queryBuilder().hasTable({ database: this.database(), table }));
3519
+ return Boolean(result[0]?.IS_EXISTS ?? false);
3520
+ }
3267
3521
  /**
3268
3522
  *
3269
3523
  * The 'showColumns' method is used to show columns table.
@@ -3388,10 +3642,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3388
3642
  ].join('\n'));
3389
3643
  return false;
3390
3644
  }
3391
- const sql = [
3392
- `${this.$constants("TRUNCATE_TABLE")}`,
3393
- `${table}`,
3394
- ].join(" ");
3645
+ const sql = this._queryBuilder().truncate(this.getTableName());
3395
3646
  if (!force) {
3396
3647
  console.log([
3397
3648
  `\x1b[33m`,
@@ -3402,7 +3653,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3402
3653
  ].join('\n'));
3403
3654
  return false;
3404
3655
  }
3405
- const childFKs = await this.getChildFKs();
3656
+ const childFKs = await this.getChildFKs().catch(() => []);
3406
3657
  if (childFKs.length && !dropFK) {
3407
3658
  console.log([
3408
3659
  `\x1b[33m`,
@@ -3609,7 +3860,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3609
3860
  await this.$utils.wait(this.$state.get("AFTER_SAVE"));
3610
3861
  const data = await new Builder()
3611
3862
  .copyBuilder(this, { select: true })
3612
- .whereIn("id", result.$meta.insertIds)
3863
+ .whereIn(this.$state.get('PRIMARY_KEY'), result.$meta.insertIds)
3864
+ .debug(this.$state.get('DEBUG'))
3613
3865
  .bind(this.$pool.get())
3614
3866
  .first();
3615
3867
  return this._resultHandler(data);
@@ -3625,7 +3877,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3625
3877
  await this.$utils.wait(this.$state.get("AFTER_SAVE"));
3626
3878
  const results = await new Builder()
3627
3879
  .copyBuilder(this, { select: true })
3628
- .whereIn("id", result.$meta.insertIds)
3880
+ .whereIn(this.$state.get('PRIMARY_KEY'), result.$meta.insertIds)
3881
+ .debug(this.$state.get('DEBUG'))
3629
3882
  .bind(this.$pool.get())
3630
3883
  .first();
3631
3884
  return this._resultHandler(results);
@@ -3637,7 +3890,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3637
3890
  await this.$utils.wait(this.$state.get("AFTER_SAVE"));
3638
3891
  const resultData = await new Builder()
3639
3892
  .copyBuilder(this, { select: true, limit: true })
3640
- .whereIn("id", result.$meta.insertIds)
3893
+ .whereIn(this.$state.get('PRIMARY_KEY'), result.$meta.insertIds)
3894
+ .debug(this.$state.get('DEBUG'))
3641
3895
  .bind(this.$pool.get())
3642
3896
  .get();
3643
3897
  return this._resultHandler(resultData);
@@ -3663,7 +3917,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3663
3917
  await this.$utils.wait(this.$state.get("AFTER_SAVE"));
3664
3918
  const data = await new Builder()
3665
3919
  .copyBuilder(this, { select: true })
3666
- .whereIn("id", result.$meta.insertIds)
3920
+ .whereIn(this.$state.get('PRIMARY_KEY'), result.$meta.insertIds)
3921
+ .debug(this.$state.get('DEBUG'))
3667
3922
  .bind(this.$pool.get())
3668
3923
  .first();
3669
3924
  const resultData = data == null ? null : { ...data, $action: "insert" };
@@ -3709,7 +3964,8 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3709
3964
  await this.$utils.wait(this.$state.get("AFTER_SAVE"));
3710
3965
  const data = await new Builder()
3711
3966
  .copyBuilder(this, { select: true })
3712
- .whereIn("id", result.$meta.insertIds)
3967
+ .whereIn(this.$state.get('PRIMARY_KEY'), result.$meta.insertIds)
3968
+ .debug(this.$state.get('DEBUG'))
3713
3969
  .bind(this.$pool.get())
3714
3970
  .first();
3715
3971
  const resultData = data == null ? null : { ...data, $action: "insert" };
@@ -3865,7 +4121,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3865
4121
  const isReaded = [
3866
4122
  this.$constants("SELECT"),
3867
4123
  this.$constants("SHOW"),
3868
- this.$constants("DESCRIBE"),
4124
+ this.$constants("DESCRIBE")
3869
4125
  ].includes(first) &&
3870
4126
  (!sql
3871
4127
  .toUpperCase()
@@ -3903,10 +4159,16 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3903
4159
  ? poolCluster?.queryBuilder
3904
4160
  : poolCluster?.masters[0]?.queryBuilder;
3905
4161
  },
4162
+ transaction: async () => {
4163
+ return await poolCluster.masters[0].connection();
4164
+ },
3906
4165
  };
3907
4166
  }
3908
4167
  let pool = Pool_1.Pool.connect();
3909
4168
  return {
4169
+ transaction: async () => {
4170
+ return await pool.connection();
4171
+ },
3910
4172
  query: async (sql) => {
3911
4173
  return pool.query(sql);
3912
4174
  },
@@ -3922,13 +4184,14 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3922
4184
  };
3923
4185
  })();
3924
4186
  this.$state = new StateManager_1.StateManager("default");
3925
- this.$constants = (name) => {
4187
+ this.$constants = ((name) => {
3926
4188
  if (name == null)
3927
4189
  return constants_1.CONSTANTS;
3928
- if (!constants_1.CONSTANTS.hasOwnProperty(name))
3929
- throw new Error(`Not found that constant : '${name}'`);
4190
+ if (!Object.prototype.hasOwnProperty.call(constants_1.CONSTANTS, name)) {
4191
+ throw new Error(`Not found that constant : '${String(name)}'`);
4192
+ }
3930
4193
  return constants_1.CONSTANTS[name];
3931
- };
4194
+ });
3932
4195
  }
3933
4196
  }
3934
4197
  exports.Builder = Builder;