tspace-mysql 1.9.1 → 1.9.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 +246 -23
- package/dist/lib/core/Abstracts/AbstractBuilder.d.ts +16 -16
- package/dist/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractDB.d.ts +1 -1
- package/dist/lib/core/Abstracts/AbstractModel.d.ts +7 -2
- package/dist/lib/core/Abstracts/AbstractModel.js.map +1 -1
- package/dist/lib/core/Blueprint.d.ts +14 -14
- package/dist/lib/core/Blueprint.js +2 -4
- package/dist/lib/core/Blueprint.js.map +1 -1
- package/dist/lib/core/Builder.d.ts +52 -34
- package/dist/lib/core/Builder.js +76 -44
- package/dist/lib/core/Builder.js.map +1 -1
- package/dist/lib/core/Cache/index.js +32 -13
- package/dist/lib/core/Cache/index.js.map +1 -1
- package/dist/lib/core/Contracts/Audit.d.ts +4 -4
- package/dist/lib/core/Contracts/Audit.js.map +1 -1
- package/dist/lib/core/Contracts/Logger.d.ts +3 -3
- package/dist/lib/core/Contracts/Logger.js.map +1 -1
- package/dist/lib/core/DB.d.ts +2 -2
- package/dist/lib/core/DB.js +6 -19
- package/dist/lib/core/DB.js.map +1 -1
- package/dist/lib/core/Driver/index.d.ts +7 -5
- package/dist/lib/core/Driver/index.js +4 -2
- package/dist/lib/core/Driver/index.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js +14 -6
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +3 -3
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js +24 -7
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js +18 -12
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.d.ts +3 -3
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js +9 -1
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlDriver.js +15 -7
- package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +3 -3
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js +24 -7
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresDriver.js +14 -6
- package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +3 -3
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js +22 -7
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +1 -0
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js +25 -4
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.d.ts +2 -0
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js +27 -21
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js.map +1 -1
- package/dist/lib/core/Join.d.ts +63 -5
- package/dist/lib/core/Join.js +92 -15
- package/dist/lib/core/Join.js.map +1 -1
- package/dist/lib/core/JoinModel.d.ts +65 -9
- package/dist/lib/core/JoinModel.js +79 -50
- package/dist/lib/core/JoinModel.js.map +1 -1
- package/dist/lib/core/Meta.d.ts +7 -7
- package/dist/lib/core/Meta.js +10 -9
- package/dist/lib/core/Meta.js.map +1 -1
- package/dist/lib/core/Model.d.ts +225 -57
- package/dist/lib/core/Model.js +375 -89
- package/dist/lib/core/Model.js.map +1 -1
- package/dist/lib/core/Queue.d.ts +16 -7
- package/dist/lib/core/Queue.js +69 -29
- package/dist/lib/core/Queue.js.map +1 -1
- package/dist/lib/core/RelationManager.d.ts +4 -4
- package/dist/lib/core/RelationManager.js +141 -16
- package/dist/lib/core/RelationManager.js.map +1 -1
- package/dist/lib/core/Repository.d.ts +1 -1
- package/dist/lib/core/Repository.js +5 -1
- package/dist/lib/core/Repository.js.map +1 -1
- package/dist/lib/core/Schema.d.ts +13 -13
- package/dist/lib/core/Schema.js +12 -0
- package/dist/lib/core/Schema.js.map +1 -1
- package/dist/lib/core/StateManager.d.ts +6 -0
- package/dist/lib/core/StateManager.js +1 -0
- package/dist/lib/core/StateManager.js.map +1 -1
- package/dist/lib/core/UtilityTypes.d.ts +69 -74
- package/dist/lib/core/UtilityTypes.js.map +1 -1
- package/dist/lib/types/index.d.ts +52 -9
- package/dist/lib/utils/index.d.ts +2 -1
- package/dist/lib/utils/index.js +26 -3
- package/dist/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/core/Model.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { AbstractModel } from "./Abstracts/AbstractModel";
|
|
|
4
4
|
import { Blueprint } from "./Blueprint";
|
|
5
5
|
import { JoinModel } from "./JoinModel";
|
|
6
6
|
import { CONSTANTS } from "../constants";
|
|
7
|
-
import type { T } from "./UtilityTypes";
|
|
8
|
-
import type { TRelationOptions, TValidateSchema, TGlobalSetting, TPattern, TRelationQueryOptions, TModelOrObject, TRelationKeys, TLifecycle, TCacheModel, TRawStringQuery } from "../types";
|
|
9
7
|
import { Join } from "./Join";
|
|
8
|
+
import { QueryBuilder } from "./Driver";
|
|
9
|
+
import type { T } from "./UtilityTypes";
|
|
10
|
+
import type { TRelationOptions, TValidateSchema, TGlobalSetting, TPattern, TRelationQueryOptions, TModelOrObject, TRelationKeys, TLifecycle, TCacheModel, TRawStringQuery, TAction, TSaveModelResult } from "../types";
|
|
10
11
|
/**
|
|
11
12
|
*
|
|
12
13
|
* The 'Model' class is a representation of a database table
|
|
@@ -33,7 +34,7 @@ import { Join } from "./Join";
|
|
|
33
34
|
* const users = await new User().findMany()
|
|
34
35
|
* console.log(users)
|
|
35
36
|
*/
|
|
36
|
-
declare class Model<TS extends Record<string, any> = any, TR = unknown> extends AbstractModel {
|
|
37
|
+
declare class Model<TS extends Record<string, any> = any, TR = unknown, TA extends TAction = any> extends AbstractModel {
|
|
37
38
|
constructor();
|
|
38
39
|
/**
|
|
39
40
|
* The 'global' method is used setting global variables in models.
|
|
@@ -405,6 +406,63 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
405
406
|
* @returns {TCacheModel} cache
|
|
406
407
|
*/
|
|
407
408
|
static get cache(): TCacheModel;
|
|
409
|
+
/**
|
|
410
|
+
* The 'lockTable' method is used table lock and execute the callback within the lock scope.
|
|
411
|
+
*
|
|
412
|
+
* The lock is automatically released after the callback completes,
|
|
413
|
+
* regardless of whether it resolves or throws an error.
|
|
414
|
+
*
|
|
415
|
+
* READ:
|
|
416
|
+
* - Other sessions can read.
|
|
417
|
+
* - Other sessions must wait before writing.
|
|
418
|
+
* - SELECT: allowed
|
|
419
|
+
* - INSERT: waits
|
|
420
|
+
* - UPDATE: waits
|
|
421
|
+
* - DELETE: waits
|
|
422
|
+
*
|
|
423
|
+
* WRITE:
|
|
424
|
+
* - Other sessions must wait before reading or writing.
|
|
425
|
+
* - SELECT: waits
|
|
426
|
+
* - INSERT: waits
|
|
427
|
+
* - UPDATE: waits
|
|
428
|
+
* - DELETE: waits
|
|
429
|
+
*
|
|
430
|
+
* The lock is released automatically after the callback completes.
|
|
431
|
+
*
|
|
432
|
+
* @Note
|
|
433
|
+
* This approach is not recommended in clustered or load-balance environments,
|
|
434
|
+
* because locks are session-bound and requests may be routed to different database connections.
|
|
435
|
+
*
|
|
436
|
+
* @template T
|
|
437
|
+
* @param {'READ'|'WRITE'} mode Lock mode.
|
|
438
|
+
* @param {(query: this) => Promise<T>} handler Function executed while the table is locked.
|
|
439
|
+
* @returns {Promise<T>} The value returned by the callback.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* await User.lockTable('READ', async (query) => {
|
|
443
|
+
* query.get();
|
|
444
|
+
* return
|
|
445
|
+
* });
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* await User.lockTable('WRITE', async (query) => {
|
|
449
|
+
* // Avoid creating a new query instance inside the lock.
|
|
450
|
+
* // The new instance uses a different connection/session and
|
|
451
|
+
* // may wait for the current table lock to be released.
|
|
452
|
+
*
|
|
453
|
+
* new User().insert({
|
|
454
|
+
* first_name: 'John',
|
|
455
|
+
* last_name: 'Doe'
|
|
456
|
+
* }).save();
|
|
457
|
+
*
|
|
458
|
+
* // Use the locked query instance instead.
|
|
459
|
+
* await query.insert({
|
|
460
|
+
* first_name: 'John',
|
|
461
|
+
* last_name: 'Doe'
|
|
462
|
+
* }).save();
|
|
463
|
+
* });
|
|
464
|
+
*/
|
|
465
|
+
static lockTable<T, Self extends Model, M extends Model = Self>(this: new () => Self, mode: 'WRITE' | 'READ', handler: (model: M) => Promise<T>): Promise<T>;
|
|
408
466
|
/**
|
|
409
467
|
* The 'boot' method is a special method that you can define within a model.
|
|
410
468
|
* @example
|
|
@@ -918,7 +976,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
918
976
|
* @returns {this} this
|
|
919
977
|
*/
|
|
920
978
|
audit(userId: number, metadata?: Record<string, any>): this;
|
|
921
|
-
|
|
979
|
+
metaTag(meta: "MAIN" | "SUBORDINATE"): this;
|
|
922
980
|
/**
|
|
923
981
|
* The 'typeOfSchema' method is used get type of schema.
|
|
924
982
|
* @returns {TS} type of schema
|
|
@@ -949,6 +1007,12 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
949
1007
|
* @returns {this} this
|
|
950
1008
|
*/
|
|
951
1009
|
select<K extends T.ColumnKeys<this> | "*">(...columns: K[]): this;
|
|
1010
|
+
/**
|
|
1011
|
+
*
|
|
1012
|
+
* @override
|
|
1013
|
+
* @param {string[]} ...columns
|
|
1014
|
+
* @returns {this} this
|
|
1015
|
+
*/
|
|
952
1016
|
addSelect<K extends T.ColumnKeys<this>>(...columns: K[]): this;
|
|
953
1017
|
/**
|
|
954
1018
|
*
|
|
@@ -997,7 +1061,9 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
997
1061
|
* @param {string} column
|
|
998
1062
|
* @returns {string} return table.column
|
|
999
1063
|
*/
|
|
1000
|
-
bindColumn(column: string,
|
|
1064
|
+
bindColumn(column: string, opts?: {
|
|
1065
|
+
pattern: boolean;
|
|
1066
|
+
}): string;
|
|
1001
1067
|
/**
|
|
1002
1068
|
*
|
|
1003
1069
|
* @override
|
|
@@ -1047,7 +1113,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1047
1113
|
* @param {Object} options keep data
|
|
1048
1114
|
* @returns {Model} Model
|
|
1049
1115
|
*/
|
|
1050
|
-
copyModel(instance: Model, options?: {
|
|
1116
|
+
copyModel(instance: Model<any, any, any>, options?: {
|
|
1051
1117
|
update?: boolean;
|
|
1052
1118
|
insert?: boolean;
|
|
1053
1119
|
delete?: boolean;
|
|
@@ -1087,7 +1153,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1087
1153
|
* @override
|
|
1088
1154
|
* @returns {string} return sql query
|
|
1089
1155
|
*/
|
|
1090
|
-
CTEs<M extends Model
|
|
1156
|
+
CTEs<M extends Model<any, any, any>>(as: string, callback: (query: M) => M, bindModel?: new () => M): this;
|
|
1091
1157
|
/**
|
|
1092
1158
|
* The 'disableSoftDelete' method is used to disable the soft delete.
|
|
1093
1159
|
*
|
|
@@ -1429,6 +1495,55 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1429
1495
|
withQuery<K extends T.RelationKeys<this>, R extends T.Relations<this>>(nameRelation: K, callback: (query: `$${K & string}` extends keyof R ? R[`$${K & string}`] extends (infer X)[] ? X : R[`$${K & string}`] extends Model ? R[`$${K & string}`] : Model : K extends keyof R ? R[K] extends (infer X)[] ? X : R[K] extends Model ? R[K] : Model : Model) => any, options?: {
|
|
1430
1496
|
pivot: boolean;
|
|
1431
1497
|
}): this;
|
|
1498
|
+
/**
|
|
1499
|
+
*
|
|
1500
|
+
* The 'withQueryExists' method is particularly useful when you want to filter or add conditions records based on related data.
|
|
1501
|
+
*
|
|
1502
|
+
* Use relation '${name}' registry models then return callback queries
|
|
1503
|
+
* @param {string} nameRelation name relation in registry in your model
|
|
1504
|
+
* @param {function} callback query callback
|
|
1505
|
+
* @param {object} options pivot the query
|
|
1506
|
+
* @example
|
|
1507
|
+
* import { Model } from 'tspace-mysql'
|
|
1508
|
+
* class User extends Model {
|
|
1509
|
+
* constructor(){
|
|
1510
|
+
* super()
|
|
1511
|
+
* this.hasMany({ name : 'posts' , model : Post })
|
|
1512
|
+
* }
|
|
1513
|
+
* }
|
|
1514
|
+
*
|
|
1515
|
+
* class Post extends Model {
|
|
1516
|
+
* constructor(){
|
|
1517
|
+
* super()
|
|
1518
|
+
* this.hasMany({ name : 'comments' , model : Comment })
|
|
1519
|
+
* this.belongsTo({ name : 'user' , model : User })
|
|
1520
|
+
* }
|
|
1521
|
+
* }
|
|
1522
|
+
*
|
|
1523
|
+
* class Comment extends Model {
|
|
1524
|
+
* constructor(){
|
|
1525
|
+
* super()
|
|
1526
|
+
* this.hasMany({ name : 'users' , model : User })
|
|
1527
|
+
* this.belongsTo({ name : 'post' , model : Post })
|
|
1528
|
+
* }
|
|
1529
|
+
* }
|
|
1530
|
+
*
|
|
1531
|
+
* await new User().with('posts')
|
|
1532
|
+
* .withQueryExists('posts', (query : Post) => {
|
|
1533
|
+
* return query.with('comments','user')
|
|
1534
|
+
* .withQuery('comments', (query : Comment) => {
|
|
1535
|
+
* return query.with('user','post')
|
|
1536
|
+
* })
|
|
1537
|
+
* .withQueryExists('user', (query : User) => {
|
|
1538
|
+
* return query.with('posts').withQueryExists('posts',(query : Post)=> {
|
|
1539
|
+
* return query.with('comments','user')
|
|
1540
|
+
* // relation n, n, ...n
|
|
1541
|
+
* })
|
|
1542
|
+
* })
|
|
1543
|
+
* })
|
|
1544
|
+
* .findMany()
|
|
1545
|
+
* @returns {this} this
|
|
1546
|
+
*/
|
|
1432
1547
|
withQueryExists<K extends T.RelationKeys<this>, R extends T.Relations<this>>(nameRelation: K, callback: (query: `$${K & string}` extends keyof R ? R[`$${K & string}`] extends (infer X)[] ? X : R[`$${K & string}`] extends Model ? R[`$${K & string}`] : Model : K extends keyof R ? R[K] extends (infer X)[] ? X : R[K] extends Model ? R[K] : Model : Model) => any, options?: {
|
|
1433
1548
|
pivot: boolean;
|
|
1434
1549
|
}): this;
|
|
@@ -1544,6 +1659,23 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1544
1659
|
* @returns {Model} model instance
|
|
1545
1660
|
*/
|
|
1546
1661
|
findWithQuery<K extends T.RelationKeys<this>>(name: K): Model | null;
|
|
1662
|
+
/**
|
|
1663
|
+
* The 'ofMany' method is used to transform a many relationship,
|
|
1664
|
+
* into a single related model by selecting one record using an aggregate
|
|
1665
|
+
* function such as MAX or MIN on the specified column.
|
|
1666
|
+
*
|
|
1667
|
+
* @note
|
|
1668
|
+
* This method is not supported on `belongsToMany` relationships.
|
|
1669
|
+
*
|
|
1670
|
+
* @param {string} column The column used for aggregation (e.g. `"id"`, `"created_at"`).
|
|
1671
|
+
* @param {"MAX" | "MIN"} aggregate The aggregate function used to select the record.
|
|
1672
|
+
* @param {((query: Model) => void) | undefined} callback A callback used to apply additional constraints to the aggregate query.
|
|
1673
|
+
*
|
|
1674
|
+
* Only filtering methods are supported. Methods that modify the result set,
|
|
1675
|
+
* such as `select` `orderBy`, `groupBy`, `limit`, `offset`, `union`, and `having`, are not supported.
|
|
1676
|
+
* @returns this
|
|
1677
|
+
*/
|
|
1678
|
+
ofMany<K extends T.ColumnKeys<this>, S extends Model | unknown, M = S extends this ? this : S extends Model ? S : this>(column: K, aggregate: "MAX" | "MIN", callback?: (query: M) => M): this;
|
|
1547
1679
|
/**
|
|
1548
1680
|
* The 'hasOne' relationship defines a one-to-one relationship between two database tables.
|
|
1549
1681
|
*
|
|
@@ -1636,6 +1768,42 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1636
1768
|
* @returns {this} this
|
|
1637
1769
|
*/
|
|
1638
1770
|
protected belongsToManySingle<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot, }: TRelationOptions<K>): this;
|
|
1771
|
+
/**
|
|
1772
|
+
* The 'createRelation' method is useful for Creates a relation accessor for a model.
|
|
1773
|
+
*
|
|
1774
|
+
* This method defines how a model relates to another model
|
|
1775
|
+
* (hasOne, hasMany, belongsTo, belongsToMany) and returns
|
|
1776
|
+
* a function that can be used to modify the relation query.
|
|
1777
|
+
*
|
|
1778
|
+
* Example:
|
|
1779
|
+
* ```ts
|
|
1780
|
+
* public posts = this.createRelation(Post, {
|
|
1781
|
+
* type: 'hasMany',
|
|
1782
|
+
* foreignKey: 'user_id',
|
|
1783
|
+
* });
|
|
1784
|
+
*
|
|
1785
|
+
* user.posts(q => q.where('id', 1));
|
|
1786
|
+
* ```
|
|
1787
|
+
*
|
|
1788
|
+
* @template M - Target model type
|
|
1789
|
+
* @template K - Optional relation name type
|
|
1790
|
+
*
|
|
1791
|
+
* @param model - The related model constructor
|
|
1792
|
+
* @param options - Relation configuration options
|
|
1793
|
+
* @param options.type - Type of relation (hasOne, hasMany, belongsTo, belongsToMany)
|
|
1794
|
+
* @param options.name - Optional relation name (when applicable)
|
|
1795
|
+
* @param options.as - Alias for relation
|
|
1796
|
+
* @param options.localKey - Local key for the relation
|
|
1797
|
+
* @param options.foreignKey - Foreign key for the relation
|
|
1798
|
+
* @param options.freezeTable - Override pivot/table name
|
|
1799
|
+
* @param options.pivot - Pivot table name (for many-to-many)
|
|
1800
|
+
* @param options.oldVersion - Enable legacy relation behavior
|
|
1801
|
+
*
|
|
1802
|
+
* @returns A function that accepts a query modifier and returns the relation result
|
|
1803
|
+
*/
|
|
1804
|
+
protected createRelation<M extends Model, K = void>(model: new () => M, options: (K extends void ? Omit<TRelationQueryOptions, 'name' | 'model'> & Partial<Pick<TRelationQueryOptions, 'name'>> : Omit<TRelationQueryOptions<K>, 'model'>) & {
|
|
1805
|
+
type: 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany';
|
|
1806
|
+
}): (modifier?: T.QueryModifier<M>) => this;
|
|
1639
1807
|
/**
|
|
1640
1808
|
* The 'hasOneBuilder' method is useful for creating 'hasOne' relationship to function
|
|
1641
1809
|
*
|
|
@@ -1650,7 +1818,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1650
1818
|
* @param {Function?} callback callback of query
|
|
1651
1819
|
* @returns {this} this
|
|
1652
1820
|
*/
|
|
1653
|
-
protected hasOneBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1821
|
+
protected hasOneBuilder<K = void>({ name, as, model, localKey, foreignKey, freezeTable, }: K extends void ? Omit<TRelationQueryOptions, 'name'> & Partial<Pick<TRelationQueryOptions, 'name'>> : TRelationQueryOptions<K>, callback?: Function): this;
|
|
1654
1822
|
/**
|
|
1655
1823
|
* The 'hasManyBuilder' method is useful for creating 'hasMany' relationship to function
|
|
1656
1824
|
*
|
|
@@ -1665,7 +1833,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1665
1833
|
* @param {function?} callback callback of query
|
|
1666
1834
|
* @returns {this} this
|
|
1667
1835
|
*/
|
|
1668
|
-
protected hasManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1836
|
+
protected hasManyBuilder<K = void>({ name, as, model, localKey, foreignKey, freezeTable, }: K extends void ? Omit<TRelationQueryOptions, 'name'> & Partial<Pick<TRelationQueryOptions, 'name'>> : TRelationQueryOptions<K>, callback?: Function): this;
|
|
1669
1837
|
/**
|
|
1670
1838
|
* The 'belongsToBuilder' method is useful for creating 'belongsTo' relationship to function
|
|
1671
1839
|
* @param {object} relation registry relation in your model
|
|
@@ -1679,7 +1847,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1679
1847
|
* @param {function?} callback callback of query
|
|
1680
1848
|
* @returns {this} this
|
|
1681
1849
|
*/
|
|
1682
|
-
protected belongsToBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1850
|
+
protected belongsToBuilder<K = void>({ name, as, model, localKey, foreignKey, freezeTable, }: K extends void ? Omit<TRelationQueryOptions, 'name'> & Partial<Pick<TRelationQueryOptions, 'name'>> : TRelationQueryOptions<K>, callback?: Function): this;
|
|
1683
1851
|
/**
|
|
1684
1852
|
* The 'belongsToManyBuilder' method is useful for creating 'belongsToMany' relationship to function
|
|
1685
1853
|
*
|
|
@@ -1694,7 +1862,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1694
1862
|
* @param {function?} callback callback of query
|
|
1695
1863
|
* @returns {this} this
|
|
1696
1864
|
*/
|
|
1697
|
-
protected belongsToManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot, }: TRelationQueryOptions, callback?: Function): this;
|
|
1865
|
+
protected belongsToManyBuilder<K = void>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot, }: K extends void ? Omit<TRelationQueryOptions, 'name'> & Partial<Pick<TRelationQueryOptions, 'name'>> : TRelationQueryOptions<K>, callback?: Function): this;
|
|
1698
1866
|
/**
|
|
1699
1867
|
* The 'trashed' method is used to specify that you want to retrieve only the soft-deleted records from a database table.
|
|
1700
1868
|
*
|
|
@@ -1727,8 +1895,8 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1727
1895
|
* @returns {string} string
|
|
1728
1896
|
*/
|
|
1729
1897
|
toTableNameAndColumn(column: string): string;
|
|
1730
|
-
where<K extends T.ColumnKeys<this>, V extends
|
|
1731
|
-
where<K extends T.ColumnKeys<this>, V extends
|
|
1898
|
+
where<K extends T.ColumnKeys<this>, V extends T.ColumnValue<this, K>>(column: K, value: V): this;
|
|
1899
|
+
where<K extends T.ColumnKeys<this>, V extends T.ColumnValue<this, K>>(column: K, operator: "=" | "<" | ">" | "!=" | "<>" | "<=" | ">=" | "LIKE" | "like", value: V): this;
|
|
1732
1900
|
where(column: Partial<{
|
|
1733
1901
|
[K in keyof T.ColumnOptions<this>]: T.ColumnOptions<this>[K];
|
|
1734
1902
|
}>): this;
|
|
@@ -1738,7 +1906,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1738
1906
|
* @param {any?} value
|
|
1739
1907
|
* @returns {this} this
|
|
1740
1908
|
*/
|
|
1741
|
-
orWhere<K extends T.ColumnKeys<this>, V extends
|
|
1909
|
+
orWhere<K extends T.ColumnKeys<this>, V extends T.ColumnValue<this, K>>(column: K, value: V): this;
|
|
1742
1910
|
/**
|
|
1743
1911
|
* @override
|
|
1744
1912
|
* @param {string | K} column if arguments is object
|
|
@@ -1746,7 +1914,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1746
1914
|
* @param {any?} value
|
|
1747
1915
|
* @returns {this} this
|
|
1748
1916
|
*/
|
|
1749
|
-
orWhere<K extends T.ColumnKeys<this>, V extends
|
|
1917
|
+
orWhere<K extends T.ColumnKeys<this>, V extends T.ColumnValue<this, K>>(column: K, operator: "=" | "<" | ">" | "!=" | "<>" | "<=" | ">=" | "LIKE" | "like", value: V): this;
|
|
1750
1918
|
/**
|
|
1751
1919
|
* @override
|
|
1752
1920
|
* @param {string} column
|
|
@@ -1887,28 +2055,28 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1887
2055
|
* @param {array} array
|
|
1888
2056
|
* @returns {this}
|
|
1889
2057
|
*/
|
|
1890
|
-
whereBetween<K extends T.ColumnKeys<this>, V extends
|
|
2058
|
+
whereBetween<K extends T.ColumnKeys<this>, V extends T.ColumnValue<this, K>>(column: K, array: [V, V]): this;
|
|
1891
2059
|
/**
|
|
1892
2060
|
* @override
|
|
1893
2061
|
* @param {string} column
|
|
1894
2062
|
* @param {array} array
|
|
1895
2063
|
* @returns {this}
|
|
1896
2064
|
*/
|
|
1897
|
-
orWhereBetween<K extends T.ColumnKeys<this>, V extends
|
|
2065
|
+
orWhereBetween<K extends T.ColumnKeys<this>, V extends T.ColumnValue<this, K>>(column: K, array: [V, V]): this;
|
|
1898
2066
|
/**
|
|
1899
2067
|
* @override
|
|
1900
2068
|
* @param {string} column
|
|
1901
2069
|
* @param {array} array
|
|
1902
2070
|
* @returns {this}
|
|
1903
2071
|
*/
|
|
1904
|
-
whereNotBetween<K extends T.ColumnKeys<this>, V extends
|
|
2072
|
+
whereNotBetween<K extends T.ColumnKeys<this>, V extends T.ColumnValue<this, K>>(column: K, array: [V, V]): this;
|
|
1905
2073
|
/**
|
|
1906
2074
|
* @override
|
|
1907
2075
|
* @param {string} column
|
|
1908
2076
|
* @param {array} array
|
|
1909
2077
|
* @returns {this}
|
|
1910
2078
|
*/
|
|
1911
|
-
orWhereNotBetween<K extends T.ColumnKeys<this>, V extends
|
|
2079
|
+
orWhereNotBetween<K extends T.ColumnKeys<this>, V extends T.ColumnValue<this, K>>(column: K, array: [V, V]): this;
|
|
1912
2080
|
/**
|
|
1913
2081
|
* @override
|
|
1914
2082
|
* @param {string} column
|
|
@@ -1979,7 +2147,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1979
2147
|
* @param {Function} callback callback query
|
|
1980
2148
|
* @returns {this}
|
|
1981
2149
|
*/
|
|
1982
|
-
whereQuery
|
|
2150
|
+
whereQuery(callback: T.QueryModifier<this>): this;
|
|
1983
2151
|
/**
|
|
1984
2152
|
* @override
|
|
1985
2153
|
* @param {Function} callback callback query
|
|
@@ -2013,7 +2181,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2013
2181
|
* @param {string | number | undefined | null | Boolean} condition when condition true will return query callback
|
|
2014
2182
|
* @returns {this} this
|
|
2015
2183
|
*/
|
|
2016
|
-
when
|
|
2184
|
+
when(condition: string | number | undefined | null | boolean, callback: T.QueryModifier<this>): this;
|
|
2017
2185
|
/**
|
|
2018
2186
|
* This 'union' method is used to union statement sql
|
|
2019
2187
|
*
|
|
@@ -2138,28 +2306,28 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2138
2306
|
/**
|
|
2139
2307
|
*
|
|
2140
2308
|
* @override
|
|
2141
|
-
* @param {string=}
|
|
2309
|
+
* @param {string=} c [column=id]
|
|
2142
2310
|
* @returns {promise<number>}
|
|
2143
2311
|
*/
|
|
2144
2312
|
count<K extends T.ColumnKeys<this> | "id" | "_id">(c?: K): Promise<number>;
|
|
2145
2313
|
/**
|
|
2146
2314
|
*
|
|
2147
2315
|
* @override
|
|
2148
|
-
* @param {string=}
|
|
2316
|
+
* @param {string=} c [column=id]
|
|
2149
2317
|
* @returns {promise<number>}
|
|
2150
2318
|
*/
|
|
2151
2319
|
avg<K extends T.ColumnKeys<this> | "id" | "_id">(c?: K): Promise<number>;
|
|
2152
2320
|
/**
|
|
2153
2321
|
*
|
|
2154
2322
|
* @override
|
|
2155
|
-
* @param {string=}
|
|
2323
|
+
* @param {string=} c [column=id]
|
|
2156
2324
|
* @returns {promise<number>}
|
|
2157
2325
|
*/
|
|
2158
2326
|
sum<K extends T.ColumnKeys<this> | "id" | "_id">(c?: K): Promise<number>;
|
|
2159
2327
|
/**
|
|
2160
2328
|
*
|
|
2161
2329
|
* @override
|
|
2162
|
-
* @param {string=}
|
|
2330
|
+
* @param {string=} c [column=id]
|
|
2163
2331
|
* @returns {promise<number>}
|
|
2164
2332
|
*/
|
|
2165
2333
|
max<K extends T.ColumnKeys<this> | "id" | "_id">(c?: K): Promise<number>;
|
|
@@ -2271,28 +2439,30 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2271
2439
|
findMany<K>(cb?: Function): Promise<T.Result<this, K>[]>;
|
|
2272
2440
|
/**
|
|
2273
2441
|
* @override
|
|
2274
|
-
* @param {object?}
|
|
2275
|
-
* @property {number}
|
|
2276
|
-
* @property {number}
|
|
2442
|
+
* @param {object?} opts by default page = 1 , limit = 15
|
|
2443
|
+
* @property {number?} opts.limit
|
|
2444
|
+
* @property {number?} opts.page
|
|
2445
|
+
* @property {boolean?} opts.distinct
|
|
2277
2446
|
* @returns {promise<Pagination>} Pagination
|
|
2278
2447
|
*/
|
|
2279
|
-
pagination<K>(
|
|
2448
|
+
pagination<K>(opts?: {
|
|
2280
2449
|
limit?: number;
|
|
2281
2450
|
page?: number;
|
|
2282
|
-
|
|
2451
|
+
distinct?: boolean;
|
|
2283
2452
|
}): Promise<T.PaginateResult<this, K>>;
|
|
2284
2453
|
/**
|
|
2285
2454
|
*
|
|
2286
2455
|
* @override
|
|
2287
|
-
* @param {?object}
|
|
2288
|
-
* @property {number}
|
|
2289
|
-
* @property {number}
|
|
2456
|
+
* @param {?object} opts by default page = 1 , limit = 15
|
|
2457
|
+
* @property {number?} opts.limit
|
|
2458
|
+
* @property {number?} opts.page
|
|
2459
|
+
* @property {boolean?} opts.distinct
|
|
2290
2460
|
* @returns {promise<Pagination>} Pagination
|
|
2291
2461
|
*/
|
|
2292
|
-
paginate<K>(
|
|
2462
|
+
paginate<K>(opts?: {
|
|
2293
2463
|
limit?: number;
|
|
2294
2464
|
page?: number;
|
|
2295
|
-
|
|
2465
|
+
distinct?: boolean;
|
|
2296
2466
|
}): Promise<T.PaginateResult<this, K>>;
|
|
2297
2467
|
/**
|
|
2298
2468
|
* @override
|
|
@@ -2323,29 +2493,27 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2323
2493
|
* @param {object} data for insert
|
|
2324
2494
|
* @returns {this} this
|
|
2325
2495
|
*/
|
|
2326
|
-
insert<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data:
|
|
2327
|
-
[P in Exclude<K & keyof C, "id" | "_id" | "uuid"> as null extends C[P] ? any : P]: Extract<C[P], Date> extends never ? Extract<C[P], Record<string, unknown>> extends never ? C[P] : string : any;
|
|
2328
|
-
}): this;
|
|
2496
|
+
insert<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): Model<TS, TR, "create">;
|
|
2329
2497
|
/**
|
|
2330
2498
|
* @override
|
|
2331
2499
|
* @param {object} data for insert
|
|
2332
2500
|
* @returns {this} this
|
|
2333
2501
|
*/
|
|
2334
|
-
create<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>):
|
|
2502
|
+
create<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): Model<TS, TR, "create">;
|
|
2335
2503
|
/**
|
|
2336
2504
|
* @override
|
|
2337
2505
|
* @param {object} data
|
|
2338
2506
|
* @param {array?} updateNotExists options for except update some records in your ${data}
|
|
2339
2507
|
* @returns {this} this
|
|
2340
2508
|
*/
|
|
2341
|
-
update<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>, updateNotExists?: T.ColumnKeys<this>[]):
|
|
2509
|
+
update<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>, updateNotExists?: T.ColumnKeys<this>[]): Model<TS, TR, "update">;
|
|
2342
2510
|
/**
|
|
2343
2511
|
* @override
|
|
2344
2512
|
* @param {object} data
|
|
2345
2513
|
* @param {array?} updateNotExists options for except update some records in your ${data}
|
|
2346
2514
|
* @returns {this} this
|
|
2347
2515
|
*/
|
|
2348
|
-
updateMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>, updateNotExists?: string[]):
|
|
2516
|
+
updateMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>, updateNotExists?: string[]): Model<TS, TR, "updateMany">;
|
|
2349
2517
|
/**
|
|
2350
2518
|
*
|
|
2351
2519
|
* @override
|
|
@@ -2365,90 +2533,90 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2365
2533
|
columns: Partial<{
|
|
2366
2534
|
[P in K & keyof T]: Extract<T[P], Record<string, unknown>> extends never ? T[P] : string;
|
|
2367
2535
|
}>;
|
|
2368
|
-
}[]):
|
|
2536
|
+
}[]): Model<TS, TR, "updateMany">;
|
|
2369
2537
|
/**
|
|
2370
2538
|
* @override
|
|
2371
2539
|
* @param {object} data
|
|
2372
2540
|
* @returns {this} this
|
|
2373
2541
|
*/
|
|
2374
|
-
updateNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>):
|
|
2542
|
+
updateNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>): Model<TS, TR, "update">;
|
|
2375
2543
|
/**
|
|
2376
2544
|
* @override
|
|
2377
2545
|
* @param {object} data for update or create
|
|
2378
2546
|
* @returns {this} this
|
|
2379
2547
|
*/
|
|
2380
|
-
updateOrCreate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.
|
|
2548
|
+
updateOrCreate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertOrUpdateInput<K, C>): Model<TS, TR, "createOrUpdate">;
|
|
2381
2549
|
/**
|
|
2382
2550
|
* @override
|
|
2383
2551
|
* @param {object} data for update or create
|
|
2384
2552
|
* @returns {this} this
|
|
2385
2553
|
*/
|
|
2386
|
-
updateOrInsert<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.
|
|
2554
|
+
updateOrInsert<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertOrUpdateInput<K, C>): Model<TS, TR, "createOrUpdate">;
|
|
2387
2555
|
/**
|
|
2388
2556
|
* @override
|
|
2389
2557
|
* @param {object} data for update or create
|
|
2390
2558
|
* @returns {this} this
|
|
2391
2559
|
*/
|
|
2392
|
-
insertOrUpdate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.
|
|
2560
|
+
insertOrUpdate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertOrUpdateInput<K, C>): Model<TS, TR, "createOrUpdate">;
|
|
2393
2561
|
/**
|
|
2394
2562
|
* @override
|
|
2395
2563
|
* @param {object} data for update or create
|
|
2396
2564
|
* @returns {this} this
|
|
2397
2565
|
*/
|
|
2398
|
-
createOrUpdate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.
|
|
2566
|
+
createOrUpdate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertOrUpdateInput<K, C>): Model<TS, TR, "createOrUpdate">;
|
|
2399
2567
|
/**
|
|
2400
2568
|
* @override
|
|
2401
2569
|
* @param {object} data for create
|
|
2402
2570
|
* @returns {this} this
|
|
2403
2571
|
*/
|
|
2404
|
-
createOrSelect<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>):
|
|
2572
|
+
createOrSelect<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): Model<TS, TR, "createOrSelect">;
|
|
2405
2573
|
/**
|
|
2406
2574
|
* @override
|
|
2407
2575
|
* @param {object} data for update or create
|
|
2408
2576
|
* @returns {this} this
|
|
2409
2577
|
*/
|
|
2410
|
-
insertOrSelect<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>):
|
|
2578
|
+
insertOrSelect<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): Model<TS, TR, "createOrSelect">;
|
|
2411
2579
|
/**
|
|
2412
2580
|
*
|
|
2413
2581
|
* @override
|
|
2414
2582
|
* @param {object} data create not exists data
|
|
2415
2583
|
* @returns {this} this
|
|
2416
2584
|
*/
|
|
2417
|
-
createNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>):
|
|
2585
|
+
createNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): Model<TS, TR, "createNotExists">;
|
|
2418
2586
|
/**
|
|
2419
2587
|
*
|
|
2420
2588
|
* @override
|
|
2421
2589
|
* @param {object} data create not exists data
|
|
2422
2590
|
* @returns {this} this this
|
|
2423
2591
|
*/
|
|
2424
|
-
insertNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>):
|
|
2592
|
+
insertNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): Model<TS, TR, "createNotExists">;
|
|
2425
2593
|
/**
|
|
2426
2594
|
* @override
|
|
2427
2595
|
* @param {Record<string,any>[]} data create multiple data
|
|
2428
2596
|
* @returns {this} this this
|
|
2429
2597
|
*/
|
|
2430
|
-
createMultiple<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]):
|
|
2598
|
+
createMultiple<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]): Model<TS, TR, "createMany">;
|
|
2431
2599
|
/**
|
|
2432
2600
|
*
|
|
2433
2601
|
* @override
|
|
2434
2602
|
* @param {Record<string,any>[]} data create multiple data
|
|
2435
2603
|
* @returns {this} this
|
|
2436
2604
|
*/
|
|
2437
|
-
createMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]):
|
|
2605
|
+
createMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]): Model<TS, TR, "createMany">;
|
|
2438
2606
|
/**
|
|
2439
2607
|
*
|
|
2440
2608
|
* @override
|
|
2441
2609
|
* @param {Record<string,any>[]} data create multiple data
|
|
2442
2610
|
* @returns {this} this
|
|
2443
2611
|
*/
|
|
2444
|
-
insertMultiple<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]):
|
|
2612
|
+
insertMultiple<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]): Model<TS, TR, "createMany">;
|
|
2445
2613
|
/**
|
|
2446
2614
|
*
|
|
2447
2615
|
* @override
|
|
2448
2616
|
* @param {Record<string,any>[]} data create multiple data
|
|
2449
2617
|
* @returns {this} this
|
|
2450
2618
|
*/
|
|
2451
|
-
insertMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]):
|
|
2619
|
+
insertMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]): Model<TS, TR, "createMany">;
|
|
2452
2620
|
/**
|
|
2453
2621
|
* The 'getSchemaModel' method is used get a schema model
|
|
2454
2622
|
* @returns {Record<string, Blueprint> | null} Record<string, Blueprint> | null
|
|
@@ -2472,7 +2640,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2472
2640
|
*/
|
|
2473
2641
|
save({ waitMs }?: {
|
|
2474
2642
|
waitMs?: number | undefined;
|
|
2475
|
-
}): Promise<
|
|
2643
|
+
}): Promise<TSaveModelResult<this, TA>>;
|
|
2476
2644
|
/**
|
|
2477
2645
|
*
|
|
2478
2646
|
* @override
|
|
@@ -2533,7 +2701,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2533
2701
|
* generate sql statements
|
|
2534
2702
|
* @override
|
|
2535
2703
|
*/
|
|
2536
|
-
protected _queryBuilder():
|
|
2704
|
+
protected _queryBuilder(): QueryBuilder;
|
|
2537
2705
|
private _runBefore;
|
|
2538
2706
|
private _runAfter;
|
|
2539
2707
|
private _validateSchema;
|