tspace-mysql 1.9.2 → 1.9.3-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.
- package/README.md +142 -17
- package/dist/lib/core/Abstracts/AbstractBuilder.d.ts +0 -1
- package/dist/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
- package/dist/lib/core/Blueprint.d.ts +43 -10
- package/dist/lib/core/Blueprint.js +43 -2
- package/dist/lib/core/Blueprint.js.map +1 -1
- package/dist/lib/core/Builder.d.ts +5 -5
- package/dist/lib/core/Builder.js +15 -12
- package/dist/lib/core/Builder.js.map +1 -1
- package/dist/lib/core/Cache/MemoryCache.js +9 -4
- package/dist/lib/core/Cache/MemoryCache.js.map +1 -1
- package/dist/lib/core/Contracts/Audit.d.ts +2 -2
- package/dist/lib/core/Contracts/Logger.d.ts +2 -2
- package/dist/lib/core/Model.d.ts +169 -29
- package/dist/lib/core/Model.js +153 -4
- package/dist/lib/core/Model.js.map +1 -1
- package/dist/lib/core/{Queue.d.ts → Queue/index.d.ts} +115 -91
- package/dist/lib/core/Queue/index.js +282 -0
- package/dist/lib/core/Queue/index.js.map +1 -0
- package/dist/lib/core/Queue/types.d.ts +39 -0
- package/dist/lib/core/Queue/types.js +3 -0
- package/dist/lib/core/Queue/types.js.map +1 -0
- package/dist/lib/core/Queue/worker.d.ts +102 -0
- package/dist/lib/core/{Queue.js → Queue/worker.js} +133 -268
- package/dist/lib/core/Queue/worker.js.map +1 -0
- package/dist/lib/core/Repository.d.ts +40 -20
- package/dist/lib/core/Repository.js +35 -14
- package/dist/lib/core/Repository.js.map +1 -1
- package/dist/lib/core/UtilityTypes.d.ts +9 -7
- package/dist/lib/core/UtilityTypes.js.map +1 -1
- package/dist/lib/types/decorator/index.d.ts +3 -0
- package/dist/lib/types/index.d.ts +17 -16
- package/dist/lib/types/repository/index.d.ts +3 -3
- package/dist/lib/utils/index.d.ts +4 -2
- package/dist/lib/utils/index.js +17 -1
- package/dist/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/lib/core/Queue.js.map +0 -1
package/dist/lib/core/Model.js
CHANGED
|
@@ -136,6 +136,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* The 'formatPattern' method is used to change the format of the pattern.
|
|
139
|
+
* @static
|
|
139
140
|
* @param {object} data { data , pattern }
|
|
140
141
|
* @property {Record | string} data
|
|
141
142
|
* @property {string} parttern
|
|
@@ -159,6 +160,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
159
160
|
}
|
|
160
161
|
/**
|
|
161
162
|
* The 'instance' method is used get instance.
|
|
163
|
+
* @static
|
|
162
164
|
* @override
|
|
163
165
|
* @static
|
|
164
166
|
* @returns {Model} instance of the Model
|
|
@@ -181,6 +183,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
181
183
|
* The 'find' method is used to retrieve a single record from a database table by its primary key.
|
|
182
184
|
*
|
|
183
185
|
* It allows you to retrieve a single record from a database table that meets the specified criteria.
|
|
186
|
+
* @static
|
|
184
187
|
* @type {?object} options
|
|
185
188
|
* @property {?object} options.select
|
|
186
189
|
* @property {?object} options.except
|
|
@@ -221,6 +224,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
221
224
|
* The 'findOne' method is used to retrieve the get record that matches the query conditions.
|
|
222
225
|
*
|
|
223
226
|
* It allows you to retrieve a single record from a database table that meets the specified criteria.
|
|
227
|
+
* @static
|
|
224
228
|
* @type {?object} options
|
|
225
229
|
* @property {?object} options.select
|
|
226
230
|
* @property {?object} options.except
|
|
@@ -261,6 +265,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
261
265
|
* The 'findMany' method is used to retrieve the get record that matches the query conditions.
|
|
262
266
|
*
|
|
263
267
|
* It allows you to retrieve a single record from a database table that meets the specified criteria.
|
|
268
|
+
* @static
|
|
264
269
|
* @type {?object} options
|
|
265
270
|
* @property {?object} options.select
|
|
266
271
|
* @property {?object} options.except
|
|
@@ -302,6 +307,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
302
307
|
*
|
|
303
308
|
* It allows you to split a large set of query results into smaller, more manageable pages,
|
|
304
309
|
* making it easier to display data in a web application and improve user experience.
|
|
310
|
+
* @static
|
|
305
311
|
* @type {?object} options
|
|
306
312
|
* @property {?object} options.select
|
|
307
313
|
* @property {?object} options.except
|
|
@@ -343,6 +349,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
343
349
|
* The 'exists' method is used to determine if any records exist in the database table that match the query conditions.
|
|
344
350
|
*
|
|
345
351
|
* It returns a boolean value indicating whether there are any matching records.
|
|
352
|
+
* @static
|
|
346
353
|
* @type {?object} options
|
|
347
354
|
* @property {?object} options.select
|
|
348
355
|
* @property {?object} options.except
|
|
@@ -378,6 +385,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
378
385
|
* The 'toQuery' method is used to retrieve the raw SQL query that would be executed by a query builder instance without actually executing it.
|
|
379
386
|
*
|
|
380
387
|
* This method is particularly useful for debugging and understanding the SQL queries generated by your application.
|
|
388
|
+
* @static
|
|
381
389
|
* @type {?object} options
|
|
382
390
|
* @property {?object} options.select
|
|
383
391
|
* @property {?object} options.except
|
|
@@ -409,10 +417,89 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
409
417
|
static toQuery(options) {
|
|
410
418
|
return (0, Repository_1.Repository)(this).toString(options);
|
|
411
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* The 'toArray' method is used to retrieve the raw SQL query that would be executed by a query builder instance without actually executing it.
|
|
422
|
+
*
|
|
423
|
+
* This method is particularly useful for debugging and understanding the SQL queries generated by your application.
|
|
424
|
+
* @static
|
|
425
|
+
* @type {?object} options
|
|
426
|
+
* @property {?object} options.select
|
|
427
|
+
* @property {?object} options.except
|
|
428
|
+
* @property {?object[]} options.orderBy
|
|
429
|
+
* @property {?string[]} options.groupBy
|
|
430
|
+
* @property {?string} options.having
|
|
431
|
+
* @property {?number} options.limit
|
|
432
|
+
* @property {?number} options.offset
|
|
433
|
+
* @property {?object} options.where
|
|
434
|
+
* @property {?string[]} options.whereRaw
|
|
435
|
+
* @property {?object} options.whereQuery
|
|
436
|
+
* @property {?{condition,callback}} options.when
|
|
437
|
+
* @property {?{localKey , referenceKey}[]} options.join
|
|
438
|
+
* @property {?{localKey , referenceKey}[]} options.rightJoin
|
|
439
|
+
* @property {?{localKey , referenceKey}[]} options.leftJoin
|
|
440
|
+
* @property {?boolean} options.debug
|
|
441
|
+
* @property {?number} options.page
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* import { User } from '../Models/User'
|
|
445
|
+
*
|
|
446
|
+
* const users = await User.exists({
|
|
447
|
+
* where : {
|
|
448
|
+
* id: 1
|
|
449
|
+
* }
|
|
450
|
+
* })
|
|
451
|
+
*
|
|
452
|
+
*/
|
|
453
|
+
static toArray(column, options = {}) {
|
|
454
|
+
return (0, Repository_1.Repository)(this).toArray(column, options);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
*
|
|
458
|
+
* The 'toAsyncIterable' method is used to execute a database query and return the result set as an asynchronous iterable.
|
|
459
|
+
*
|
|
460
|
+
* It retrieves multiple records from a database table based on the criteria specified in the query.
|
|
461
|
+
* The optional callback function can be used to modify the generated SQL query before execution.
|
|
462
|
+
* @static
|
|
463
|
+
* @type {?object} options
|
|
464
|
+
* @property {?object} options.select
|
|
465
|
+
* @property {?object} options.except
|
|
466
|
+
* @property {?object[]} options.orderBy
|
|
467
|
+
* @property {?string[]} options.groupBy
|
|
468
|
+
* @property {?string} options.having
|
|
469
|
+
* @property {?number} options.limit
|
|
470
|
+
* @property {?number} options.offset
|
|
471
|
+
* @property {?object} options.where
|
|
472
|
+
* @property {?string[]} options.whereRaw
|
|
473
|
+
* @property {?object} options.whereQuery
|
|
474
|
+
* @property {?{condition,callback}} options.when
|
|
475
|
+
* @property {?{localKey , referenceKey}[]} options.join
|
|
476
|
+
* @property {?{localKey , referenceKey}[]} options.rightJoin
|
|
477
|
+
* @property {?{localKey , referenceKey}[]} options.leftJoin
|
|
478
|
+
* @property {?string[]} options.relations
|
|
479
|
+
* @property {string[]} options.relationExists
|
|
480
|
+
* @property {?{condition,callback}} options.relationQuery
|
|
481
|
+
* @property {?boolean} options.debug
|
|
482
|
+
* @returns {promise<object>[]}
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* import { User } from '../Models/User'
|
|
486
|
+
*
|
|
487
|
+
* const users = await User.findMany({
|
|
488
|
+
* select : { id: true, name: true },
|
|
489
|
+
* where : {
|
|
490
|
+
* id: 1
|
|
491
|
+
* }
|
|
492
|
+
* })
|
|
493
|
+
*
|
|
494
|
+
*/
|
|
495
|
+
static async *toAsyncIterable(options = {}) {
|
|
496
|
+
return yield* (0, Repository_1.Repository)(this).toAsyncIterable(options);
|
|
497
|
+
}
|
|
412
498
|
/**
|
|
413
499
|
* The 'create' method is used to insert a new record into a database table associated.
|
|
414
500
|
*
|
|
415
501
|
* It simplifies the process of creating and inserting records.
|
|
502
|
+
* @static
|
|
416
503
|
* @type {object} options
|
|
417
504
|
* @property {object} options.data
|
|
418
505
|
* @property {?boolean} options.debug
|
|
@@ -426,6 +513,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
426
513
|
* The 'createMany' method is used to insert a new records into a database table associated.
|
|
427
514
|
*
|
|
428
515
|
* It simplifies the process of creating and inserting records with an array.
|
|
516
|
+
* @static
|
|
429
517
|
* @type {object} options
|
|
430
518
|
* @property {object[]} options.data
|
|
431
519
|
* @property {?boolean} options.debug
|
|
@@ -441,6 +529,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
441
529
|
*
|
|
442
530
|
* This method is particularly useful when you want to update a record based on certain conditions and,
|
|
443
531
|
* if the record matching those conditions doesn't exist, create a new one with the provided data.
|
|
532
|
+
* @static
|
|
444
533
|
* @type {object} options
|
|
445
534
|
* @property {object} options.data
|
|
446
535
|
* @property {object} options.where
|
|
@@ -456,7 +545,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
456
545
|
*
|
|
457
546
|
* This method is particularly useful when you want to insert records into a table and ensure that duplicates are not inserted,
|
|
458
547
|
* but without raising an error or exception if duplicates are encountered.
|
|
459
|
-
*
|
|
548
|
+
* @static
|
|
460
549
|
* @type {object} options
|
|
461
550
|
* @property {object} options.data
|
|
462
551
|
* @property {object} options.where
|
|
@@ -473,6 +562,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
473
562
|
*
|
|
474
563
|
* This method is particularly useful when you want to insert records into a table and ensure that duplicates are not inserted,
|
|
475
564
|
* but if exists should be returns a result.
|
|
565
|
+
* @static
|
|
476
566
|
* @type {object} options
|
|
477
567
|
* @property {object} options.data
|
|
478
568
|
* @property {object} options.where
|
|
@@ -488,6 +578,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
488
578
|
* It simplifies the process of updating records by allowing you to specify the values to be updated using a single call.
|
|
489
579
|
*
|
|
490
580
|
* It allows you to remove one record that match certain criteria.
|
|
581
|
+
* @static
|
|
491
582
|
* @type {object} options
|
|
492
583
|
* @property {object} options.data
|
|
493
584
|
* @property {object} options.where
|
|
@@ -504,6 +595,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
504
595
|
* It simplifies the process of updating records by allowing you to specify the values to be updated using a single call.
|
|
505
596
|
*
|
|
506
597
|
* It allows you to remove more records that match certain criteria.
|
|
598
|
+
* @static
|
|
507
599
|
* @type {object} options
|
|
508
600
|
* @property {object} options.data
|
|
509
601
|
* @property {object} options.where
|
|
@@ -515,8 +607,52 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
515
607
|
return (0, Repository_1.Repository)(this).updateMany(options);
|
|
516
608
|
}
|
|
517
609
|
/**
|
|
518
|
-
* The 'cache' method is used
|
|
519
|
-
*
|
|
610
|
+
* The 'cache' method is used to access to cache operations for the current model.
|
|
611
|
+
*
|
|
612
|
+
* The cache API exposes methods for retrieving the configured cache provider,
|
|
613
|
+
* selecting a cache driver, managing cache entries, and optionally generating
|
|
614
|
+
* model-scoped cache keys.
|
|
615
|
+
*
|
|
616
|
+
* When the `namespace` option is enabled, cache keys are automatically prefixed
|
|
617
|
+
* with the current database and table name in the following format:
|
|
618
|
+
*
|
|
619
|
+
* `database:table:key`
|
|
620
|
+
*
|
|
621
|
+
* This helps prevent cache key collisions between different models or tables.
|
|
622
|
+
* @static
|
|
623
|
+
* @returns {TCacheModel} An object containing cache provider, driver, and cache management methods.
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* // Get the configured cache provider.
|
|
627
|
+
* const provider = User.cache.provider(); // "db" | "memory" | "redis"
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
* // Store a value using a model-scoped cache key.
|
|
631
|
+
* await User.cache.set("users", users, 60_000, {
|
|
632
|
+
* namespace: true
|
|
633
|
+
* });
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* // Retrieve a model-scoped cache value.
|
|
637
|
+
* const users = await User.cache.get("users", {
|
|
638
|
+
* namespace: true
|
|
639
|
+
* });
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* // Check whether a cache entry exists.
|
|
643
|
+
* const exists = await User.cache.exists("users", {
|
|
644
|
+
* namespace: true
|
|
645
|
+
* });
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* // Delete a cache entry.
|
|
649
|
+
* await User.cache.delete("users", {
|
|
650
|
+
* namespace: true
|
|
651
|
+
* });
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* // Clear all cache entries.
|
|
655
|
+
* await User.cache.clear();
|
|
520
656
|
*/
|
|
521
657
|
static get cache() {
|
|
522
658
|
const getCacheKey = (key) => {
|
|
@@ -573,6 +709,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
573
709
|
* - DELETE: waits
|
|
574
710
|
*
|
|
575
711
|
* The lock is released automatically after the callback completes.
|
|
712
|
+
* @static
|
|
576
713
|
*
|
|
577
714
|
* @Note
|
|
578
715
|
* This approach is not recommended in clustered or load-balance environments,
|
|
@@ -4338,6 +4475,18 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
4338
4475
|
toSQL({ latest = false, oldest = false, } = {}) {
|
|
4339
4476
|
return this.toString({ latest, oldest });
|
|
4340
4477
|
}
|
|
4478
|
+
/**
|
|
4479
|
+
*
|
|
4480
|
+
* @override
|
|
4481
|
+
* @param {Function?} cb callback function return query sql
|
|
4482
|
+
* @returns {AsyncIterable<T.Result<this, K>>}
|
|
4483
|
+
*/
|
|
4484
|
+
async *toAsyncIterable(cb) {
|
|
4485
|
+
if (this.$state.get("VOID"))
|
|
4486
|
+
return yield* [];
|
|
4487
|
+
const results = await this.get(cb);
|
|
4488
|
+
return yield* results;
|
|
4489
|
+
}
|
|
4341
4490
|
/**
|
|
4342
4491
|
* @override
|
|
4343
4492
|
* @param {string=} column [column=id]
|
|
@@ -5946,7 +6095,7 @@ class Model extends AbstractModel_1.AbstractModel {
|
|
|
5946
6095
|
}
|
|
5947
6096
|
await this.$utils.hookHandle(this.$state.get("HOOKS"), result);
|
|
5948
6097
|
await this._observer(result, "selected");
|
|
5949
|
-
this._setCache(result);
|
|
6098
|
+
await this._setCache(result);
|
|
5950
6099
|
return result;
|
|
5951
6100
|
}
|
|
5952
6101
|
async _queryUpdateModel() {
|