tspace-mysql 1.8.2 → 1.8.4
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 +443 -68
- package/build/cli/generate/model.js +3 -3
- package/build/cli/generate/model.js.map +1 -1
- package/build/lib/constants/index.d.ts +7 -1
- package/build/lib/constants/index.js +7 -1
- package/build/lib/constants/index.js.map +1 -1
- package/build/lib/core/Abstracts/AbstractBuilder.d.ts +1 -1
- package/build/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
- package/build/lib/core/Abstracts/AbstractDB.d.ts +2 -2
- package/build/lib/core/Abstracts/AbstractDB.js.map +1 -1
- package/build/lib/core/Abstracts/AbstractView.d.ts +10 -0
- package/build/lib/core/Abstracts/AbstractView.js +9 -0
- package/build/lib/core/Abstracts/AbstractView.js.map +1 -0
- package/build/lib/core/Blueprint.d.ts +24 -4
- package/build/lib/core/Blueprint.js +78 -87
- package/build/lib/core/Blueprint.js.map +1 -1
- package/build/lib/core/Builder.d.ts +39 -30
- package/build/lib/core/Builder.js +1094 -1044
- package/build/lib/core/Builder.js.map +1 -1
- package/build/lib/core/Cache/DBCache.js +15 -16
- package/build/lib/core/Cache/DBCache.js.map +1 -1
- package/build/lib/core/DB.d.ts +38 -38
- package/build/lib/core/DB.js +119 -115
- package/build/lib/core/DB.js.map +1 -1
- package/build/lib/core/Decorator.d.ts +1 -1
- package/build/lib/core/Decorator.js.map +1 -1
- package/build/lib/core/Handlers/Relation.d.ts +2 -1
- package/build/lib/core/Handlers/Relation.js +60 -15
- package/build/lib/core/Handlers/Relation.js.map +1 -1
- package/build/lib/core/Handlers/State.d.ts +1 -0
- package/build/lib/core/Handlers/State.js +1 -1
- package/build/lib/core/Handlers/State.js.map +1 -1
- package/build/lib/core/JoinModel.d.ts +1 -1
- package/build/lib/core/JoinModel.js.map +1 -1
- package/build/lib/core/Meta.d.ts +55 -0
- package/build/lib/core/Meta.js +175 -0
- package/build/lib/core/Meta.js.map +1 -0
- package/build/lib/core/Model.d.ts +158 -94
- package/build/lib/core/Model.js +1586 -1203
- package/build/lib/core/Model.js.map +1 -1
- package/build/lib/core/Nest/index.d.ts +3 -1
- package/build/lib/core/Nest/index.js +4 -2
- package/build/lib/core/Nest/index.js.map +1 -1
- package/build/lib/{connection/index.d.ts → core/Pool.d.ts} +2 -1
- package/build/lib/{connection/index.js → core/Pool.js} +74 -6
- package/build/lib/core/Pool.js.map +1 -0
- package/build/lib/core/Repository.d.ts +16 -16
- package/build/lib/core/Repository.js +73 -45
- package/build/lib/core/Repository.js.map +1 -1
- package/build/lib/core/Schema.d.ts +2 -2
- package/build/lib/core/Schema.js +113 -78
- package/build/lib/core/Schema.js.map +1 -1
- package/build/lib/core/SqlLike.js.map +1 -1
- package/build/lib/core/StoredProcedure.d.ts +120 -0
- package/build/lib/core/StoredProcedure.js +161 -0
- package/build/lib/core/StoredProcedure.js.map +1 -0
- package/build/lib/core/UtilityTypes.d.ts +25 -44
- package/build/lib/core/View.d.ts +96 -0
- package/build/lib/core/View.js +141 -0
- package/build/lib/core/View.js.map +1 -0
- package/build/lib/core/index.d.ts +17 -12
- package/build/lib/core/index.js +9 -4
- package/build/lib/core/index.js.map +1 -1
- package/build/lib/types/index.d.ts +23 -3
- package/build/lib/utils/index.js +5 -2
- package/build/lib/utils/index.js.map +1 -1
- package/build/tests/01-Pool.test.js +0 -10
- package/build/tests/01-Pool.test.js.map +1 -1
- package/build/tests/04-Model-pattern.test.js +1 -1
- package/build/tests/04-Model-pattern.test.js.map +1 -1
- package/build/tests/05-View.test.d.ts +1 -0
- package/build/tests/05-View.test.js +83 -0
- package/build/tests/05-View.test.js.map +1 -0
- package/build/tests/06-Meta.test.d.ts +1 -0
- package/build/tests/06-Meta.test.js +103 -0
- package/build/tests/06-Meta.test.js.map +1 -0
- package/build/tests/07-Virtual-column.test.d.ts +1 -0
- package/build/tests/07-Virtual-column.test.js +160 -0
- package/build/tests/07-Virtual-column.test.js.map +1 -0
- package/build/tests/schema-spec.js +25 -25
- package/build/tests/schema-spec.js.map +1 -1
- package/package.json +1 -1
- package/build/lib/connection/index.js.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { AbstractModel } from
|
|
2
|
-
import { Blueprint } from
|
|
3
|
-
import { TSchemaModel } from
|
|
4
|
-
import { JoinModel } from
|
|
5
|
-
import
|
|
1
|
+
import { AbstractModel } from "./Abstracts/AbstractModel";
|
|
2
|
+
import { Blueprint } from "./Blueprint";
|
|
3
|
+
import { TSchemaModel } from "./UtilityTypes";
|
|
4
|
+
import { JoinModel } from "./JoinModel";
|
|
5
|
+
import { CONSTANTS } from "../constants";
|
|
6
|
+
import type { TCache, TRelationOptions, TPagination, TRelationQueryOptions, TValidateSchema, TGlobalSetting, TRawStringQuery, TFreezeStringQuery, TPattern, TSchemaKeys, TSchemaColumns, TModelConstructorOrObject, TRelationResults, TRelationKeys } from "../types";
|
|
6
7
|
/**
|
|
7
8
|
*
|
|
8
9
|
* 'Model' class is a representation of a database table
|
|
@@ -75,7 +76,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
75
76
|
* @property {string} parttern
|
|
76
77
|
* @returns {Record | string} T
|
|
77
78
|
*/
|
|
78
|
-
static formatPattern<T extends Record<string, any> | string>({ data, pattern }: {
|
|
79
|
+
static formatPattern<T extends Record<string, any> | string>({ data, pattern, }: {
|
|
79
80
|
data: T;
|
|
80
81
|
pattern: TPattern;
|
|
81
82
|
}): T;
|
|
@@ -91,6 +92,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
91
92
|
* @returns {TCache} cache
|
|
92
93
|
*/
|
|
93
94
|
static get cache(): TCache;
|
|
95
|
+
protected useMiddleware(func: Function): this;
|
|
94
96
|
/**
|
|
95
97
|
* The 'globalScope' method is a feature that allows you to apply query constraints to all queries for a given model.
|
|
96
98
|
*
|
|
@@ -177,28 +179,28 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
177
179
|
deleted: Function;
|
|
178
180
|
}): this;
|
|
179
181
|
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
protected useLogger({ selected, inserted, updated, deleted }?: {
|
|
182
|
+
* The "useLogger" method is used to keeping query data and changed in models.
|
|
183
|
+
*
|
|
184
|
+
* @type {object} options
|
|
185
|
+
* @property {boolean} options.selected - default is false
|
|
186
|
+
* @property {boolean} options.inserted - default is true
|
|
187
|
+
* @property {boolean} options.updated - default is true
|
|
188
|
+
* @property {boolean} options.deleted - default is true
|
|
189
|
+
* @example
|
|
190
|
+
* class User extends Model {
|
|
191
|
+
* constructor() {
|
|
192
|
+
* super()
|
|
193
|
+
* this.useLogger({
|
|
194
|
+
* selected : true,
|
|
195
|
+
* inserted : true,
|
|
196
|
+
* updated : true,
|
|
197
|
+
* deleted : true,
|
|
198
|
+
* })
|
|
199
|
+
* }
|
|
200
|
+
* }
|
|
201
|
+
* @returns {this} this
|
|
202
|
+
*/
|
|
203
|
+
protected useLogger({ selected, inserted, updated, deleted, }?: {
|
|
202
204
|
selected?: boolean | undefined;
|
|
203
205
|
inserted?: boolean | undefined;
|
|
204
206
|
updated?: boolean | undefined;
|
|
@@ -485,7 +487,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
485
487
|
* this.useHook([(results) => console.log(results)])
|
|
486
488
|
* }
|
|
487
489
|
* }
|
|
488
|
-
|
|
490
|
+
*/
|
|
489
491
|
protected useHooks(arrayFunctions: Function[]): this;
|
|
490
492
|
/**
|
|
491
493
|
* The "beforeCreatingTable" method is used exection function when creating the table.
|
|
@@ -503,7 +505,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
503
505
|
* })
|
|
504
506
|
* }
|
|
505
507
|
* }
|
|
506
|
-
|
|
508
|
+
*/
|
|
507
509
|
protected beforeCreatingTable(fn: () => Promise<any>): this;
|
|
508
510
|
/**
|
|
509
511
|
* The "whenCreatingTable" method is used exection function when creating the table.
|
|
@@ -521,7 +523,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
521
523
|
* })
|
|
522
524
|
* }
|
|
523
525
|
* }
|
|
524
|
-
|
|
526
|
+
*/
|
|
525
527
|
protected whenCreatingTable(fn: () => Promise<any>): this;
|
|
526
528
|
/**
|
|
527
529
|
* exceptColumns for method except
|
|
@@ -536,7 +538,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
536
538
|
* @returns {this} this
|
|
537
539
|
*/
|
|
538
540
|
protected buildMethodRelation<K extends TR extends object ? TRelationKeys<TR> : string>(name: K, callback?: Function): this;
|
|
539
|
-
meta(meta:
|
|
541
|
+
meta(meta: "MAIN" | "SUBORDINATE"): this;
|
|
540
542
|
/**
|
|
541
543
|
* The 'typeOfSchema' method is used get type of schema.
|
|
542
544
|
* @returns {TS} type of schema
|
|
@@ -564,7 +566,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
564
566
|
* @param {string[]} ...columns
|
|
565
567
|
* @returns {this} this
|
|
566
568
|
*/
|
|
567
|
-
select<K extends Extract<TSchemaKeys<TS>, string> | `${string}.${string}` | TRawStringQuery |
|
|
569
|
+
select<K extends Extract<TSchemaKeys<TS>, string> | `${string}.${string}` | TRawStringQuery | "*">(...columns: K[]): this;
|
|
568
570
|
/**
|
|
569
571
|
*
|
|
570
572
|
* @override
|
|
@@ -592,7 +594,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
592
594
|
* @param {string?} order by default order = 'asc' but you can used 'asc' or 'desc'
|
|
593
595
|
* @returns {this}
|
|
594
596
|
*/
|
|
595
|
-
orderBy<K extends Extract<TSchemaKeys<TS>, string> | `${string}.${string}`>(column: K, order?:
|
|
597
|
+
orderBy<K extends Extract<TSchemaKeys<TS>, string> | `${string}.${string}`>(column: K, order?: "ASC" | "asc" | "DESC" | "desc"): this;
|
|
596
598
|
/**
|
|
597
599
|
*
|
|
598
600
|
* @override
|
|
@@ -702,7 +704,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
702
704
|
* @property {Function} actions.returnId
|
|
703
705
|
* @returns {this} this
|
|
704
706
|
*/
|
|
705
|
-
protected _actionStatement({ sql, returnId }: {
|
|
707
|
+
protected _actionStatement({ sql, returnId, }: {
|
|
706
708
|
sql: string;
|
|
707
709
|
returnId?: boolean;
|
|
708
710
|
}): Promise<any>;
|
|
@@ -721,7 +723,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
721
723
|
*/
|
|
722
724
|
disableSoftDelete(condition?: boolean): this;
|
|
723
725
|
/**
|
|
724
|
-
|
|
726
|
+
* The 'ignoreSoftDelete' method is used to disable the soft delete.
|
|
725
727
|
* @param {boolean} condition
|
|
726
728
|
* @returns {this} this
|
|
727
729
|
*/
|
|
@@ -876,9 +878,6 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
876
878
|
* @returns {this} this
|
|
877
879
|
* @example
|
|
878
880
|
* import { Model } from 'tspace-mysql'
|
|
879
|
-
import { alias } from 'yargs';
|
|
880
|
-
* import { pattern } from '../../tests/schema-spec';
|
|
881
|
-
* import { TRelationOptions } from '../types';
|
|
882
881
|
* class User extends Model {
|
|
883
882
|
* constructor(){
|
|
884
883
|
* super()
|
|
@@ -906,8 +905,6 @@ import { alias } from 'yargs';
|
|
|
906
905
|
* @returns {this} this
|
|
907
906
|
* @example
|
|
908
907
|
* import { Model } from 'tspace-mysql'
|
|
909
|
-
* import utils from '../utils/index';
|
|
910
|
-
* import { TRelationOptions } from '../types';
|
|
911
908
|
* class User extends Model {
|
|
912
909
|
* constructor(){
|
|
913
910
|
* super()
|
|
@@ -1062,6 +1059,9 @@ import { alias } from 'yargs';
|
|
|
1062
1059
|
withQuery<K extends TR extends object ? TRelationKeys<TR> : string, M = `$${K & string}` extends keyof TR ? TR[`$${K & string}`] extends (infer T)[] ? T : TR[`$${K & string}`] : Model>(nameRelation: K, callback: (query: M) => M, options?: {
|
|
1063
1060
|
pivot: boolean;
|
|
1064
1061
|
}): this;
|
|
1062
|
+
withQueryExists<K extends TR extends object ? TRelationKeys<TR> : string, M = `$${K & string}` extends keyof TR ? TR[`$${K & string}`] extends (infer T)[] ? T : TR[`$${K & string}`] : Model>(nameRelation: K, callback: (query: M) => M, options?: {
|
|
1063
|
+
pivot: boolean;
|
|
1064
|
+
}): this;
|
|
1065
1065
|
/**
|
|
1066
1066
|
*
|
|
1067
1067
|
* The 'relationQuery' method is particularly useful when you want to filter or add conditions records based on related data.
|
|
@@ -1114,6 +1114,58 @@ import { alias } from 'yargs';
|
|
|
1114
1114
|
relationQuery<K extends TR extends object ? TRelationKeys<TR> : string, M = `$${K & string}` extends keyof TR ? TR[`$${K & string}`] extends (infer T)[] ? T : TR[`$${K & string}`] : Model>(nameRelation: K, callback: (query: M) => M, options?: {
|
|
1115
1115
|
pivot: boolean;
|
|
1116
1116
|
}): this;
|
|
1117
|
+
/**
|
|
1118
|
+
*
|
|
1119
|
+
* The 'relationQueryExists' method is particularly useful when you want to filter or add conditions records based on related data.
|
|
1120
|
+
*
|
|
1121
|
+
* Use relation '${name}' registry models then return callback queries
|
|
1122
|
+
* @param {string} nameRelation name relation in registry in your model
|
|
1123
|
+
* @param {function} callback query callback
|
|
1124
|
+
* @param {object} options pivot the query
|
|
1125
|
+
* @example
|
|
1126
|
+
* import { Model } from 'tspace-mysql'
|
|
1127
|
+
* class User extends Model {
|
|
1128
|
+
* constructor(){
|
|
1129
|
+
* super()
|
|
1130
|
+
* this.hasMany({ name : 'posts' , model : Post })
|
|
1131
|
+
* }
|
|
1132
|
+
* }
|
|
1133
|
+
*
|
|
1134
|
+
* class Post extends Model {
|
|
1135
|
+
* constructor(){
|
|
1136
|
+
* super()
|
|
1137
|
+
* this.hasMany({ name : 'comments' , model : Comment })
|
|
1138
|
+
* this.belongsTo({ name : 'user' , model : User })
|
|
1139
|
+
* }
|
|
1140
|
+
* }
|
|
1141
|
+
*
|
|
1142
|
+
* class Comment extends Model {
|
|
1143
|
+
* constructor(){
|
|
1144
|
+
* super()
|
|
1145
|
+
* this.hasMany({ name : 'users' , model : User })
|
|
1146
|
+
* this.belongsTo({ name : 'post' , model : Post })
|
|
1147
|
+
* }
|
|
1148
|
+
* }
|
|
1149
|
+
*
|
|
1150
|
+
* await new User().relations('posts')
|
|
1151
|
+
* .relationQuery('posts', (query : Post) => {
|
|
1152
|
+
* return query.relations('comments','user')
|
|
1153
|
+
* .relationQuery('comments', (query : Comment) => {
|
|
1154
|
+
* return query.relations('user','post')
|
|
1155
|
+
* })
|
|
1156
|
+
* .relationQuery('user', (query : User) => {
|
|
1157
|
+
* return query.relations('posts').relationsQuery('posts',(query : Post)=> {
|
|
1158
|
+
* return query.relations('comments','user')
|
|
1159
|
+
* // relation n, n, ...n
|
|
1160
|
+
* })
|
|
1161
|
+
* })
|
|
1162
|
+
* })
|
|
1163
|
+
* .findMany()
|
|
1164
|
+
* @returns {this} this
|
|
1165
|
+
*/
|
|
1166
|
+
relationQueryExists<K extends TR extends object ? TRelationKeys<TR> : string, M = `$${K & string}` extends keyof TR ? TR[`$${K & string}`] extends (infer T)[] ? T : TR[`$${K & string}`] : Model>(nameRelation: K, callback: (query: M) => M, options?: {
|
|
1167
|
+
pivot: boolean;
|
|
1168
|
+
}): this;
|
|
1117
1169
|
/**
|
|
1118
1170
|
*
|
|
1119
1171
|
* The 'findWithQuery' method is used to find instance call back from relation.
|
|
@@ -1138,7 +1190,7 @@ import { alias } from 'yargs';
|
|
|
1138
1190
|
* @property {string} relation.freezeTable
|
|
1139
1191
|
* @returns {this} this
|
|
1140
1192
|
*/
|
|
1141
|
-
protected hasOne<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
|
|
1193
|
+
protected hasOne<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationOptions<K>): this;
|
|
1142
1194
|
/**
|
|
1143
1195
|
* The 'hasMany' relationship defines a one-to-many relationship between two database tables.
|
|
1144
1196
|
*
|
|
@@ -1155,7 +1207,7 @@ import { alias } from 'yargs';
|
|
|
1155
1207
|
* @property {string} relation.freezeTable
|
|
1156
1208
|
* @returns {this} this
|
|
1157
1209
|
*/
|
|
1158
|
-
protected hasMany<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
|
|
1210
|
+
protected hasMany<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationOptions<K>): this;
|
|
1159
1211
|
/**
|
|
1160
1212
|
* The 'belongsTo' relationship defines a one-to-one or many-to-one relationship between two database tables.
|
|
1161
1213
|
*
|
|
@@ -1172,7 +1224,7 @@ import { alias } from 'yargs';
|
|
|
1172
1224
|
* @property {string} relation.freezeTable
|
|
1173
1225
|
* @returns {this} this
|
|
1174
1226
|
*/
|
|
1175
|
-
protected belongsTo<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
|
|
1227
|
+
protected belongsTo<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationOptions<K>): this;
|
|
1176
1228
|
/**
|
|
1177
1229
|
* The 'belongsToMany' relationship defines a many-to-many relationship between two database tables.
|
|
1178
1230
|
*
|
|
@@ -1192,7 +1244,7 @@ import { alias } from 'yargs';
|
|
|
1192
1244
|
* @property {class?} relation.modelPivot model for pivot
|
|
1193
1245
|
* @returns {this} this
|
|
1194
1246
|
*/
|
|
1195
|
-
protected belongsToMany<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }: TRelationOptions<K>): this;
|
|
1247
|
+
protected belongsToMany<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot, }: TRelationOptions<K>): this;
|
|
1196
1248
|
/**
|
|
1197
1249
|
* The 'hasOneBuilder' method is useful for creating 'hasOne' relationship to function
|
|
1198
1250
|
*
|
|
@@ -1207,7 +1259,7 @@ import { alias } from 'yargs';
|
|
|
1207
1259
|
* @param {Function?} callback callback of query
|
|
1208
1260
|
* @returns {this} this
|
|
1209
1261
|
*/
|
|
1210
|
-
protected hasOneBuilder({ name, as, model, localKey, foreignKey, freezeTable }: TRelationQueryOptions, callback?: Function): this;
|
|
1262
|
+
protected hasOneBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1211
1263
|
/**
|
|
1212
1264
|
* The 'hasManyBuilder' method is useful for creating 'hasMany' relationship to function
|
|
1213
1265
|
*
|
|
@@ -1222,7 +1274,7 @@ import { alias } from 'yargs';
|
|
|
1222
1274
|
* @param {function?} callback callback of query
|
|
1223
1275
|
* @returns {this} this
|
|
1224
1276
|
*/
|
|
1225
|
-
protected hasManyBuilder({ name, as, model, localKey, foreignKey, freezeTable }: TRelationQueryOptions, callback?: Function): this;
|
|
1277
|
+
protected hasManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1226
1278
|
/**
|
|
1227
1279
|
* The 'belongsToBuilder' method is useful for creating 'belongsTo' relationship to function
|
|
1228
1280
|
* @param {object} relation registry relation in your model
|
|
@@ -1236,7 +1288,7 @@ import { alias } from 'yargs';
|
|
|
1236
1288
|
* @param {function?} callback callback of query
|
|
1237
1289
|
* @returns {this} this
|
|
1238
1290
|
*/
|
|
1239
|
-
protected belongsToBuilder({ name, as, model, localKey, foreignKey, freezeTable }: TRelationQueryOptions, callback?: Function): this;
|
|
1291
|
+
protected belongsToBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1240
1292
|
/**
|
|
1241
1293
|
* The 'belongsToManyBuilder' method is useful for creating 'belongsToMany' relationship to function
|
|
1242
1294
|
*
|
|
@@ -1251,7 +1303,7 @@ import { alias } from 'yargs';
|
|
|
1251
1303
|
* @param {function?} callback callback of query
|
|
1252
1304
|
* @returns {this} this
|
|
1253
1305
|
*/
|
|
1254
|
-
protected belongsToManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }: TRelationQueryOptions, callback?: Function): this;
|
|
1306
|
+
protected belongsToManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot, }: TRelationQueryOptions, callback?: Function): this;
|
|
1255
1307
|
/**
|
|
1256
1308
|
* The 'trashed' method is used to specify that you want to retrieve only the soft-deleted records from a database table.
|
|
1257
1309
|
*
|
|
@@ -1332,14 +1384,14 @@ import { alias } from 'yargs';
|
|
|
1332
1384
|
[P in K]: any;
|
|
1333
1385
|
}): this;
|
|
1334
1386
|
/**
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1387
|
+
* @override
|
|
1388
|
+
* @param {string} column
|
|
1389
|
+
* @param {object} property object { key , value , operator }
|
|
1390
|
+
* @property {string} property.key
|
|
1391
|
+
* @property {string} property.value
|
|
1392
|
+
* @property {string?} property.operator
|
|
1393
|
+
* @returns {this}
|
|
1394
|
+
*/
|
|
1343
1395
|
whereJSON<K extends TSchemaColumns<TS>>(column: K, { key, value, operator }: {
|
|
1344
1396
|
key: string;
|
|
1345
1397
|
value: string;
|
|
@@ -1400,28 +1452,36 @@ import { alias } from 'yargs';
|
|
|
1400
1452
|
* @param {string} subQuery
|
|
1401
1453
|
* @returns {this}
|
|
1402
1454
|
*/
|
|
1403
|
-
whereSubQuery<K extends TSchemaColumns<TS>>(column: K, subQuery: string
|
|
1455
|
+
whereSubQuery<K extends TSchemaColumns<TS>>(column: K, subQuery: string, options?: {
|
|
1456
|
+
operator?: (typeof CONSTANTS)["EQ"] | (typeof CONSTANTS)["IN"];
|
|
1457
|
+
}): this;
|
|
1404
1458
|
/**
|
|
1405
1459
|
* @override
|
|
1406
1460
|
* @param {string} column
|
|
1407
1461
|
* @param {string} subQuery
|
|
1408
1462
|
* @returns {this}
|
|
1409
1463
|
*/
|
|
1410
|
-
whereNotSubQuery<K extends TSchemaColumns<TS>>(column: K, subQuery: string
|
|
1464
|
+
whereNotSubQuery<K extends TSchemaColumns<TS>>(column: K, subQuery: string, options?: {
|
|
1465
|
+
operator?: (typeof CONSTANTS)["NOT_EQ"] | (typeof CONSTANTS)["NOT_IN"];
|
|
1466
|
+
}): this;
|
|
1411
1467
|
/**
|
|
1412
1468
|
* @override
|
|
1413
1469
|
* @param {string} column
|
|
1414
1470
|
* @param {string} subQuery
|
|
1415
1471
|
* @returns {this}
|
|
1416
1472
|
*/
|
|
1417
|
-
orWhereSubQuery<K extends TSchemaColumns<TS>>(column: K, subQuery: string
|
|
1473
|
+
orWhereSubQuery<K extends TSchemaColumns<TS>>(column: K, subQuery: string, options?: {
|
|
1474
|
+
operator?: (typeof CONSTANTS)["EQ"] | (typeof CONSTANTS)["IN"];
|
|
1475
|
+
}): this;
|
|
1418
1476
|
/**
|
|
1419
1477
|
* @override
|
|
1420
1478
|
* @param {string} column
|
|
1421
1479
|
* @param {string} subQuery
|
|
1422
1480
|
* @returns {this}
|
|
1423
1481
|
*/
|
|
1424
|
-
orWhereNotSubQuery<K extends TSchemaColumns<TS>>(column: K, subQuery: string
|
|
1482
|
+
orWhereNotSubQuery<K extends TSchemaColumns<TS>>(column: K, subQuery: string, options?: {
|
|
1483
|
+
operator?: (typeof CONSTANTS)["NOT_EQ"] | (typeof CONSTANTS)["NOT_IN"];
|
|
1484
|
+
}): this;
|
|
1425
1485
|
/**
|
|
1426
1486
|
* @override
|
|
1427
1487
|
* @param {string} column
|
|
@@ -1498,6 +1558,7 @@ import { alias } from 'yargs';
|
|
|
1498
1558
|
* @returns {this}
|
|
1499
1559
|
*/
|
|
1500
1560
|
orWhereSensitive<K extends TSchemaColumns<TS>>(column: K, operator?: any, value?: any): this;
|
|
1561
|
+
whereHas<K extends TR extends object ? TRelationKeys<TR> : string, M = `$${K & string}` extends keyof TR ? TR[`$${K & string}`] extends (infer T)[] ? T : TR[`$${K & string}`] : Model>(nameRelation: K, callback: (query: M) => M): this;
|
|
1501
1562
|
/**
|
|
1502
1563
|
* @override
|
|
1503
1564
|
* @param {Function} callback callback query
|
|
@@ -1603,7 +1664,7 @@ import { alias } from 'yargs';
|
|
|
1603
1664
|
* @property {boolean} options.oldest
|
|
1604
1665
|
* @returns {string} return sql query
|
|
1605
1666
|
*/
|
|
1606
|
-
toString({ latest, oldest }?: {
|
|
1667
|
+
toString({ latest, oldest, }?: {
|
|
1607
1668
|
latest?: boolean;
|
|
1608
1669
|
oldest?: boolean;
|
|
1609
1670
|
}): string;
|
|
@@ -1615,7 +1676,7 @@ import { alias } from 'yargs';
|
|
|
1615
1676
|
* @property {boolean} options.oldest
|
|
1616
1677
|
* @returns {string} return sql query
|
|
1617
1678
|
*/
|
|
1618
|
-
toSQL({ latest, oldest }?: {
|
|
1679
|
+
toSQL({ latest, oldest, }?: {
|
|
1619
1680
|
latest?: boolean;
|
|
1620
1681
|
oldest?: boolean;
|
|
1621
1682
|
}): string;
|
|
@@ -1624,7 +1685,7 @@ import { alias } from 'yargs';
|
|
|
1624
1685
|
* @param {string=} column [column=id]
|
|
1625
1686
|
* @returns {promise<Array>}
|
|
1626
1687
|
*/
|
|
1627
|
-
toArray<K extends Extract<TSchemaKeys<TS>, string> |
|
|
1688
|
+
toArray<K extends Extract<TSchemaKeys<TS>, string> | "id">(column?: K): Promise<any[]>;
|
|
1628
1689
|
/**
|
|
1629
1690
|
*
|
|
1630
1691
|
* @override
|
|
@@ -1636,38 +1697,38 @@ import { alias } from 'yargs';
|
|
|
1636
1697
|
* @override
|
|
1637
1698
|
* @param {Function?} cb callback function return query sql
|
|
1638
1699
|
* @returns {promise<Record<string,any> | null>} Record | null
|
|
1639
|
-
|
|
1700
|
+
*/
|
|
1640
1701
|
first<K, R = TRelationResults<TR>>(cb?: Function): Promise<(unknown extends TS ? Record<string, any> : TS & K & Partial<R extends any ? TS & Partial<R> : R>) | null>;
|
|
1641
1702
|
/**
|
|
1642
1703
|
* @override
|
|
1643
1704
|
* @param {Function?} cb callback function return query sql
|
|
1644
1705
|
* @returns {promise<Record<string,any> | null>} Record | null
|
|
1645
|
-
|
|
1706
|
+
*/
|
|
1646
1707
|
findOne<K, R = TRelationResults<TR>>(cb?: Function): Promise<(unknown extends TS ? Record<string, any> : TS & K & Partial<R extends any ? TS & Partial<R> : R>) | null>;
|
|
1647
1708
|
/**
|
|
1648
1709
|
* @override
|
|
1649
1710
|
* @returns {promise<object | Error>} Record | throw error
|
|
1650
|
-
|
|
1651
|
-
firstOrError<K, R = TRelationResults<TR>>(message?: string, options?: Record<string, any>): Promise<
|
|
1711
|
+
*/
|
|
1712
|
+
firstOrError<K, R = TRelationResults<TR>>(message?: string, options?: Record<string, any>): Promise<unknown extends TS ? Record<string, any> : TS & K & Partial<R extends any ? TS & Partial<R> : R>>;
|
|
1652
1713
|
/**
|
|
1653
1714
|
*
|
|
1654
1715
|
* @override
|
|
1655
1716
|
* @returns {promise<any>} Record | throw error
|
|
1656
|
-
|
|
1657
|
-
findOneOrError<K, R = TRelationResults<TR>>(message?: string, options?: Record<string, any>): Promise<
|
|
1717
|
+
*/
|
|
1718
|
+
findOneOrError<K, R = TRelationResults<TR>>(message?: string, options?: Record<string, any>): Promise<unknown extends TS ? Record<string, any> : TS & K & Partial<R extends any ? TS & Partial<R> : R>>;
|
|
1658
1719
|
/**
|
|
1659
1720
|
*
|
|
1660
1721
|
* @override
|
|
1661
1722
|
* @param {Function?} cb callback function return query sql
|
|
1662
1723
|
* @returns {promise<array>} Array
|
|
1663
|
-
|
|
1724
|
+
*/
|
|
1664
1725
|
get<K, R = TRelationResults<TR>>(cb?: Function): Promise<(unknown extends TS ? Record<string, any> : TS & K & Partial<TR extends any ? TS & Partial<R> : R>)[]>;
|
|
1665
1726
|
/**
|
|
1666
1727
|
*
|
|
1667
1728
|
* @override
|
|
1668
1729
|
* @param {Function?} cb callback function return query sql
|
|
1669
1730
|
* @returns {promise<array>} Array
|
|
1670
|
-
|
|
1731
|
+
*/
|
|
1671
1732
|
findMany<K, R = TRelationResults<TR>>(cb?: Function): Promise<(unknown extends TS ? Record<string, any> : TS & K & Partial<TR extends any ? TS & Partial<R> : R>)[]>;
|
|
1672
1733
|
/**
|
|
1673
1734
|
* @override
|
|
@@ -1680,20 +1741,20 @@ import { alias } from 'yargs';
|
|
|
1680
1741
|
limit?: number;
|
|
1681
1742
|
page?: number;
|
|
1682
1743
|
alias?: boolean;
|
|
1683
|
-
}): Promise<TPagination<
|
|
1684
|
-
/**
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1744
|
+
}): Promise<TPagination<TS & K & Partial<R extends any ? TS & Partial<R> : R>>>;
|
|
1745
|
+
/**
|
|
1746
|
+
*
|
|
1747
|
+
* @override
|
|
1748
|
+
* @param {?object} paginationOptions by default page = 1 , limit = 15
|
|
1749
|
+
* @property {number} paginationOptions.limit
|
|
1750
|
+
* @property {number} paginationOptions.page
|
|
1751
|
+
* @returns {promise<Pagination>} Pagination
|
|
1752
|
+
*/
|
|
1692
1753
|
paginate<K, R = TRelationResults<TR>>(paginationOptions?: {
|
|
1693
1754
|
limit?: number;
|
|
1694
1755
|
page?: number;
|
|
1695
1756
|
alias?: boolean;
|
|
1696
|
-
}): Promise<TPagination<
|
|
1757
|
+
}): Promise<TPagination<TS & K & Partial<R extends any ? TS & Partial<R> : R>>>;
|
|
1697
1758
|
/**
|
|
1698
1759
|
* @override
|
|
1699
1760
|
* @param {string} column
|
|
@@ -1831,11 +1892,11 @@ import { alias } from 'yargs';
|
|
|
1831
1892
|
[P in K]: any;
|
|
1832
1893
|
}): this;
|
|
1833
1894
|
/**
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1895
|
+
*
|
|
1896
|
+
* @override
|
|
1897
|
+
* @param {object} data create not exists data
|
|
1898
|
+
* @returns {this} this
|
|
1899
|
+
*/
|
|
1839
1900
|
createNotExists<K extends TSchemaKeys<TS> | TRawStringQuery | TFreezeStringQuery>(data: K extends TSchemaKeys<TS> ? {
|
|
1840
1901
|
[P in K]: TS[K] | TRawStringQuery;
|
|
1841
1902
|
} : {
|
|
@@ -1882,14 +1943,14 @@ import { alias } from 'yargs';
|
|
|
1882
1943
|
* @returns {this} this
|
|
1883
1944
|
*/
|
|
1884
1945
|
updateMultiple<K extends TSchemaKeys<TS> | TRawStringQuery | TFreezeStringQuery>(cases: {
|
|
1885
|
-
when:
|
|
1946
|
+
when: K extends TSchemaKeys<TS> ? Partial<{
|
|
1886
1947
|
[K in TSchemaKeys<TS>]: TS[K];
|
|
1887
1948
|
}> : {
|
|
1888
1949
|
[P in K]: any;
|
|
1889
|
-
}
|
|
1890
|
-
columns:
|
|
1950
|
+
};
|
|
1951
|
+
columns: K extends TSchemaKeys<TS> ? Partial<{
|
|
1891
1952
|
[K in TSchemaKeys<TS>]: TS[K];
|
|
1892
|
-
}> : Record<string, any
|
|
1953
|
+
}> : Record<string, any>;
|
|
1893
1954
|
}[]): this;
|
|
1894
1955
|
/**
|
|
1895
1956
|
* The 'getSchemaModel' method is used get a schema model
|
|
@@ -1933,16 +1994,18 @@ import { alias } from 'yargs';
|
|
|
1933
1994
|
* @property {boolean} options.index - add columns to index
|
|
1934
1995
|
* @returns {Promise<void>}
|
|
1935
1996
|
*/
|
|
1936
|
-
sync({ force, foreign, changed, index }?: {
|
|
1997
|
+
sync({ force, foreign, changed, index, }?: {
|
|
1937
1998
|
force?: boolean | undefined;
|
|
1938
1999
|
foreign?: boolean | undefined;
|
|
1939
2000
|
changed?: boolean | undefined;
|
|
1940
2001
|
index?: boolean | undefined;
|
|
1941
2002
|
}): Promise<void>;
|
|
1942
|
-
|
|
2003
|
+
protected _valuePattern(column: string): string;
|
|
1943
2004
|
private _checkTableLoggerIsExists;
|
|
1944
2005
|
private _isPatternSnakeCase;
|
|
1945
|
-
|
|
2006
|
+
protected _classToTableName(className?: string | null, { singular }?: {
|
|
2007
|
+
singular?: boolean | undefined;
|
|
2008
|
+
}): string;
|
|
1946
2009
|
private _makeTableName;
|
|
1947
2010
|
private _handleSoftDelete;
|
|
1948
2011
|
private _handleGlobalScope;
|
|
@@ -1993,6 +2056,7 @@ import { alias } from 'yargs';
|
|
|
1993
2056
|
private _makeRelations;
|
|
1994
2057
|
private _guardWhereCondition;
|
|
1995
2058
|
private _isModel;
|
|
2059
|
+
private _getBlueprintByKey;
|
|
1996
2060
|
private _initialModel;
|
|
1997
2061
|
}
|
|
1998
2062
|
export { Model };
|