tspace-mysql 1.9.0-beta.4 → 1.9.0-beta.6

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.
@@ -1,9 +1,12 @@
1
1
  import Builder from '../Builder';
2
- import type { TPoolConnected, TConnectionOptions, TConnectionTransaction } from '../../types';
2
+ import type { TPoolConnected, TConnectionOptions, TConnectionTransaction, TConnection, TPoolEvent } from '../../types';
3
3
  declare abstract class AbstractDB extends Builder {
4
4
  abstract beginTransaction(): Promise<TConnectionTransaction>;
5
+ abstract transaction<T>(handler: (conn: TConnection) => Promise<T>): Promise<T>;
5
6
  abstract generateUUID(): string;
6
7
  abstract raw(sql: string): string;
8
+ abstract query(sql: string, parameters: Record<string, any>): Promise<any>;
9
+ abstract event(event: TPoolEvent, callback: (data: any) => any): Promise<void>;
7
10
  abstract escape(sql: string): string;
8
11
  abstract escapeXSS(sql: string): string;
9
12
  abstract snakeCase(sql: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractDB.js","sourceRoot":"","sources":["../../../../src/lib/core/Abstracts/AbstractDB.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAmC;AAOnC,MAAe,UAAW,SAAQ,iBAAO;CAcxC;AAEQ,gCAAU;AACnB,kBAAe,UAAU,CAAA"}
1
+ {"version":3,"file":"AbstractDB.js","sourceRoot":"","sources":["../../../../src/lib/core/Abstracts/AbstractDB.ts"],"names":[],"mappings":";;;;;;AAAA,yDAAmC;AASnC,MAAe,UAAW,SAAQ,iBAAO;CAiBxC;AAEQ,gCAAU;AACnB,kBAAe,UAAU,CAAA"}
@@ -3,7 +3,7 @@ import { DB } from "./DB";
3
3
  import { Join } from "./Join";
4
4
  import { CONSTANTS } from "../constants";
5
5
  import { QueryBuilder } from "./Driver";
6
- import { TPagination, TConnectionOptions, TPoolConnected, TConnectionTransaction } from "../types";
6
+ import { TPagination, TConnectionOptions, TPoolConnected, TConnectionTransaction, TDriver } from "../types";
7
7
  declare class Builder extends AbstractBuilder {
8
8
  constructor();
9
9
  /**
@@ -14,9 +14,9 @@ declare class Builder extends AbstractBuilder {
14
14
  static get instance(): Builder;
15
15
  /**
16
16
  * The 'driver' method is used to get current driver
17
- * @returns {string} driver
17
+ * @returns {TDriver} driver
18
18
  */
19
- driver(): string;
19
+ driver(): TDriver;
20
20
  /**
21
21
  * The 'database' method is used to get current database
22
22
  * @returns {string} database
@@ -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;
@@ -459,8 +459,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
459
459
  return this.whereObject(column);
460
460
  }
461
461
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
462
- value = this.$utils.escape(value);
463
- value = this.$utils.transfromBooleanToNumber(value);
464
462
  if (value === null) {
465
463
  return this.whereNull(column);
466
464
  }
@@ -472,7 +470,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
472
470
  {
473
471
  column: this.bindColumn(String(column)),
474
472
  operator: operator,
475
- value: this.$utils.transfromValueHasRaw(value),
473
+ value: this.$utils.formatQueryValue(value),
476
474
  }
477
475
  ]);
478
476
  return this;
@@ -490,29 +488,18 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
490
488
  */
491
489
  orWhere(column, operator, value) {
492
490
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
493
- value = this.$utils.escape(value);
494
- value = this.$utils.transfromBooleanToNumber(value);
495
491
  if (value === null) {
496
492
  return this.orWhereNull(column);
497
493
  }
498
494
  if (Array.isArray(value)) {
499
495
  return this.orWhereIn(column, value);
500
496
  }
501
- // this.$state.set("WHERE", [
502
- // ...this.$state.get("WHERE"),
503
- // [
504
- // this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
505
- // `${this.bindColumn(String(column))}`,
506
- // `${operator}`,
507
- // `${this.$utils.transfromValueHasRaw(value)}`,
508
- // ].join(" "),
509
- // ]);
510
497
  this.$state.set("WHERE", [
511
498
  ...this.$state.get("WHERE"),
512
499
  {
513
500
  column: this.bindColumn(String(column)),
514
501
  operator: operator,
515
- value: this.$utils.transfromValueHasRaw(value),
502
+ value: this.$utils.formatQueryValue(value),
516
503
  condition: 'OR'
517
504
  }
518
505
  ]);
@@ -546,21 +533,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
546
533
  * @returns {this}
547
534
  */
548
535
  whereMonth(column, month) {
549
- // this.$state.set("WHERE", [
550
- // ...this.$state.get("WHERE"),
551
- // [
552
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
553
- // `MONTH(${this.bindColumn(String(column))})`,
554
- // `=`,
555
- // `'${`00${this.$utils.escape(month)}`.slice(-2)}'`,
556
- // ].join(" "),
557
- // ]);
558
536
  this.$state.set("WHERE", [
559
537
  ...this.$state.get("WHERE"),
560
538
  {
561
539
  column: `MONTH(${this.bindColumn(String(column))})`,
562
540
  operator: '=',
563
- value: `'${`00${this.$utils.escape(month)}`.slice(-2)}'`,
541
+ value: `'${`00${this.$utils.formatQueryValue(month)}`.slice(-2)}'`,
564
542
  }
565
543
  ]);
566
544
  return this;
@@ -574,21 +552,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
574
552
  * @returns {this}
575
553
  */
576
554
  whereYear(column, year) {
577
- // this.$state.set("WHERE", [
578
- // ...this.$state.get("WHERE"),
579
- // [
580
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
581
- // `YEAR(${this.bindColumn(String(column))})`,
582
- // `=`,
583
- // `'${`0000${this.$utils.escape(year)}`.slice(-4)}'`,
584
- // ].join(" "),
585
- // ]);
586
555
  this.$state.set("WHERE", [
587
556
  ...this.$state.get("WHERE"),
588
557
  {
589
558
  column: `YEAR(${this.bindColumn(String(column))})`,
590
559
  operator: '=',
591
- value: `'${`0000${this.$utils.escape(year)}`.slice(-2)}'`,
560
+ value: `'${`0000${this.$utils.formatQueryValue(year)}`.slice(-2)}'`,
592
561
  }
593
562
  ]);
594
563
  return this;
@@ -710,23 +679,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
710
679
  * @returns {this}
711
680
  */
712
681
  whereJSON(column, { key, value, operator }) {
713
- value = this.$utils.escape(value);
714
- value = this.$utils.transfromBooleanToNumber(value);
715
- // this.$state.set("WHERE", [
716
- // ...this.$state.get("WHERE"),
717
- // [
718
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
719
- // `${this.bindColumn(column)}->>'$.${key}'`,
720
- // `${operator == null ? "=" : operator.toLocaleUpperCase()}`,
721
- // `${this.$utils.transfromValueHasRaw(value)}`,
722
- // ].join(" "),
723
- // ]);
724
682
  this.$state.set("WHERE", [
725
683
  ...this.$state.get("WHERE"),
726
684
  {
727
685
  column: `${this.bindColumn(String(column))}->>'$.${key}'`,
728
686
  operator: `${operator == null ? "=" : operator.toLocaleUpperCase()}`,
729
- value: `${this.$utils.transfromValueHasRaw(value)}`
687
+ value: `${this.$utils.formatQueryValue(value)}`
730
688
  }
731
689
  ]);
732
690
  return this;
@@ -754,14 +712,15 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
754
712
  * @returns {this}
755
713
  */
756
714
  whereExists(sql) {
757
- // this.$state.set("WHERE", [
758
- // ...this.$state.get("WHERE"),
759
- // [
760
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
761
- // `${this.$constants("EXISTS")}`,
762
- // `(${sql})`,
763
- // ].join(" "),
764
- // ]);
715
+ if (sql instanceof Builder && !sql.$state.get("SELECT").length) {
716
+ sql.select1();
717
+ }
718
+ this.$state.set("WHERE", [
719
+ ...this.$state.get("WHERE"),
720
+ {
721
+ value: `${this.$constants("EXISTS")} (${sql})`
722
+ }
723
+ ]);
765
724
  return this;
766
725
  }
767
726
  /**
@@ -878,11 +837,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
878
837
  whereIn(column, array) {
879
838
  if (!Array.isArray(array))
880
839
  array = [array];
881
- const values = array.length
882
- ? `${array
883
- .map((value) => this.$utils.transfromValueHasRaw(this.$utils.escape(value)))
884
- .join(",")}`
885
- : this.$constants(this.$constants("NULL"));
840
+ if (!array.length) {
841
+ array = [DB_1.DB.raw(this.$constants("NULL"))];
842
+ }
886
843
  this.$state.set("WHERE", [
887
844
  ...this.$state.get("WHERE"),
888
845
  {
@@ -890,7 +847,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
890
847
  operator: `${this.$constants("IN")}`,
891
848
  value: array
892
849
  .map((value) => {
893
- return this.$utils.transfromValueHasRaw(this.$utils.escape(value));
850
+ return this.$utils.formatQueryValue(value);
894
851
  })
895
852
  }
896
853
  ]);
@@ -907,11 +864,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
907
864
  orWhereIn(column, array) {
908
865
  if (!Array.isArray(array))
909
866
  array = [array];
910
- const values = array.length
911
- ? `${array
912
- .map((value) => this.$utils.transfromValueHasRaw(this.$utils.escape(value)))
913
- .join(",")}`
914
- : this.$constants(this.$constants("NULL"));
867
+ if (!array.length) {
868
+ array = [DB_1.DB.raw(this.$constants("NULL"))];
869
+ }
915
870
  this.$state.set("WHERE", [
916
871
  ...this.$state.get("WHERE"),
917
872
  {
@@ -920,7 +875,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
920
875
  condition: 'OR',
921
876
  value: array
922
877
  .map((value) => {
923
- return this.$utils.transfromValueHasRaw(this.$utils.escape(value));
878
+ return this.$utils.formatQueryValue(value);
924
879
  })
925
880
  }
926
881
  ]);
@@ -937,20 +892,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
937
892
  whereNotIn(column, array) {
938
893
  if (!Array.isArray(array))
939
894
  array = [array];
940
- const values = array.length
941
- ? `${array
942
- .map((value) => this.$utils.transfromValueHasRaw(this.$utils.escape(value)))
943
- .join(",")}`
944
- : this.$constants(this.$constants("NULL"));
945
- // this.$state.set("WHERE", [
946
- // ...this.$state.get("WHERE"),
947
- // [
948
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
949
- // `${this.bindColumn(column)}`,
950
- // `${this.$constants("NOT_IN")}`,
951
- // `(${values})`,
952
- // ].join(" "),
953
- // ]);
954
895
  this.$state.set("WHERE", [
955
896
  ...this.$state.get("WHERE"),
956
897
  {
@@ -958,7 +899,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
958
899
  operator: `${this.$constants("NOT_IN")}`,
959
900
  value: array
960
901
  .map((value) => {
961
- return this.$utils.transfromValueHasRaw(this.$utils.escape(value));
902
+ return this.$utils.formatQueryValue(value);
962
903
  })
963
904
  }
964
905
  ]);
@@ -975,20 +916,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
975
916
  orWhereNotIn(column, array) {
976
917
  if (!Array.isArray(array))
977
918
  array = [array];
978
- const values = array.length
979
- ? `${array
980
- .map((value) => this.$utils.transfromValueHasRaw(this.$utils.escape(value)))
981
- .join(",")}`
982
- : this.$constants(this.$constants("NULL"));
983
- // this.$state.set("WHERE", [
984
- // ...this.$state.get("WHERE"),
985
- // [
986
- // this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
987
- // `${this.bindColumn(column)}`,
988
- // `${this.$constants("NOT_IN")}`,
989
- // `(${values})`,
990
- // ].join(" "),
991
- // ]);
992
919
  this.$state.set("WHERE", [
993
920
  ...this.$state.get("WHERE"),
994
921
  {
@@ -997,7 +924,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
997
924
  condition: 'OR',
998
925
  value: array
999
926
  .map((value) => {
1000
- return this.$utils.transfromValueHasRaw(this.$utils.escape(value));
927
+ return this.$utils.formatQueryValue(value);
1001
928
  })
1002
929
  }
1003
930
  ]);
@@ -1017,15 +944,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1017
944
  if (subQuery instanceof Builder && !subQuery.$state.get("SELECT").length) {
1018
945
  subQuery.select("id");
1019
946
  }
1020
- // this.$state.set("WHERE", [
1021
- // ...this.$state.get("WHERE"),
1022
- // [
1023
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1024
- // `${this.bindColumn(column)}`,
1025
- // options.operator,
1026
- // `(${subQuery})`,
1027
- // ].join(" "),
1028
- // ]);
1029
947
  this.$state.set("WHERE", [
1030
948
  ...this.$state.get("WHERE"),
1031
949
  {
@@ -1050,16 +968,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1050
968
  if (subQuery instanceof Builder && !subQuery.$state.get("SELECT").length) {
1051
969
  subQuery.select("id");
1052
970
  }
1053
- // this.$state.set("WHERE", [
1054
- // ...this.$state.get("WHERE"),
1055
- // [
1056
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1057
- // `${this.bindColumn(column)}`,
1058
- // options.operator,
1059
- // ,
1060
- // `(${subQuery})`,
1061
- // ].join(" "),
1062
- // ]);
1063
971
  this.$state.set("WHERE", [
1064
972
  ...this.$state.get("WHERE"),
1065
973
  {
@@ -1084,15 +992,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1084
992
  if (subQuery instanceof Builder && !subQuery.$state.get("SELECT").length) {
1085
993
  subQuery.select("id");
1086
994
  }
1087
- // this.$state.set("WHERE", [
1088
- // ...this.$state.get("WHERE"),
1089
- // [
1090
- // this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1091
- // `${this.bindColumn(column)}`,
1092
- // options.operator,
1093
- // `(${subQuery})`,
1094
- // ].join(" "),
1095
- // ]);
1096
995
  this.$state.set("WHERE", [
1097
996
  ...this.$state.get("WHERE"),
1098
997
  {
@@ -1118,15 +1017,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1118
1017
  if (subQuery instanceof Builder && !subQuery.$state.get("SELECT").length) {
1119
1018
  subQuery.select("id");
1120
1019
  }
1121
- // this.$state.set("WHERE", [
1122
- // ...this.$state.get("WHERE"),
1123
- // [
1124
- // this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1125
- // `${this.bindColumn(column)}`,
1126
- // options.operator,
1127
- // `(${subQuery})`,
1128
- // ].join(" "),
1129
- // ]);
1130
1020
  this.$state.set("WHERE", [
1131
1021
  ...this.$state.get("WHERE"),
1132
1022
  {
@@ -1148,29 +1038,18 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1148
1038
  */
1149
1039
  whereBetween(column, array) {
1150
1040
  if (!array.length) {
1151
- return this.whereBetween(column, ['NULL', 'NULL']);
1041
+ return this.whereBetween(column, [DB_1.DB.raw('NULL'), DB_1.DB.raw('NULL')]);
1152
1042
  }
1153
1043
  const [value1, value2] = array;
1154
- // this.$state.set("WHERE", [
1155
- // ...this.$state.get("WHERE"),
1156
- // [
1157
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1158
- // `${this.bindColumn(column)}`,
1159
- // `${this.$constants("BETWEEN")}`,
1160
- // `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1161
- // `${this.$constants("AND")}`,
1162
- // `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1163
- // ].join(" "),
1164
- // ]);
1165
1044
  this.$state.set("WHERE", [
1166
1045
  ...this.$state.get("WHERE"),
1167
1046
  {
1168
1047
  column: this.bindColumn(String(column)),
1169
1048
  operator: `${this.$constants("BETWEEN")}`,
1170
1049
  value: [
1171
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1050
+ `${this.$utils.formatQueryValue(value1)}`,
1172
1051
  `${this.$constants("AND")}`,
1173
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1052
+ `${this.$utils.formatQueryValue(value2)}`,
1174
1053
  ].join(" ")
1175
1054
  }
1176
1055
  ]);
@@ -1196,9 +1075,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1196
1075
  operator: `${this.$constants("BETWEEN")}`,
1197
1076
  condition: 'OR',
1198
1077
  value: [
1199
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1078
+ `${this.$utils.formatQueryValue(value1)}`,
1200
1079
  `${this.$constants("AND")}`,
1201
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1080
+ `${this.$utils.formatQueryValue(value2)}`,
1202
1081
  ].join(" ")
1203
1082
  }
1204
1083
  ]);
@@ -1225,9 +1104,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1225
1104
  column: this.bindColumn(String(column)),
1226
1105
  operator: `${this.$constants("NOT_BETWEEN")}`,
1227
1106
  value: [
1228
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1107
+ `${this.$utils.formatQueryValue(value1)}`,
1229
1108
  `${this.$constants("AND")}`,
1230
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1109
+ `${this.$utils.formatQueryValue(value2)}`,
1231
1110
  ].join(" ")
1232
1111
  }
1233
1112
  ]);
@@ -1255,9 +1134,9 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1255
1134
  operator: `${this.$constants("NOT_BETWEEN")}`,
1256
1135
  condition: 'OR',
1257
1136
  value: [
1258
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value1))}`,
1137
+ `${this.$utils.formatQueryValue(value1)}`,
1259
1138
  `${this.$constants("AND")}`,
1260
- `${this.$utils.transfromValueHasRaw(this.$utils.escape(value2))}`,
1139
+ `${this.$utils.formatQueryValue(value2)}`,
1261
1140
  ].join(" ")
1262
1141
  }
1263
1142
  ]);
@@ -1271,14 +1150,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1271
1150
  * @returns {this}
1272
1151
  */
1273
1152
  whereNull(column) {
1274
- // this.$state.set("WHERE", [
1275
- // ...this.$state.get("WHERE"),
1276
- // [
1277
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1278
- // `${this.bindColumn(column)}`,
1279
- // `${this.$constants("IS_NULL")}`,
1280
- // ].join(" "),
1281
- // ]);
1282
1153
  this.$state.set("WHERE", [
1283
1154
  ...this.$state.get("WHERE"),
1284
1155
  {
@@ -1296,14 +1167,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1296
1167
  * @returns {this}
1297
1168
  */
1298
1169
  orWhereNull(column) {
1299
- // this.$state.set("WHERE", [
1300
- // ...this.$state.get("WHERE"),
1301
- // [
1302
- // this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1303
- // `${this.bindColumn(column)}`,
1304
- // `${this.$constants("IS_NULL")}`,
1305
- // ].join(" "),
1306
- // ]);
1307
1170
  this.$state.set("WHERE", [
1308
1171
  ...this.$state.get("WHERE"),
1309
1172
  {
@@ -1322,14 +1185,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1322
1185
  * @returns {this}
1323
1186
  */
1324
1187
  whereNotNull(column) {
1325
- // this.$state.set("WHERE", [
1326
- // ...this.$state.get("WHERE"),
1327
- // [
1328
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1329
- // `${this.bindColumn(column)}`,
1330
- // `${this.$constants("IS_NOT_NULL")}`,
1331
- // ].join(" "),
1332
- // ]);
1333
1188
  this.$state.set("WHERE", [
1334
1189
  ...this.$state.get("WHERE"),
1335
1190
  {
@@ -1347,14 +1202,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1347
1202
  * @returns {this}
1348
1203
  */
1349
1204
  orWhereNotNull(column) {
1350
- // this.$state.set("WHERE", [
1351
- // ...this.$state.get("WHERE"),
1352
- // [
1353
- // this.$state.get("WHERE").length ? `${this.$constants("OR")}` : "",
1354
- // `${this.bindColumn(column)}`,
1355
- // `${this.$constants("IS_NOT_NULL")}`,
1356
- // ].join(" "),
1357
- // ]);
1358
1205
  this.$state.set("WHERE", [
1359
1206
  ...this.$state.get("WHERE"),
1360
1207
  {
@@ -1377,24 +1224,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1377
1224
  */
1378
1225
  whereSensitive(column, operator, value) {
1379
1226
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
1380
- value = this.$utils.escape(value);
1381
- value = this.$utils.transfromBooleanToNumber(value);
1382
- // this.$state.set("WHERE", [
1383
- // ...this.$state.get("WHERE"),
1384
- // [
1385
- // this.$state.get("WHERE").length ? `${this.$constants("AND")}` : "",
1386
- // `${this.$constants("BINARY")}`,
1387
- // `${this.bindColumn(column)}`,
1388
- // `${operator}`,
1389
- // `${this.$utils.transfromValueHasRaw(this.$utils.escape(value))}`,
1390
- // ].join(" "),
1391
- // ]);
1392
1227
  this.$state.set("WHERE", [
1393
1228
  ...this.$state.get("WHERE"),
1394
1229
  {
1395
1230
  column: `${this.$constants("BINARY")} ${this.bindColumn(String(column))}`,
1396
1231
  operator: `${this.$constants("IS_NULL")}`,
1397
- value: `${this.$utils.transfromValueHasRaw(this.$utils.escape(value))}`,
1232
+ value: `${this.$utils.formatQueryValue(value)}`,
1398
1233
  }
1399
1234
  ]);
1400
1235
  return this;
@@ -1426,15 +1261,13 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1426
1261
  */
1427
1262
  orWhereSensitive(column, operator, value) {
1428
1263
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
1429
- value = this.$utils.escape(value);
1430
- value = this.$utils.transfromBooleanToNumber(value);
1431
1264
  this.$state.set("WHERE", [
1432
1265
  ...this.$state.get("WHERE"),
1433
1266
  {
1434
1267
  column: `${this.$constants("BINARY")} ${this.bindColumn(String(column))}`,
1435
1268
  operator,
1436
1269
  condition: 'OR',
1437
- value: `${this.$utils.transfromValueHasRaw(this.$utils.escape(value))}`,
1270
+ value: `${this.$utils.formatQueryValue(value)}`,
1438
1271
  }
1439
1272
  ]);
1440
1273
  return this;
@@ -1518,8 +1351,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1518
1351
  */
1519
1352
  whereAny(columns, operator, value) {
1520
1353
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
1521
- value = this.$utils.escape(value);
1522
- value = this.$utils.transfromBooleanToNumber(value);
1523
1354
  this.whereQuery((query) => {
1524
1355
  for (const index in columns) {
1525
1356
  const column = columns[index];
@@ -1546,8 +1377,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1546
1377
  */
1547
1378
  whereAll(columns, operator, value) {
1548
1379
  [value, operator] = this.$utils.valueAndOperator(value, operator, arguments.length === 2);
1549
- value = this.$utils.escape(value);
1550
- value = this.$utils.transfromBooleanToNumber(value);
1551
1380
  this.whereQuery((query) => {
1552
1381
  for (const column of columns)
1553
1382
  query.where(column, operator, value);
@@ -1574,18 +1403,17 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1574
1403
  throw new Error(`can't find then condition`);
1575
1404
  return `${this.$constants("WHEN")} ${when} ${this.$constants("THEN")} ${then}`;
1576
1405
  });
1577
- // const whereClause = [
1578
- // this.$state.get("WHERE").length ? this.$constants("AND") : "",
1579
- // "(",
1580
- // this.$constants("CASE"),
1581
- // ...query,
1582
- // elseCase != null ? `ELSE ${elseCase}` : "",
1583
- // this.$constants("END"),
1584
- // ")",
1585
- // ]
1586
- // .filter(Boolean)
1587
- // .join(" ");
1588
- // this.$state.set("WHERE", [...this.$state.get("WHERE"), whereClause]);
1406
+ const whereClause = [
1407
+ "(",
1408
+ this.$constants("CASE"),
1409
+ ...query,
1410
+ elseCase != null ? `ELSE ${elseCase}` : "",
1411
+ this.$constants("END"),
1412
+ ")",
1413
+ ]
1414
+ .filter(Boolean)
1415
+ .join(" ");
1416
+ this.whereRaw(whereClause);
1589
1417
  return this;
1590
1418
  }
1591
1419
  /**
@@ -1608,7 +1436,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1608
1436
  return `${this.$constants("WHEN")} ${when} ${this.$constants("THEN")} ${then}`;
1609
1437
  });
1610
1438
  const whereClause = [
1611
- this.$state.get("WHERE").length ? this.$constants("OR") : "",
1612
1439
  "(",
1613
1440
  this.$constants("CASE"),
1614
1441
  ...query,
@@ -1618,7 +1445,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
1618
1445
  ]
1619
1446
  .filter(Boolean)
1620
1447
  .join(" ");
1621
- // this.$state.set("WHERE", [...this.$state.get("WHERE"), whereClause]);
1448
+ this.orWhereRaw(whereClause);
1622
1449
  return this;
1623
1450
  }
1624
1451
  whereReference(tableAndLocalKey, tableAndForeignKey) {
@@ -3122,7 +2949,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3122
2949
  const result = await this._queryStatement(sql);
3123
2950
  if (!result.length)
3124
2951
  return {
3125
- //@ts-ignore
3126
2952
  meta: {
3127
2953
  total: 0,
3128
2954
  limit,
@@ -3131,6 +2957,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3131
2957
  last_page: 0,
3132
2958
  next_page: 0,
3133
2959
  prev_page: 0,
2960
+ page: {
2961
+ prev: 0,
2962
+ next: 0,
2963
+ current: currentPage,
2964
+ last: 0,
2965
+ },
3134
2966
  },
3135
2967
  data: [],
3136
2968
  };
@@ -3144,7 +2976,6 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3144
2976
  lastPage = lastPage > 1 ? lastPage : 1;
3145
2977
  const count = result?.length ?? 0;
3146
2978
  return {
3147
- //@ts-ignore
3148
2979
  meta: {
3149
2980
  total: total,
3150
2981
  limit: limit,
@@ -3153,6 +2984,12 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
3153
2984
  last_page: lastPage,
3154
2985
  next_page: nextPage,
3155
2986
  prev_page: prevPage,
2987
+ page: {
2988
+ prev: prevPage,
2989
+ next: nextPage,
2990
+ current: currentPage,
2991
+ last: lastPage,
2992
+ },
3156
2993
  },
3157
2994
  data: result ?? [],
3158
2995
  };