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
@@ -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,14 @@ class RepositoryFactory {
662
558
  if (transaction != null) {
663
559
  instance.bind(transaction);
664
560
  }
561
+ if (noReturn != null && noReturn) {
562
+ instance.void();
563
+ }
564
+ //@ts-ignore
665
565
  return (await instance.createMultiple(data).save());
666
566
  }
667
567
  /**
668
- * The 'createMultiple' method is used to insert a new records into a database table associated.
568
+ * The 'createMany' method is used to insert a new records into a database table associated.
669
569
  *
670
570
  * It simplifies the process of creating and inserting records with an array.
671
571
  * @type {object} options
@@ -674,11 +574,8 @@ class RepositoryFactory {
674
574
  * @property {?transaction} options.transaction
675
575
  * @return {promise<TS[]>}
676
576
  */
677
- async insertMultiple({ data, debug, }) {
678
- return await this.createMultiple({
679
- data,
680
- debug,
681
- });
577
+ async createMany({ data, debug, transaction, noReturn }) {
578
+ return this.createMultiple({ data, debug, transaction, noReturn });
682
579
  }
683
580
  /**
684
581
  *
@@ -690,39 +587,27 @@ class RepositoryFactory {
690
587
  * @property {object} options.data
691
588
  * @property {object} options.where
692
589
  * @property {?boolean} options.debug
693
- * @return {promise<TS>}
590
+ * @return {promise<T.Result<M>>}
694
591
  */
695
- async createOrUpdate({ data, where, debug, }) {
592
+ async createOrUpdate({ data, where, debug, transaction, noReturn }) {
696
593
  if (where == null || !Object.keys(where).length)
697
594
  throw new Error("The method createOrUpdate can't use without where condition");
698
595
  let instance = new this._model();
699
596
  if (debug != null && debug) {
700
597
  instance.debug();
701
598
  }
599
+ if (transaction != null) {
600
+ instance.bind(transaction);
601
+ }
602
+ if (noReturn != null && noReturn) {
603
+ instance.void();
604
+ }
605
+ //@ts-ignore
702
606
  instance.where(where);
703
607
  return (await instance
704
608
  .createOrUpdate(data)
705
609
  .save());
706
610
  }
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
611
  /**
727
612
  *
728
613
  * The 'createOrSelect' method to insert data into a database table while select any duplicate key constraint violations.
@@ -733,9 +618,9 @@ class RepositoryFactory {
733
618
  * @property {object} options.data
734
619
  * @property {object} options.where
735
620
  * @property {?boolean} options.debug
736
- * @return {promise<TS>}
621
+ * @return {promise<T.Result<M>>}
737
622
  */
738
- async createOrSelect({ data, where, debug, }) {
623
+ async createOrSelect({ data, where, debug, transaction, noReturn }) {
739
624
  if (where == null || !Object.keys(where).length) {
740
625
  throw new Error("The method createOrSelect can't use without where condition");
741
626
  }
@@ -743,31 +628,18 @@ class RepositoryFactory {
743
628
  if (debug != null && debug) {
744
629
  instance.debug();
745
630
  }
631
+ if (transaction != null) {
632
+ instance.bind(transaction);
633
+ }
634
+ if (noReturn != null && noReturn) {
635
+ instance.void();
636
+ }
637
+ //@ts-ignore
746
638
  instance.where(where);
747
639
  return (await instance
748
640
  .createOrSelect(data)
749
641
  .save());
750
642
  }
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
643
  /**
772
644
  * The 'update' method is used to update existing records in a database table that are associated.
773
645
  *
@@ -779,9 +651,9 @@ class RepositoryFactory {
779
651
  * @property {object} options.where
780
652
  * @property {?boolean} options.debug
781
653
  * @property {?transaction} options.transaction
782
- * @return {promise<TS>}
654
+ * @return {promise<T.Result<M>>}
783
655
  */
784
- async update({ data, where, debug, transaction, }) {
656
+ async update({ data, where, debug, transaction, noReturn }) {
785
657
  if (where == null || !Object.keys(where).length) {
786
658
  throw new Error("The method update can't use without where condition");
787
659
  }
@@ -792,6 +664,10 @@ class RepositoryFactory {
792
664
  if (transaction != null) {
793
665
  instance.bind(transaction);
794
666
  }
667
+ if (noReturn != null && noReturn) {
668
+ instance.void();
669
+ }
670
+ //@ts-ignore
795
671
  instance.where(where);
796
672
  return (await instance
797
673
  .update(data)
@@ -808,9 +684,9 @@ class RepositoryFactory {
808
684
  * @property {object} options.where
809
685
  * @property {?boolean} options.debug
810
686
  * @property {?transaction} options.transaction
811
- * @return {promise<TS>}
687
+ * @return {promise<T.Result<M>[]>}
812
688
  */
813
- async updateMany({ data, where, debug, transaction, }) {
689
+ async updateMany({ data, where, debug, transaction, noReturn }) {
814
690
  if (where == null || !Object.keys(where).length) {
815
691
  throw new Error("The method updateMany can't use without where condition");
816
692
  }
@@ -821,7 +697,12 @@ class RepositoryFactory {
821
697
  if (transaction != null) {
822
698
  instance.bind(transaction);
823
699
  }
700
+ if (noReturn != null && noReturn) {
701
+ instance.void();
702
+ }
703
+ //@ts-ignore
824
704
  instance.where(where);
705
+ //@ts-ignore
825
706
  return (await instance
826
707
  .updateMany(data)
827
708
  .save());
@@ -864,7 +745,7 @@ class RepositoryFactory {
864
745
  * })
865
746
  *
866
747
  */
867
- async updateCases({ cases, debug, transaction, }) {
748
+ async updateCases({ cases, debug, transaction, noReturn }) {
868
749
  if (!cases.length) {
869
750
  throw new Error("The method updateCases can't use without cases condition");
870
751
  }
@@ -875,8 +756,11 @@ class RepositoryFactory {
875
756
  if (transaction != null) {
876
757
  instance.bind(transaction);
877
758
  }
759
+ if (noReturn != null && noReturn) {
760
+ instance.void();
761
+ }
878
762
  //@ts-ignore
879
- return (await instance.updateCases(cases).save());
763
+ return await instance.updateCases(cases).save();
880
764
  }
881
765
  /**
882
766
  * The 'delete' method is used to delete records from a database table based on the specified query conditions.
@@ -900,6 +784,7 @@ class RepositoryFactory {
900
784
  if (transaction != null) {
901
785
  instance.bind(transaction);
902
786
  }
787
+ //@ts-ignore
903
788
  instance.where(where);
904
789
  return await instance.delete();
905
790
  }
@@ -922,6 +807,7 @@ class RepositoryFactory {
922
807
  if (debug != null && debug) {
923
808
  instance.debug();
924
809
  }
810
+ //@ts-ignore
925
811
  instance.where(where);
926
812
  if (transaction != null) {
927
813
  instance.bind(transaction);
@@ -961,7 +847,7 @@ class RepositoryFactory {
961
847
  return callbackRelation;
962
848
  }
963
849
  _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;
850
+ 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
851
  instance = (instance == null ? new this._model() : instance);
966
852
  const registryRelations = [];
967
853
  if (relations != null) {
@@ -1005,6 +891,7 @@ class RepositoryFactory {
1005
891
  instance.cache({
1006
892
  key: cache.key,
1007
893
  expires: cache.expires,
894
+ namespace: cache.namespace,
1008
895
  });
1009
896
  }
1010
897
  if (select != null) {
@@ -1026,6 +913,12 @@ class RepositoryFactory {
1026
913
  }
1027
914
  }
1028
915
  }
916
+ if (selectRaw != null) {
917
+ for (const column in selectRaw) {
918
+ const value = selectRaw[column];
919
+ instance.selectRaw(`${value.replace(/\s+AS\s+[\w$]+$/i, '')} AS ${column}`);
920
+ }
921
+ }
1029
922
  if (except != null) {
1030
923
  for (const column in except) {
1031
924
  const value = except[column];
@@ -1065,7 +958,6 @@ class RepositoryFactory {
1065
958
  if (value === true)
1066
959
  instance.whereHas(column, (q) => q);
1067
960
  if (value === false) {
1068
- console.log("where not Has");
1069
961
  instance.whereNotHas(column, (q) => q);
1070
962
  }
1071
963
  delete where[column];
@@ -1090,7 +982,6 @@ class RepositoryFactory {
1090
982
  }
1091
983
  if (whereQuery != null) {
1092
984
  instance.whereQuery((query) => {
1093
- //@ts-ignore
1094
985
  return query.whereObject(whereQuery);
1095
986
  });
1096
987
  }
@@ -1167,9 +1058,6 @@ class RepositoryFactory {
1167
1058
  *
1168
1059
  * It provides methods for querying, inserting, updating, and deleting records in the database associated with the model.
1169
1060
  *
1170
- *
1171
- *
1172
- * The 'bind' method is used to bind the model to the repository
1173
1061
  * @param {Model} model A class constructor for a model
1174
1062
  * @returns {RepositoryFactory<T,R>}
1175
1063
  *