tspace-mysql 1.9.0 → 1.9.1-beta.2

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 (118) hide show
  1. package/README.md +4580 -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 +27 -23
  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 +5 -2
  12. package/dist/lib/core/Abstracts/AbstractDB.js.map +1 -1
  13. package/dist/lib/core/Abstracts/AbstractModel.d.ts +7 -2
  14. package/dist/lib/core/Abstracts/AbstractModel.js.map +1 -1
  15. package/dist/lib/core/Abstracts/AbstractView.js.map +1 -1
  16. package/dist/lib/core/Blueprint.d.ts +37 -17
  17. package/dist/lib/core/Blueprint.js +38 -14
  18. package/dist/lib/core/Blueprint.js.map +1 -1
  19. package/dist/lib/core/Builder.d.ts +314 -42
  20. package/dist/lib/core/Builder.js +686 -391
  21. package/dist/lib/core/Builder.js.map +1 -1
  22. package/dist/lib/core/Cache/DBCache.js +19 -20
  23. package/dist/lib/core/Cache/DBCache.js.map +1 -1
  24. package/dist/lib/core/Cache/MemoryCache.js +3 -3
  25. package/dist/lib/core/Cache/MemoryCache.js.map +1 -1
  26. package/dist/lib/core/Cache/RedisCache.js +27 -17
  27. package/dist/lib/core/Cache/RedisCache.js.map +1 -1
  28. package/dist/lib/core/Cache/index.js +37 -17
  29. package/dist/lib/core/Cache/index.js.map +1 -1
  30. package/dist/lib/core/Contracts/AlterTable.d.ts +152 -0
  31. package/dist/lib/core/Contracts/AlterTable.js +243 -0
  32. package/dist/lib/core/Contracts/AlterTable.js.map +1 -0
  33. package/dist/lib/core/Contracts/Audit.d.ts +1 -1
  34. package/dist/lib/core/Contracts/Audit.js +2 -5
  35. package/dist/lib/core/Contracts/Audit.js.map +1 -1
  36. package/dist/lib/core/Contracts/Logger.d.ts +1 -1
  37. package/dist/lib/core/Contracts/Logger.js.map +1 -1
  38. package/dist/lib/core/DB.d.ts +103 -11
  39. package/dist/lib/core/DB.js +158 -32
  40. package/dist/lib/core/DB.js.map +1 -1
  41. package/dist/lib/core/Decorator.d.ts +144 -16
  42. package/dist/lib/core/Decorator.js +156 -14
  43. package/dist/lib/core/Decorator.js.map +1 -1
  44. package/dist/lib/core/Driver/index.d.ts +50 -14
  45. package/dist/lib/core/Driver/index.js +13 -9
  46. package/dist/lib/core/Driver/index.js.map +1 -1
  47. package/dist/lib/core/Driver/mariadb/MariadbDriver.js +84 -29
  48. package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
  49. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +48 -12
  50. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js +189 -28
  51. package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -1
  52. package/dist/lib/core/Driver/mongodb/MongodbDriver.d.ts +24 -0
  53. package/dist/lib/core/Driver/mongodb/MongodbDriver.js +261 -0
  54. package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -0
  55. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.d.ts +141 -0
  56. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js +571 -0
  57. package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js.map +1 -0
  58. package/dist/lib/core/Driver/mysql/MysqlDriver.js +115 -97
  59. package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
  60. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +48 -12
  61. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js +189 -28
  62. package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -1
  63. package/dist/lib/core/Driver/postgres/PostgresDriver.js +106 -73
  64. package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
  65. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +53 -12
  66. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js +318 -48
  67. package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -1
  68. package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +21 -0
  69. package/dist/lib/core/Driver/sqlite/SqliteDriver.js +213 -0
  70. package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -0
  71. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.d.ts +146 -0
  72. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js +705 -0
  73. package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js.map +1 -0
  74. package/dist/lib/core/Join.d.ts +63 -5
  75. package/dist/lib/core/Join.js +92 -15
  76. package/dist/lib/core/Join.js.map +1 -1
  77. package/dist/lib/core/JoinModel.d.ts +65 -9
  78. package/dist/lib/core/JoinModel.js +81 -52
  79. package/dist/lib/core/JoinModel.js.map +1 -1
  80. package/dist/lib/core/Meta.d.ts +22 -16
  81. package/dist/lib/core/Meta.js +28 -21
  82. package/dist/lib/core/Meta.js.map +1 -1
  83. package/dist/lib/core/Model.d.ts +644 -134
  84. package/dist/lib/core/Model.js +1361 -631
  85. package/dist/lib/core/Model.js.map +1 -1
  86. package/dist/lib/{tools/index.d.ts → core/Package.d.ts} +11 -3
  87. package/dist/lib/{tools/index.js → core/Package.js} +20 -7
  88. package/dist/lib/core/Package.js.map +1 -0
  89. package/dist/lib/core/Pool.js +42 -30
  90. package/dist/lib/core/Pool.js.map +1 -1
  91. package/dist/lib/core/Queue.d.ts +249 -0
  92. package/dist/lib/core/Queue.js +726 -0
  93. package/dist/lib/core/Queue.js.map +1 -0
  94. package/dist/lib/core/RelationManager.d.ts +4 -4
  95. package/dist/lib/core/RelationManager.js +168 -41
  96. package/dist/lib/core/RelationManager.js.map +1 -1
  97. package/dist/lib/core/Repository.d.ts +73 -207
  98. package/dist/lib/core/Repository.js +122 -234
  99. package/dist/lib/core/Repository.js.map +1 -1
  100. package/dist/lib/core/Schema.d.ts +211 -1
  101. package/dist/lib/core/Schema.js +370 -65
  102. package/dist/lib/core/Schema.js.map +1 -1
  103. package/dist/lib/core/StateManager.d.ts +31 -12
  104. package/dist/lib/core/StateManager.js +11 -5
  105. package/dist/lib/core/StateManager.js.map +1 -1
  106. package/dist/lib/core/UtilityTypes.d.ts +103 -81
  107. package/dist/lib/core/UtilityTypes.js.map +1 -1
  108. package/dist/lib/core/index.d.ts +4 -0
  109. package/dist/lib/core/index.js +6 -2
  110. package/dist/lib/core/index.js.map +1 -1
  111. package/dist/lib/types/decorator/index.d.ts +1 -1
  112. package/dist/lib/types/index.d.ts +120 -30
  113. package/dist/lib/types/repository/index.d.ts +68 -37
  114. package/dist/lib/utils/index.d.ts +13 -2
  115. package/dist/lib/utils/index.js +81 -2
  116. package/dist/lib/utils/index.js.map +1 -1
  117. package/package.json +14 -6
  118. package/dist/lib/tools/index.js.map +0 -1
@@ -3,8 +3,8 @@ 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";
7
- declare class Builder extends AbstractBuilder {
6
+ import type { TPagination, TConnectionOptions, TPoolConnected, TConnectionTransaction, TDriver, TSaveBuilderResult, TAction } from "../types";
7
+ declare class Builder<TA extends TAction = null> extends AbstractBuilder {
8
8
  constructor();
9
9
  /**
10
10
  * The 'instance' method is used get instance.
@@ -14,21 +14,76 @@ 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
+ * @static
18
+ * @returns {TDriver} driver
19
+ */
20
+ static driver(): TDriver;
21
+ /**
22
+ * The 'driver' method is used to get current driver
23
+ * @returns {TDriver} driver
18
24
  */
19
- driver(): string;
25
+ driver(): TDriver;
20
26
  /**
21
27
  * The 'database' method is used to get current database
22
28
  * @returns {string} database
23
29
  */
24
30
  database(): string;
25
31
  /**
26
- * The 'rowLock' method is used to row level locks
32
+ * The 'rowLock' method is used to row level locks (`FOR UPDATE` or `FOR SHARE`) to the query.
27
33
  *
28
34
  * @param {string} mode
29
35
  * @returns {this} this
30
36
  */
31
- rowLock(mode: "FOR_UPDATE" | "FOR_SHARE"): this;
37
+ rowLock(mode: "FOR_UPDATE" | "FOR_SHARE", opts?: {
38
+ skipLocked?: boolean;
39
+ nowait?: boolean;
40
+ }): this;
41
+ /**
42
+ * The 'forUpdate' method is used to applies a row-level exclusive lock (`FOR UPDATE`) to the query.
43
+ *
44
+ * This lock prevents other transactions from modifying or acquiring
45
+ * conflicting locks on the selected rows until the current transaction
46
+ * is committed or rolled back.
47
+ *
48
+ * Commonly used in queue systems or critical sections to safely
49
+ * select and update rows without race conditions.
50
+ *
51
+ * @param {Object} [opts] - Locking options
52
+ * @param {boolean} [opts.skipLocked=false] - If true, skips rows that are already locked by other transactions.
53
+ * Useful for building non-blocking workers (e.g., job queues).
54
+ * @param {boolean} [opts.nowait=false] - If true, throws an error immediately if the lock cannot be acquired.
55
+ *
56
+ * @throws {Error} If both `skipLocked` and `nowait` are enabled at the same time.
57
+ *
58
+ * @returns {this} Returns the query builder instance for chaining.
59
+ */
60
+ forUpdate(opts?: {
61
+ skipLocked?: boolean;
62
+ nowait?: boolean;
63
+ }): this;
64
+ /**
65
+ * The 'forShare' method is used to applies a row-level exclusive lock (`FOR SHARE`) to the query.
66
+ *
67
+ * This lock prevents other transactions from modifying or acquiring
68
+ * conflicting locks on the selected rows until the current transaction
69
+ * is committed or rolled back.
70
+ *
71
+ * Commonly used in queue systems or critical sections to safely
72
+ * select and update rows without race conditions.
73
+ *
74
+ * @param {Object} [opts] - Locking options
75
+ * @param {boolean} [opts.skipLocked=false] - If true, skips rows that are already locked by other transactions.
76
+ * Useful for building non-blocking workers (e.g., job queues).
77
+ * @param {boolean} [opts.nowait=false] - If true, throws an error immediately if the lock cannot be acquired.
78
+ *
79
+ * @throws {Error} If both `skipLocked` and `nowait` are enabled at the same time.
80
+ *
81
+ * @returns {this} Returns the query builder instance for chaining.
82
+ */
83
+ forShare(opts?: {
84
+ skipLocked?: boolean;
85
+ nowait?: boolean;
86
+ }): this;
32
87
  /**
33
88
  * The 'unset' method is used to drop a property as desired.
34
89
  * @param {object} options
@@ -80,6 +135,14 @@ declare class Builder extends AbstractBuilder {
80
135
  * @returns {this} this
81
136
  */
82
137
  select(...columns: string[]): this;
138
+ /**
139
+ * The 'addSelect' method is used to add columns you want to retrieve from a database table.
140
+ *
141
+ * It allows you to choose the specific columns that should be included in the result set of a database query.
142
+ * @param {string[]} ...columns
143
+ * @returns {this} this
144
+ */
145
+ addSelect(...columns: string[]): this;
83
146
  /**
84
147
  * The 'selectRaw' method is used to specify which columns you want to retrieve from a database table.
85
148
  *
@@ -106,7 +169,7 @@ declare class Builder extends AbstractBuilder {
106
169
  */
107
170
  selectObject(object: Record<string, string | `${string}.${string}`>, alias: string): this;
108
171
  /**
109
- * The 'selectObject' method is used to specify which columns you want to retrieve from a database table.
172
+ * The 'selectArray' method is used to specify which columns you want to retrieve from a database table.
110
173
  *
111
174
  * It allows you to choose the specific columns that should be included in the result set to 'Object' of a database query.
112
175
  * @param {string} object table name
@@ -187,7 +250,7 @@ declare class Builder extends AbstractBuilder {
187
250
  * @param {string | number | undefined | null | Boolean} condition when condition true will return query callback
188
251
  * @returns {this} this
189
252
  */
190
- when(condition: string | number | undefined | null | Boolean, callback: (query: Builder) => Builder): this;
253
+ when(condition: string | number | undefined | null | Boolean, callback: (query: Builder<any>) => Builder): this;
191
254
  /**
192
255
  * The 'where' method is used to add conditions to a database query.
193
256
  *
@@ -247,7 +310,7 @@ declare class Builder extends AbstractBuilder {
247
310
  * @param {string} sql where column with raw sql
248
311
  * @returns {this} this
249
312
  */
250
- whereRaw(sql: string): this;
313
+ whereRaw(sql: string, parameters?: (boolean | number | string | any[] | null)[]): this;
251
314
  /**
252
315
  * The 'orWhereRaw' method is used to add a raw SQL condition to a database query.
253
316
  *
@@ -256,7 +319,7 @@ declare class Builder extends AbstractBuilder {
256
319
  * @param {string} sql where column with raw sql
257
320
  * @returns {this} this
258
321
  */
259
- orWhereRaw(sql: string): this;
322
+ orWhereRaw(sql: string, parameters?: (boolean | number | string | any[] | null)[]): this;
260
323
  /**
261
324
  * The 'whereObject' method is used to add conditions to a database query.
262
325
  *
@@ -847,7 +910,7 @@ declare class Builder extends AbstractBuilder {
847
910
  * @param {array?} updateNotExists options for except update some records in your ${data} using name column(s)
848
911
  * @returns {this} this
849
912
  */
850
- update(data: Record<string, any>, updateNotExists?: string[]): this;
913
+ update(data: Record<string, any>, updateNotExists?: string[]): Builder<"update">;
851
914
  /**
852
915
  * The 'updateMany' method is used to update existing records in a database table that are associated.
853
916
  *
@@ -858,7 +921,7 @@ declare class Builder extends AbstractBuilder {
858
921
  * @param {array?} updateNotExists options for except update some records in your ${data} using name column(s)
859
922
  * @returns {this} this
860
923
  */
861
- updateMany(data: Record<string, any>, updateNotExists?: string[]): this;
924
+ updateMany(data: Record<string, any>, updateNotExists?: string[]): Builder<"updateMany">;
862
925
  /**
863
926
  * The 'updateCases' method is used to update records in a table based on specific conditions.
864
927
  *
@@ -881,7 +944,7 @@ declare class Builder extends AbstractBuilder {
881
944
  updateCases(cases: {
882
945
  condition: ((query: Builder) => Builder) | Record<string, any>;
883
946
  columns: Record<string, any>;
884
- }[]): this;
947
+ }[]): Builder<"updateMany">;
885
948
  /**
886
949
  * The 'updateNotExists' method is used to update existing records in a database table that are associated.
887
950
  *
@@ -891,7 +954,7 @@ declare class Builder extends AbstractBuilder {
891
954
  * @param {object} data
892
955
  * @returns {this} this
893
956
  */
894
- updateNotExists(data: Record<string, any>): this;
957
+ updateNotExists(data: Record<string, any>): Builder<'update'>;
895
958
  /**
896
959
  * The 'insert' method is used to insert a new record into a database table associated.
897
960
  *
@@ -899,7 +962,7 @@ declare class Builder extends AbstractBuilder {
899
962
  * @param {object} data
900
963
  * @returns {this} this
901
964
  */
902
- insert(data: Record<string, any>): this;
965
+ insert(data: Record<string, any>): Builder<"create">;
903
966
  /**
904
967
  * The 'create' method is used to insert a new record into a database table associated.
905
968
  *
@@ -907,7 +970,7 @@ declare class Builder extends AbstractBuilder {
907
970
  * @param {object} data
908
971
  * @returns {this} this
909
972
  */
910
- create(data: Record<string, any>): this;
973
+ create(data: Record<string, any>): Builder<"create">;
911
974
  /**
912
975
  * The 'createMultiple' method is used to insert a new records into a database table associated.
913
976
  *
@@ -915,7 +978,7 @@ declare class Builder extends AbstractBuilder {
915
978
  * @param {array} data create multiple data
916
979
  * @returns {this} this this
917
980
  */
918
- createMultiple(data: any[]): this;
981
+ createMultiple(data: any[]): Builder<"createMany">;
919
982
  /**
920
983
  * The 'createMany' method is used to insert a new records into a database table associated.
921
984
  *
@@ -923,7 +986,7 @@ declare class Builder extends AbstractBuilder {
923
986
  * @param {array} data create multiple data
924
987
  * @returns {this} this this
925
988
  */
926
- createMany(data: any[]): this;
989
+ createMany(data: any[]): Builder<"createMany">;
927
990
  /**
928
991
  * The 'insertMultiple' method is used to insert a new records into a database table associated.
929
992
  *
@@ -931,7 +994,7 @@ declare class Builder extends AbstractBuilder {
931
994
  * @param {array} data create multiple data
932
995
  * @returns {this} this this
933
996
  */
934
- insertMultiple(data: any[]): this;
997
+ insertMultiple(data: any[]): Builder<"createMany">;
935
998
  /**
936
999
  * The 'insertMany' method is used to insert a new records into a database table associated.
937
1000
  *
@@ -939,7 +1002,7 @@ declare class Builder extends AbstractBuilder {
939
1002
  * @param {array} data create multiple data
940
1003
  * @returns {this} this this
941
1004
  */
942
- insertMany(data: any[]): this;
1005
+ insertMany(data: any[]): Builder<"createMany">;
943
1006
  /**
944
1007
  * The 'createNotExists' method to insert data into a database table while ignoring any duplicate key constraint violations.
945
1008
  *
@@ -948,7 +1011,7 @@ declare class Builder extends AbstractBuilder {
948
1011
  * @param {object} data create not exists data
949
1012
  * @returns {this} this this
950
1013
  */
951
- createNotExists(data: Record<string, any>): this;
1014
+ createNotExists(data: Record<string, any>): Builder<"create">;
952
1015
  /**
953
1016
  * The 'insertNotExists' method to insert data into a database table while ignoring any duplicate key constraint violations.
954
1017
  *
@@ -959,7 +1022,7 @@ declare class Builder extends AbstractBuilder {
959
1022
  */
960
1023
  insertNotExists(data: Record<string, any> & {
961
1024
  length?: never;
962
- }): this;
1025
+ }): Builder<"create">;
963
1026
  /**
964
1027
  * The 'createOrSelect' method to insert data into a database table while select any duplicate key constraint violations.
965
1028
  *
@@ -970,7 +1033,7 @@ declare class Builder extends AbstractBuilder {
970
1033
  */
971
1034
  createOrSelect(data: Record<string, any> & {
972
1035
  length?: never;
973
- }): this;
1036
+ }): Builder<'create'>;
974
1037
  /**
975
1038
  * The 'insertOrSelect' method to insert data into a database table while select any duplicate key constraint violations.
976
1039
  *
@@ -981,7 +1044,7 @@ declare class Builder extends AbstractBuilder {
981
1044
  */
982
1045
  insertOrSelect(data: Record<string, any> & {
983
1046
  length?: never;
984
- }): this;
1047
+ }): Builder<'create'>;
985
1048
  /**
986
1049
  * The 'updateOrCreate' method allows you to update an existing record in a database table if it exists or create a new record if it does not exist.
987
1050
  *
@@ -992,7 +1055,7 @@ declare class Builder extends AbstractBuilder {
992
1055
  */
993
1056
  updateOrCreate(data: Record<string, any> & {
994
1057
  length?: never;
995
- }): this;
1058
+ }): Builder<"createOrUpdate">;
996
1059
  /**
997
1060
  * The 'updateOrInsert' method allows you to update an existing record in a database table if it exists or create a new record if it does not exist.
998
1061
  *
@@ -1003,7 +1066,7 @@ declare class Builder extends AbstractBuilder {
1003
1066
  */
1004
1067
  updateOrInsert(data: Record<string, any> & {
1005
1068
  length?: never;
1006
- }): this;
1069
+ }): Builder<"createOrUpdate">;
1007
1070
  /**
1008
1071
  * The 'insertOrUpdate' method allows you to update an existing record in a database table if it exists or create a new record if it does not exist.
1009
1072
  *
@@ -1014,7 +1077,7 @@ declare class Builder extends AbstractBuilder {
1014
1077
  */
1015
1078
  insertOrUpdate(data: Record<string, any> & {
1016
1079
  length?: never;
1017
- }): this;
1080
+ }): Builder<"createOrUpdate">;
1018
1081
  /**
1019
1082
  *
1020
1083
  * The 'createOrUpdate' method allows you to update an existing record in a database table if it exists or create a new record if it does not exist.
@@ -1026,7 +1089,7 @@ declare class Builder extends AbstractBuilder {
1026
1089
  */
1027
1090
  createOrUpdate(data: Record<string, any> & {
1028
1091
  length?: never;
1029
- }): this;
1092
+ }): Builder<"createOrUpdate">;
1030
1093
  /**
1031
1094
  * The 'toString' method is used to retrieve the raw SQL query that would be executed by a query builder instance without actually executing it.
1032
1095
  *
@@ -1162,6 +1225,40 @@ declare class Builder extends AbstractBuilder {
1162
1225
  ParentTable: string;
1163
1226
  ParentColumn: string;
1164
1227
  }[]>;
1228
+ /**
1229
+ * Adds a foreign key constraint to a table.
1230
+ *
1231
+ * This method checks whether the specified foreign key constraint already exists
1232
+ * on the table before attempting to create it. If the constraint exists, an error
1233
+ * will be thrown to prevent duplication.
1234
+ *
1235
+ * @async
1236
+ * @method addFK
1237
+ * @param {Object} params - Parameters for creating the foreign key.
1238
+ * @param {string} params.table - The name of the table where the foreign key will be added.
1239
+ * @param {string} params.tableRef - The referenced table name.
1240
+ * @param {string} params.key - The column in the current table that will act as the foreign key.
1241
+ * @param {string} params.constraint - The name of the foreign key constraint.
1242
+ * @param {Object} params.foreign - Foreign key configuration.
1243
+ * @param {string} params.foreign.references - The referenced column in the referenced table.
1244
+ * @param {string} params.foreign.onDelete - Action when a referenced row is deleted (e.g. CASCADE, SET NULL).
1245
+ * @param {string} params.foreign.onUpdate - Action when a referenced row is updated (e.g. CASCADE, RESTRICT).
1246
+ *
1247
+ * @throws {Error} If the specified foreign key constraint already exists.
1248
+ *
1249
+ * @returns {Promise<void>} Resolves when the foreign key constraint is successfully created.
1250
+ */
1251
+ addFK({ table, tableRef, key, constraint, foreign }: {
1252
+ table: string;
1253
+ tableRef: string;
1254
+ key: string;
1255
+ constraint: string;
1256
+ foreign: {
1257
+ references: string;
1258
+ onDelete: string;
1259
+ onUpdate: string;
1260
+ };
1261
+ }): Promise<void>;
1165
1262
  /**
1166
1263
  * The `dropFK` method is used to remove a foreign key constraint from the database.
1167
1264
  * If a table name is provided, the constraint will be dropped from that table;
@@ -1208,10 +1305,172 @@ declare class Builder extends AbstractBuilder {
1208
1305
  * @returns {Promise<boolean>}
1209
1306
  *
1210
1307
  */
1211
- hasIndex({ index, table }: {
1212
- index: string;
1308
+ hasIndex({ name, table }: {
1309
+ name: string;
1310
+ table?: string;
1311
+ }): Promise<boolean>;
1312
+ /**
1313
+ * Adds an index to a table.
1314
+ *
1315
+ * This method checks whether the specified index already exists on the table
1316
+ * before attempting to create it. If the index exists, an error will be thrown
1317
+ * to prevent duplication.
1318
+ *
1319
+ * @async
1320
+ * @method addIndex
1321
+ * @param {Object} params - Parameters for creating the index.
1322
+ * @param {string} params.name - The name of the index.
1323
+ * @param {string} [params.table] - The table where the index will be created. Defaults to the current model table.
1324
+ * @param {string[]} params.columns - The columns included in the index.
1325
+ *
1326
+ * @throws {Error} If the specified index already exists.
1327
+ *
1328
+ * @returns {Promise<void>} Resolves when the index has been successfully created.
1329
+ */
1330
+ addIndex({ name, table, columns }: {
1331
+ name: string;
1332
+ table?: string;
1333
+ columns: string[];
1334
+ }): Promise<void>;
1335
+ /**
1336
+ * Drops an index from a table.
1337
+ *
1338
+ * This method checks whether the specified index exists on the table
1339
+ * before attempting to drop it. If the index does not exist, an error
1340
+ * will be thrown.
1341
+ *
1342
+ * @async
1343
+ * @method dropIndex
1344
+ * @param {Object} params - Parameters for dropping the index.
1345
+ * @param {string} params.name - The name of the index to drop.
1346
+ * @param {string} [params.table] - The table from which the index will be removed. Defaults to the current model table.
1347
+ *
1348
+ * @throws {Error} If the specified index was not found.
1349
+ *
1350
+ * @returns {Promise<void>} Resolves when the index has been successfully dropped.
1351
+ */
1352
+ dropIndex({ name, table }: {
1353
+ name: string;
1354
+ table?: string;
1355
+ }): Promise<void>;
1356
+ /**
1357
+ * Checks whether a unique constraint exists on a table.
1358
+ *
1359
+ * This method queries the database metadata to determine if the specified
1360
+ * unique constraint exists on the given table.
1361
+ *
1362
+ * @async
1363
+ * @method hasUnique
1364
+ * @param {Object} params - Parameters for checking the unique constraint.
1365
+ * @param {string} params.name - The name of the unique constraint.
1366
+ * @param {string} [params.table] - The table to check. Defaults to the current model table.
1367
+ *
1368
+ * @returns {Promise<boolean>} Returns `true` if the unique constraint exists, otherwise `false`.
1369
+ */
1370
+ hasUnique({ name, table }: {
1371
+ name: string;
1372
+ table?: string;
1373
+ }): Promise<boolean>;
1374
+ /**
1375
+ * Adds a unique constraint to a table.
1376
+ *
1377
+ * This method checks whether the specified unique constraint already exists
1378
+ * on the table before attempting to create it. If the constraint already exists,
1379
+ * an error will be thrown to prevent duplication.
1380
+ *
1381
+ * @async
1382
+ * @method addUnique
1383
+ * @param {Object} params - Parameters for creating the unique constraint.
1384
+ * @param {string} params.name - The name of the unique constraint.
1385
+ * @param {string} [params.table] - The table where the unique constraint will be added. Defaults to the current model table.
1386
+ * @param {string[]} params.columns - The columns that will be included in the unique constraint.
1387
+ *
1388
+ * @throws {Error} If the specified unique constraint already exists.
1389
+ *
1390
+ * @returns {Promise<void>} Resolves when the unique constraint has been successfully created.
1391
+ */
1392
+ addUnique({ name, table, columns }: {
1393
+ name: string;
1394
+ table?: string;
1395
+ columns: string[];
1396
+ }): Promise<void>;
1397
+ /**
1398
+ * Drops a unique constraint from a table.
1399
+ *
1400
+ * This method checks whether the specified unique constraint exists
1401
+ * on the table before attempting to remove it. If the constraint does
1402
+ * not exist, an error will be thrown.
1403
+ *
1404
+ * @async
1405
+ * @method dropUnique
1406
+ * @param {Object} params - Parameters for dropping the unique constraint.
1407
+ * @param {string} params.name - The name of the unique constraint to drop.
1408
+ * @param {string} [params.table] - The table from which the unique constraint will be removed. Defaults to the current model table.
1409
+ *
1410
+ * @throws {Error} If the specified unique constraint was not found.
1411
+ *
1412
+ * @returns {Promise<void>} Resolves when the unique constraint has been successfully dropped.
1413
+ */
1414
+ dropUnique({ name, table }: {
1415
+ name: string;
1416
+ table?: string;
1417
+ }): Promise<void>;
1418
+ /**
1419
+ * Checks whether a primary key constraint exists on a table.
1420
+ *
1421
+ * This method queries the database metadata to determine if the specified
1422
+ * table contains a primary key constraint.
1423
+ *
1424
+ * @async
1425
+ * @method hasPrimaryKey
1426
+ * @param {Object} [params={}] - Parameters for checking the primary key.
1427
+ * @param {string} [params.table] - The table to check. Defaults to the current model table.
1428
+ *
1429
+ * @returns {Promise<boolean>} Returns `true` if the table has a primary key constraint,
1430
+ * otherwise `false`.
1431
+ */
1432
+ hasPrimaryKey({ table }?: {
1213
1433
  table?: string;
1214
1434
  }): Promise<boolean>;
1435
+ /**
1436
+ * Adds a primary key constraint to a table.
1437
+ *
1438
+ * This method checks whether the table already has a primary key
1439
+ * before attempting to create one. If a primary key already exists,
1440
+ * an error will be thrown.
1441
+ *
1442
+ * @async
1443
+ * @method addPrimaryKey
1444
+ * @param {Object} params - Parameters for creating the primary key.
1445
+ * @param {string} [params.table] - The table where the primary key will be added. Defaults to the current model table.
1446
+ * @param {string[]} params.columns - The column(s) that will form the primary key.
1447
+ *
1448
+ * @throws {Error} If the table already has a primary key constraint.
1449
+ *
1450
+ * @returns {Promise<void>} Resolves when the primary key has been successfully created.
1451
+ */
1452
+ addPrimaryKey({ table, columns }: {
1453
+ table?: string;
1454
+ columns: string[];
1455
+ }): Promise<void>;
1456
+ /**
1457
+ * Drops the primary key constraint from a table.
1458
+ *
1459
+ * This method checks whether the table has a primary key before
1460
+ * attempting to remove it. If no primary key exists, an error will be thrown.
1461
+ *
1462
+ * @async
1463
+ * @method dropPrimaryKey
1464
+ * @param {Object} [params={}] - Parameters for dropping the primary key.
1465
+ * @param {string} [params.table] - The table from which the primary key will be removed. Defaults to the current model table.
1466
+ *
1467
+ * @throws {Error} If the specified primary key constraint was not found.
1468
+ *
1469
+ * @returns {Promise<void>} Resolves when the primary key constraint has been successfully removed.
1470
+ */
1471
+ dropPrimaryKey({ table }?: {
1472
+ table?: string;
1473
+ }): Promise<void>;
1215
1474
  /**
1216
1475
  * The 'bindColumn' method is used to concat table and column -> `users`.`id`
1217
1476
  * @param {string} column
@@ -1330,37 +1589,41 @@ declare class Builder extends AbstractBuilder {
1330
1589
  * The 'find' method is used to retrieve a single record from a database table by its primary key.
1331
1590
  *
1332
1591
  * This method allows you to quickly fetch a specific record by specifying the primary key value, which is typically an integer id.
1333
- * @param {number} id
1592
+ * @param {number | string} primaryKey
1334
1593
  * @returns {promise<any>}
1335
1594
  */
1336
- find(id: number): Promise<Record<string, any> | null>;
1595
+ find(primaryKey: number | string): Promise<Record<string, any> | null>;
1337
1596
  /**
1338
1597
  * The 'pagination' method is used to perform pagination on a set of database query results obtained through the Query Builder.
1339
1598
  *
1340
1599
  * It allows you to split a large set of query results into smaller, more manageable pages,
1341
1600
  * making it easier to display data in a web application and improve user experience
1342
- * @param {?object} paginationOptions
1343
- * @param {number} paginationOptions.limit default 15
1344
- * @param {number} paginationOptions.page default 1
1601
+ * @param {object?} opts by default page = 1 , limit = 15
1602
+ * @property {number?} opts.limit
1603
+ * @property {number?} opts.page
1604
+ * @property {boolean?} opts.distinct
1345
1605
  * @returns {promise<Pagination>}
1346
1606
  */
1347
- pagination(paginationOptions?: {
1607
+ pagination(opts?: {
1348
1608
  limit?: number;
1349
1609
  page?: number;
1610
+ distinct?: boolean;
1350
1611
  }): Promise<TPagination>;
1351
1612
  /**
1352
1613
  * The 'paginate' method is used to perform pagination on a set of database query results obtained through the Query Builder.
1353
1614
  *
1354
1615
  * It allows you to split a large set of query results into smaller, more manageable pages,
1355
1616
  * making it easier to display data in a web application and improve user experience
1356
- * @param {?object} paginationOptions
1357
- * @param {number} paginationOptions.limit
1358
- * @param {number} paginationOptions.page
1617
+ * @param {object?} opts by default page = 1 , limit = 15
1618
+ * @property {number?} opts.limit
1619
+ * @property {number?} opts.page
1620
+ * @property {boolean?} opts.distinct
1359
1621
  * @returns {promise<Pagination>}
1360
1622
  */
1361
- paginate(paginationOptions?: {
1623
+ paginate(opts?: {
1362
1624
  limit?: number;
1363
1625
  page?: number;
1626
+ distinct?: boolean;
1364
1627
  }): Promise<TPagination>;
1365
1628
  /**
1366
1629
  *
@@ -1546,7 +1809,7 @@ declare class Builder extends AbstractBuilder {
1546
1809
  */
1547
1810
  save({ waitMs }?: {
1548
1811
  waitMs?: number | undefined;
1549
- }): Promise<Record<string, any> | any[] | null | undefined>;
1812
+ }): Promise<TSaveBuilderResult<TA>>;
1550
1813
  /**
1551
1814
  *
1552
1815
  * The 'makeSelectStatement' method is used to make select statement.
@@ -1586,6 +1849,15 @@ declare class Builder extends AbstractBuilder {
1586
1849
  * @async
1587
1850
  */
1588
1851
  getTables(): Promise<string[]>;
1852
+ /**
1853
+ * The `getTable` method is used to retrieve a list of all table names
1854
+ * in the current database.
1855
+ *
1856
+ * @returns {Promise<string[]>} A promise that resolves to an array of table names.
1857
+ *
1858
+ * @async
1859
+ */
1860
+ hasTable(table: string): Promise<boolean>;
1589
1861
  /**
1590
1862
  *
1591
1863
  * The 'showColumns' method is used to show columns table.
@@ -1639,7 +1911,7 @@ declare class Builder extends AbstractBuilder {
1639
1911
  }): Promise<boolean>;
1640
1912
  protected exceptColumns(): Promise<string[]>;
1641
1913
  protected _updateHandler(column: string, value?: string | number | null | boolean): string;
1642
- copyBuilder(instance: Builder, options?: {
1914
+ copyBuilder(instance: Builder<any>, options?: {
1643
1915
  update?: boolean;
1644
1916
  insert?: boolean;
1645
1917
  delete?: boolean;