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
@@ -7,56 +7,53 @@ class RepositoryFactory {
7
7
  this._model = _model;
8
8
  }
9
9
  /**
10
- *
11
- * The 'first' method is used to retrieve the first record that matches the query conditions.
12
- *
13
- * It allows you to retrieve a single record from a database table that meets the specified criteria.
14
- * @type {?Object} options
15
- * @property {?object} options.select
16
- * @property {?object} options.except
17
- * @property {?object[]} options.orderBy
18
- * @property {?string[]} options.groupBy
19
- * @property {?string} options.having
20
- * @property {?number} options.limit
21
- * @property {?number} options.offset
22
- * @property {?object} options.where
23
- * @property {?string[]} options.whereRaw
24
- * @property {?object} options.whereQuery
25
- * @property {?{condition,callback}} options.when
26
- * @property {?{localKey , referenceKey}[]} options.join
27
- * @property {?{localKey , referenceKey}[]} options.rightJoin
28
- * @property {?{localKey , referenceKey}[]} options.leftJoin
29
- * @property {string[]} options.relations
30
- * @property {string[]} options.relationExists
31
- * @property {?{condition,callback}} options.relationQuery
32
- * @property {?boolean} options.debug
33
- * @returns {promise<Object | null>}
34
- *
35
- * @example
36
- * import { Repository } from 'tspace-mysql'
37
- * import { User } from '../Models/User'
38
- *
39
- * const userRepository = Repository(User)
40
- *
41
- * const user = await userRepository.findOne({
42
- * select : { id: true, name: true },
43
- * where : {
44
- * id: 1
45
- * }
46
- * })
47
- *
48
- * const user = await userRepository.findOne()
49
- */
50
- async first(options = {}) {
10
+ *
11
+ * The 'find' method is used to retrieve a single record from a database table by its primary key.
12
+ *
13
+ * It allows you to retrieve a single record from a database table that meets the specified criteria.
14
+ * @type {?Object} options
15
+ * @property {?object} options.select
16
+ * @property {?object} options.except
17
+ * @property {?object[]} options.orderBy
18
+ * @property {?string[]} options.groupBy
19
+ * @property {?string} options.having
20
+ * @property {?number} options.limit
21
+ * @property {?number} options.offset
22
+ * @property {?object} options.where
23
+ * @property {?string[]} options.whereRaw
24
+ * @property {?object} options.whereQuery
25
+ * @property {?{condition,callback}} options.when
26
+ * @property {?{localKey , referenceKey}[]} options.join
27
+ * @property {?{localKey , referenceKey}[]} options.rightJoin
28
+ * @property {?{localKey , referenceKey}[]} options.leftJoin
29
+ * @property {string[]} options.relations
30
+ * @property {string[]} options.relationExists
31
+ * @property {?{condition,callback}} options.relationQuery
32
+ * @property {?boolean} options.debug
33
+ * @returns {promise<Object | null>}
34
+ *
35
+ * @example
36
+ * import { Repository } from 'tspace-mysql'
37
+ * import { User } from '../Models/User'
38
+ *
39
+ * const userRepository = Repository(User)
40
+ *
41
+ * const user = await userRepository.find(1,{
42
+ * select : { id: true, name: true }
43
+ * })
44
+ *
45
+ * const user = await userRepository.findOne()
46
+ */
47
+ async find(primaryKey, options = {}) {
51
48
  const instance = this._handlerRequest(options);
52
49
  if (!instance) {
53
50
  throw new Error("The instance is not initialized");
54
51
  }
55
- return await instance.first();
52
+ return await instance.where(instance['$state'].get("PRIMARY_KEY"), primaryKey).first();
56
53
  }
57
54
  /**
58
55
  *
59
- * The 'findOne' method is used to retrieve the findOne record that matches the query conditions.
56
+ * The 'findOne' method is used to retrieve the first record that matches the query conditions.
60
57
  *
61
58
  * It allows you to retrieve a single record from a database table that meets the specified criteria.
62
59
  * @type {?Object} options
@@ -96,11 +93,15 @@ class RepositoryFactory {
96
93
  * const user = await userRepository.findOne()
97
94
  */
98
95
  async findOne(options = {}) {
99
- return await this.first(options);
96
+ const instance = this._handlerRequest(options);
97
+ if (!instance) {
98
+ throw new Error("The instance is not initialized");
99
+ }
100
+ return await instance.first();
100
101
  }
101
102
  /**
102
103
  *
103
- * The 'get' method is used to retrieve the get record that matches the query conditions.
104
+ * The 'findMany' method is used to retrieve the get record that matches the query conditions.
104
105
  *
105
106
  * It allows you to retrieve a single record from a database table that meets the specified criteria.
106
107
  * @type {?Object} options
@@ -139,7 +140,7 @@ class RepositoryFactory {
139
140
  *
140
141
  * const users = await userRepository.get()
141
142
  */
142
- async get(options = {}) {
143
+ async findMany(options = {}) {
143
144
  const instance = this._handlerRequest(options);
144
145
  if (instance == null)
145
146
  throw new Error("The instance is not initialized");
@@ -147,51 +148,7 @@ class RepositoryFactory {
147
148
  }
148
149
  /**
149
150
  *
150
- * The 'get' method is used to retrieve the get record that matches the query conditions.
151
- *
152
- * It allows you to retrieve a single record from a database table that meets the specified criteria.
153
- * @type {?object} options
154
- * @property {?object} options.select
155
- * @property {?object} options.except
156
- * @property {?object[]} options.orderBy
157
- * @property {?string[]} options.groupBy
158
- * @property {?string} options.having
159
- * @property {?number} options.limit
160
- * @property {?number} options.offset
161
- * @property {?object} options.where
162
- * @property {?string[]} options.whereRaw
163
- * @property {?object} options.whereQuery
164
- * @property {?{condition,callback}} options.when
165
- * @property {?{localKey , referenceKey}[]} options.join
166
- * @property {?{localKey , referenceKey}[]} options.rightJoin
167
- * @property {?{localKey , referenceKey}[]} options.leftJoin
168
- * @property {?string[]} options.relations
169
- * @property {string[]} options.relationExists
170
- * @property {?{condition,callback}} options.relationQuery
171
- * @property {?boolean} options.debug
172
- * @returns {promise<object>[]}
173
- *
174
- * @example
175
- * import { Repository } from 'tspace-mysql'
176
- * import { User } from '../Models/User'
177
- *
178
- * const userRepository = Repository(User)
179
- *
180
- * const users = await userRepository.findMany({
181
- * select : { id: true, name: true },
182
- * where : {
183
- * id: 1
184
- * }
185
- * })
186
- *
187
- * const users = await userRepository.findMany()
188
- */
189
- async findMany(options = {}) {
190
- return await this.get(options);
191
- }
192
- /**
193
- *
194
- * The 'pagination' method is used to perform pagination on a set of database query results obtained through the Query Builder.
151
+ * The 'paginate' method is used to perform pagination on a set of database query results obtained through the Query Builder.
195
152
  *
196
153
  * It allows you to split a large set of query results into smaller, more manageable pages,
197
154
  * making it easier to display data in a web application and improve user experience.
@@ -223,30 +180,28 @@ class RepositoryFactory {
223
180
  *
224
181
  * const userRepository = Repository(User)
225
182
  *
226
- * const users = await userRepository.pagination({
183
+ * const users = await userRepository.paginate({
227
184
  * select : { id: true, name: true },
228
185
  * where : {
229
186
  * id: 1
230
187
  * }
231
188
  * })
232
189
  *
233
- * const users = await userRepository.pagination({ page : 1 , limit : 2 })
190
+ * const users = await userRepository.paginate({ page : 1 , limit : 2 })
234
191
  */
235
- async pagination(options = {}) {
192
+ async paginate(options = {}) {
236
193
  const instance = this._handlerRequest(options);
237
194
  if (instance == null)
238
195
  throw new Error("The instance is not initialized");
239
- return (await instance.pagination({
196
+ return (await instance.paginate({
240
197
  limit: options.limit,
241
198
  page: options.page,
242
199
  }));
243
200
  }
244
201
  /**
202
+ * The 'exists' method is used to determine if any records exist in the database table that match the query conditions.
245
203
  *
246
- * The 'paginate' method is used to perform pagination on a set of database query results obtained through the Query Builder.
247
- *
248
- * It allows you to split a large set of query results into smaller, more manageable pages,
249
- * making it easier to display data in a web application and improve user experience
204
+ * It returns a boolean value indicating whether there are any matching records.
250
205
  * @type {?object} options
251
206
  * @property {?object} options.select
252
207
  * @property {?object} options.except
@@ -262,12 +217,7 @@ class RepositoryFactory {
262
217
  * @property {?{localKey , referenceKey}[]} options.join
263
218
  * @property {?{localKey , referenceKey}[]} options.rightJoin
264
219
  * @property {?{localKey , referenceKey}[]} options.leftJoin
265
- * @property {?string[]} options.relations
266
- * @property {string[]} options.relationExists
267
- * @property {?{condition,callback}} options.relationQuery
268
220
  * @property {?boolean} options.debug
269
- * @property {?number} options.page
270
- * @returns {promise<{ meta , data[]}>}
271
221
  *
272
222
  * @example
273
223
  * import { Repository } from 'tspace-mysql'
@@ -275,39 +225,12 @@ class RepositoryFactory {
275
225
  *
276
226
  * const userRepository = Repository(User)
277
227
  *
278
- * const users = await userRepository.paginate({
279
- * select : { id: true, name: true },
228
+ * const users = await userRepository.exists({
280
229
  * where : {
281
230
  * id: 1
282
231
  * }
283
232
  * })
284
233
  *
285
- * const users = await userRepository.paginate({ page : 1 , limit : 2 })
286
- */
287
- async paginate(options = {}) {
288
- return await this.pagination(options);
289
- }
290
- /**
291
- * The 'exists' method is used to determine if any records exist in the database table that match the query conditions.
292
- *
293
- * It returns a boolean value indicating whether there are any matching records.
294
- * @type {?object} options
295
- * @property {?object} options.select
296
- * @property {?object} options.except
297
- * @property {?object[]} options.orderBy
298
- * @property {?string[]} options.groupBy
299
- * @property {?string} options.having
300
- * @property {?number} options.limit
301
- * @property {?number} options.offset
302
- * @property {?object} options.where
303
- * @property {?string[]} options.whereRaw
304
- * @property {?object} options.whereQuery
305
- * @property {?{condition,callback}} options.when
306
- * @property {?{localKey , referenceKey}[]} options.join
307
- * @property {?{localKey , referenceKey}[]} options.rightJoin
308
- * @property {?{localKey , referenceKey}[]} options.leftJoin
309
- * @property {?boolean} options.debug
310
- * @property {?number} options.page
311
234
  */
312
235
  async exists(options) {
313
236
  const instance = this._handlerRequest(options);
@@ -335,7 +258,6 @@ class RepositoryFactory {
335
258
  * @property {?{localKey , referenceKey}[]} options.rightJoin
336
259
  * @property {?{localKey , referenceKey}[]} options.leftJoin
337
260
  * @property {?boolean} options.debug
338
- * @property {?number} options.page
339
261
  * @returns {string}
340
262
  */
341
263
  toString(options = {}) {
@@ -565,15 +487,18 @@ class RepositoryFactory {
565
487
  * @property {object} options.data
566
488
  * @property {?boolean} options.debug
567
489
  * @property {?transaction} options.transaction
568
- * @return {promise<TS>}
490
+ * @return {promise<T.Result<M>>}
569
491
  */
570
- async create({ data, debug, transaction, }) {
492
+ async create({ data, debug, transaction, noReturn, }) {
571
493
  if (!Object.keys(data).length)
572
494
  throw new Error("The data must be required");
573
495
  const instance = new this._model();
574
496
  if (debug != null && debug) {
575
497
  instance.debug();
576
498
  }
499
+ if (noReturn != null && noReturn) {
500
+ instance.void();
501
+ }
577
502
  if (transaction != null) {
578
503
  instance.bind(transaction);
579
504
  }
@@ -581,22 +506,6 @@ class RepositoryFactory {
581
506
  .create(data)
582
507
  .save());
583
508
  }
584
- /**
585
- * The 'insert' method is used to insert a new record into a database table associated.
586
- *
587
- * It simplifies the process of creating and inserting records.
588
- * @type {object} options
589
- * @property {object} options.data
590
- * @property {?boolean} options.debug
591
- * @property {?transaction} options.transaction
592
- * @return {promise<TS>}
593
- */
594
- async insert({ data, debug }) {
595
- return await this.create({
596
- data,
597
- debug,
598
- });
599
- }
600
509
  /**
601
510
  * The 'createNotExists' method to insert data into a database table while ignoring any duplicate key constraint violations.
602
511
  *
@@ -610,38 +519,25 @@ class RepositoryFactory {
610
519
  * @property {?transaction} options.transaction
611
520
  * @return {promise<T | null>}
612
521
  */
613
- async createNotExists({ data, where, debug, }) {
522
+ async createNotExists({ data, where, debug, noReturn, transaction }) {
614
523
  let instance = new this._model();
615
524
  if (debug != null && debug) {
616
525
  instance.debug();
617
526
  }
527
+ if (noReturn != null && noReturn) {
528
+ instance.void();
529
+ }
530
+ if (transaction != null) {
531
+ instance.bind(transaction);
532
+ }
618
533
  if (where == null || !Object.keys(where).length)
619
534
  throw new Error("The method createNotExists can't use without where condition");
535
+ //@ts-ignore
620
536
  instance.where(where);
621
537
  return (await instance
622
538
  .createNotExists(data)
623
539
  .save());
624
540
  }
625
- /**
626
- * The 'insertNotExists' method to insert data into a database table while ignoring any duplicate key constraint violations.
627
- *
628
- * This method is particularly useful when you want to insert records into a table and ensure that duplicates are not inserted,
629
- * but without raising an error or exception if duplicates are encountered.
630
- *
631
- * @type {object} options
632
- * @property {object} options.data
633
- * @property {object} options.where
634
- * @property {?boolean} options.debug
635
- * @property {?transaction} options.transaction
636
- * @return {promise<T | null>}
637
- */
638
- async insertNotExists({ data, where, debug, }) {
639
- return await this.createNotExists({
640
- data,
641
- where,
642
- debug,
643
- });
644
- }
645
541
  /**
646
542
  * The 'createMultiple' method is used to insert a new records into a database table associated.
647
543
  *
@@ -652,7 +548,7 @@ class RepositoryFactory {
652
548
  * @property {?transaction} options.transaction
653
549
  * @return {promise<TS[]>}
654
550
  */
655
- async createMultiple({ data, debug, transaction, }) {
551
+ async createMultiple({ data, debug, transaction, noReturn }) {
656
552
  if (!Object.keys(data).length)
657
553
  throw new Error("The data must be required");
658
554
  const instance = new this._model();
@@ -662,10 +558,13 @@ class RepositoryFactory {
662
558
  if (transaction != null) {
663
559
  instance.bind(transaction);
664
560
  }
561
+ if (noReturn != null && noReturn) {
562
+ instance.void();
563
+ }
665
564
  return (await instance.createMultiple(data).save());
666
565
  }
667
566
  /**
668
- * The 'createMultiple' method is used to insert a new records into a database table associated.
567
+ * The 'createMany' method is used to insert a new records into a database table associated.
669
568
  *
670
569
  * It simplifies the process of creating and inserting records with an array.
671
570
  * @type {object} options
@@ -674,11 +573,8 @@ class RepositoryFactory {
674
573
  * @property {?transaction} options.transaction
675
574
  * @return {promise<TS[]>}
676
575
  */
677
- async insertMultiple({ data, debug, }) {
678
- return await this.createMultiple({
679
- data,
680
- debug,
681
- });
576
+ async createMany({ data, debug, transaction, noReturn }) {
577
+ return this.createMultiple({ data, debug, transaction, noReturn });
682
578
  }
683
579
  /**
684
580
  *
@@ -690,39 +586,27 @@ class RepositoryFactory {
690
586
  * @property {object} options.data
691
587
  * @property {object} options.where
692
588
  * @property {?boolean} options.debug
693
- * @return {promise<TS>}
589
+ * @return {promise<T.Result<M>>}
694
590
  */
695
- async createOrUpdate({ data, where, debug, }) {
591
+ async createOrUpdate({ data, where, debug, transaction, noReturn }) {
696
592
  if (where == null || !Object.keys(where).length)
697
593
  throw new Error("The method createOrUpdate can't use without where condition");
698
594
  let instance = new this._model();
699
595
  if (debug != null && debug) {
700
596
  instance.debug();
701
597
  }
598
+ if (transaction != null) {
599
+ instance.bind(transaction);
600
+ }
601
+ if (noReturn != null && noReturn) {
602
+ instance.void();
603
+ }
604
+ //@ts-ignore
702
605
  instance.where(where);
703
606
  return (await instance
704
607
  .createOrUpdate(data)
705
608
  .save());
706
609
  }
707
- /**
708
- *
709
- * 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.
710
- *
711
- * This method is particularly useful when you want to update a record based on certain conditions and,
712
- * if the record matching those conditions doesn't exist, create a new one with the provided data.
713
- * @type {object} options
714
- * @property {object} options.data
715
- * @property {object} options.where
716
- * @property {?boolean} options.debug
717
- * @return {promise<TS>}
718
- */
719
- async insertOrUpdate({ data, where, debug, }) {
720
- return await this.createOrUpdate({
721
- data,
722
- where,
723
- debug,
724
- });
725
- }
726
610
  /**
727
611
  *
728
612
  * The 'createOrSelect' method to insert data into a database table while select any duplicate key constraint violations.
@@ -733,9 +617,9 @@ class RepositoryFactory {
733
617
  * @property {object} options.data
734
618
  * @property {object} options.where
735
619
  * @property {?boolean} options.debug
736
- * @return {promise<TS>}
620
+ * @return {promise<T.Result<M>>}
737
621
  */
738
- async createOrSelect({ data, where, debug, }) {
622
+ async createOrSelect({ data, where, debug, transaction, noReturn }) {
739
623
  if (where == null || !Object.keys(where).length) {
740
624
  throw new Error("The method createOrSelect can't use without where condition");
741
625
  }
@@ -743,31 +627,18 @@ class RepositoryFactory {
743
627
  if (debug != null && debug) {
744
628
  instance.debug();
745
629
  }
630
+ if (transaction != null) {
631
+ instance.bind(transaction);
632
+ }
633
+ if (noReturn != null && noReturn) {
634
+ instance.void();
635
+ }
636
+ //@ts-ignore
746
637
  instance.where(where);
747
638
  return (await instance
748
639
  .createOrSelect(data)
749
640
  .save());
750
641
  }
751
- /**
752
- *
753
- * The 'insertOrSelect' method to insert data into a database table while select any duplicate key constraint violations.
754
- *
755
- * This method is particularly useful when you want to insert records into a table and ensure that duplicates are not inserted,
756
- * but if exists should be returns a result.
757
- * @type {object} options
758
- * @property {object} options.data
759
- * @property {object} options.where
760
- * @property {?boolean} options.debug
761
- * @property {?transaction} options.transaction
762
- * @return {promise<TS>}
763
- */
764
- async insertOrSelect({ data, where, debug, }) {
765
- return await this.createOrSelect({
766
- data,
767
- where,
768
- debug,
769
- });
770
- }
771
642
  /**
772
643
  * The 'update' method is used to update existing records in a database table that are associated.
773
644
  *
@@ -779,9 +650,9 @@ class RepositoryFactory {
779
650
  * @property {object} options.where
780
651
  * @property {?boolean} options.debug
781
652
  * @property {?transaction} options.transaction
782
- * @return {promise<TS>}
653
+ * @return {promise<T.Result<M>>}
783
654
  */
784
- async update({ data, where, debug, transaction, }) {
655
+ async update({ data, where, debug, transaction, noReturn }) {
785
656
  if (where == null || !Object.keys(where).length) {
786
657
  throw new Error("The method update can't use without where condition");
787
658
  }
@@ -792,6 +663,10 @@ class RepositoryFactory {
792
663
  if (transaction != null) {
793
664
  instance.bind(transaction);
794
665
  }
666
+ if (noReturn != null && noReturn) {
667
+ instance.void();
668
+ }
669
+ //@ts-ignore
795
670
  instance.where(where);
796
671
  return (await instance
797
672
  .update(data)
@@ -808,9 +683,9 @@ class RepositoryFactory {
808
683
  * @property {object} options.where
809
684
  * @property {?boolean} options.debug
810
685
  * @property {?transaction} options.transaction
811
- * @return {promise<TS>}
686
+ * @return {promise<T.Result<M>[]>}
812
687
  */
813
- async updateMany({ data, where, debug, transaction, }) {
688
+ async updateMany({ data, where, debug, transaction, noReturn }) {
814
689
  if (where == null || !Object.keys(where).length) {
815
690
  throw new Error("The method updateMany can't use without where condition");
816
691
  }
@@ -821,6 +696,10 @@ class RepositoryFactory {
821
696
  if (transaction != null) {
822
697
  instance.bind(transaction);
823
698
  }
699
+ if (noReturn != null && noReturn) {
700
+ instance.void();
701
+ }
702
+ //@ts-ignore
824
703
  instance.where(where);
825
704
  return (await instance
826
705
  .updateMany(data)
@@ -864,7 +743,7 @@ class RepositoryFactory {
864
743
  * })
865
744
  *
866
745
  */
867
- async updateCases({ cases, debug, transaction, }) {
746
+ async updateCases({ cases, debug, transaction, noReturn }) {
868
747
  if (!cases.length) {
869
748
  throw new Error("The method updateCases can't use without cases condition");
870
749
  }
@@ -875,8 +754,10 @@ class RepositoryFactory {
875
754
  if (transaction != null) {
876
755
  instance.bind(transaction);
877
756
  }
878
- //@ts-ignore
879
- return (await instance.updateCases(cases).save());
757
+ if (noReturn != null && noReturn) {
758
+ instance.void();
759
+ }
760
+ return await instance.updateCases(cases).save();
880
761
  }
881
762
  /**
882
763
  * The 'delete' method is used to delete records from a database table based on the specified query conditions.
@@ -900,6 +781,7 @@ class RepositoryFactory {
900
781
  if (transaction != null) {
901
782
  instance.bind(transaction);
902
783
  }
784
+ //@ts-ignore
903
785
  instance.where(where);
904
786
  return await instance.delete();
905
787
  }
@@ -922,6 +804,7 @@ class RepositoryFactory {
922
804
  if (debug != null && debug) {
923
805
  instance.debug();
924
806
  }
807
+ //@ts-ignore
925
808
  instance.where(where);
926
809
  if (transaction != null) {
927
810
  instance.bind(transaction);
@@ -961,7 +844,7 @@ class RepositoryFactory {
961
844
  return callbackRelation;
962
845
  }
963
846
  _handlerRequest(options) {
964
- let { cache, select, except, join, leftJoin, rightJoin, where, whereRaw, whereQuery, groupBy, having, orderBy, limit, offset, relations, relationsExists, when, hooks, debug, using, audit, instance, } = options;
847
+ let { cache, select, selectRaw, except, join, leftJoin, rightJoin, where, whereRaw, whereQuery, groupBy, having, orderBy, limit, offset, relations, relationsExists, when, hooks, debug, using, audit, instance, } = options;
965
848
  instance = (instance == null ? new this._model() : instance);
966
849
  const registryRelations = [];
967
850
  if (relations != null) {
@@ -1005,6 +888,7 @@ class RepositoryFactory {
1005
888
  instance.cache({
1006
889
  key: cache.key,
1007
890
  expires: cache.expires,
891
+ namespace: cache.namespace,
1008
892
  });
1009
893
  }
1010
894
  if (select != null) {
@@ -1026,6 +910,12 @@ class RepositoryFactory {
1026
910
  }
1027
911
  }
1028
912
  }
913
+ if (selectRaw != null) {
914
+ for (const column in selectRaw) {
915
+ const value = selectRaw[column];
916
+ instance.selectRaw(`${value.replace(/\s+AS\s+[\w$]+$/i, '')} AS ${column}`);
917
+ }
918
+ }
1029
919
  if (except != null) {
1030
920
  for (const column in except) {
1031
921
  const value = except[column];
@@ -1065,7 +955,6 @@ class RepositoryFactory {
1065
955
  if (value === true)
1066
956
  instance.whereHas(column, (q) => q);
1067
957
  if (value === false) {
1068
- console.log("where not Has");
1069
958
  instance.whereNotHas(column, (q) => q);
1070
959
  }
1071
960
  delete where[column];
@@ -1090,7 +979,6 @@ class RepositoryFactory {
1090
979
  }
1091
980
  if (whereQuery != null) {
1092
981
  instance.whereQuery((query) => {
1093
- //@ts-ignore
1094
982
  return query.whereObject(whereQuery);
1095
983
  });
1096
984
  }
@@ -1167,9 +1055,6 @@ class RepositoryFactory {
1167
1055
  *
1168
1056
  * It provides methods for querying, inserting, updating, and deleting records in the database associated with the model.
1169
1057
  *
1170
- *
1171
- *
1172
- * The 'bind' method is used to bind the model to the repository
1173
1058
  * @param {Model} model A class constructor for a model
1174
1059
  * @returns {RepositoryFactory<T,R>}
1175
1060
  *