tspace-mysql 1.8.2 → 1.8.3
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 +76 -11
- package/build/lib/core/Abstracts/AbstractDB.d.ts +2 -2
- package/build/lib/core/Abstracts/AbstractDB.js.map +1 -1
- package/build/lib/core/Builder.d.ts +26 -26
- package/build/lib/core/Builder.js +1092 -1014
- package/build/lib/core/Builder.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/Handlers/Relation.js +9 -7
- package/build/lib/core/Handlers/Relation.js.map +1 -1
- package/build/lib/core/Model.d.ts +138 -88
- package/build/lib/core/Model.js +1403 -1196
- 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/index.d.ts +12 -12
- package/build/lib/core/index.js +3 -3
- package/build/lib/core/index.js.map +1 -1
- package/build/lib/types/index.d.ts +19 -3
- package/build/tests/01-Pool.test.js +0 -10
- package/build/tests/01-Pool.test.js.map +1 -1
- package/package.json +1 -1
- package/build/lib/connection/index.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AbstractModel } from
|
|
2
|
-
import { Blueprint } from
|
|
3
|
-
import { TSchemaModel } from
|
|
4
|
-
import { JoinModel } from
|
|
5
|
-
import type { TCache, TRelationOptions, TPagination, TRelationQueryOptions, TValidateSchema, TGlobalSetting, TRawStringQuery, TFreezeStringQuery, TPattern, TSchemaKeys, TSchemaColumns, TModelConstructorOrObject, TRelationResults, TRelationKeys } from
|
|
1
|
+
import { AbstractModel } from "./Abstracts/AbstractModel";
|
|
2
|
+
import { Blueprint } from "./Blueprint";
|
|
3
|
+
import { TSchemaModel } from "./UtilityTypes";
|
|
4
|
+
import { JoinModel } from "./JoinModel";
|
|
5
|
+
import type { TCache, TRelationOptions, TPagination, TRelationQueryOptions, TValidateSchema, TGlobalSetting, TRawStringQuery, TFreezeStringQuery, TPattern, TSchemaKeys, TSchemaColumns, TModelConstructorOrObject, TRelationResults, TRelationKeys } from "../types";
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
* 'Model' class is a representation of a database table
|
|
@@ -75,7 +75,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
75
75
|
* @property {string} parttern
|
|
76
76
|
* @returns {Record | string} T
|
|
77
77
|
*/
|
|
78
|
-
static formatPattern<T extends Record<string, any> | string>({ data, pattern }: {
|
|
78
|
+
static formatPattern<T extends Record<string, any> | string>({ data, pattern, }: {
|
|
79
79
|
data: T;
|
|
80
80
|
pattern: TPattern;
|
|
81
81
|
}): T;
|
|
@@ -177,28 +177,28 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
177
177
|
deleted: Function;
|
|
178
178
|
}): this;
|
|
179
179
|
/**
|
|
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 }?: {
|
|
180
|
+
* The "useLogger" method is used to keeping query data and changed in models.
|
|
181
|
+
*
|
|
182
|
+
* @type {object} options
|
|
183
|
+
* @property {boolean} options.selected - default is false
|
|
184
|
+
* @property {boolean} options.inserted - default is true
|
|
185
|
+
* @property {boolean} options.updated - default is true
|
|
186
|
+
* @property {boolean} options.deleted - default is true
|
|
187
|
+
* @example
|
|
188
|
+
* class User extends Model {
|
|
189
|
+
* constructor() {
|
|
190
|
+
* super()
|
|
191
|
+
* this.useLogger({
|
|
192
|
+
* selected : true,
|
|
193
|
+
* inserted : true,
|
|
194
|
+
* updated : true,
|
|
195
|
+
* deleted : true,
|
|
196
|
+
* })
|
|
197
|
+
* }
|
|
198
|
+
* }
|
|
199
|
+
* @returns {this} this
|
|
200
|
+
*/
|
|
201
|
+
protected useLogger({ selected, inserted, updated, deleted, }?: {
|
|
202
202
|
selected?: boolean | undefined;
|
|
203
203
|
inserted?: boolean | undefined;
|
|
204
204
|
updated?: boolean | undefined;
|
|
@@ -485,7 +485,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
485
485
|
* this.useHook([(results) => console.log(results)])
|
|
486
486
|
* }
|
|
487
487
|
* }
|
|
488
|
-
|
|
488
|
+
*/
|
|
489
489
|
protected useHooks(arrayFunctions: Function[]): this;
|
|
490
490
|
/**
|
|
491
491
|
* The "beforeCreatingTable" method is used exection function when creating the table.
|
|
@@ -503,7 +503,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
503
503
|
* })
|
|
504
504
|
* }
|
|
505
505
|
* }
|
|
506
|
-
|
|
506
|
+
*/
|
|
507
507
|
protected beforeCreatingTable(fn: () => Promise<any>): this;
|
|
508
508
|
/**
|
|
509
509
|
* The "whenCreatingTable" method is used exection function when creating the table.
|
|
@@ -521,7 +521,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
521
521
|
* })
|
|
522
522
|
* }
|
|
523
523
|
* }
|
|
524
|
-
|
|
524
|
+
*/
|
|
525
525
|
protected whenCreatingTable(fn: () => Promise<any>): this;
|
|
526
526
|
/**
|
|
527
527
|
* exceptColumns for method except
|
|
@@ -536,7 +536,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
536
536
|
* @returns {this} this
|
|
537
537
|
*/
|
|
538
538
|
protected buildMethodRelation<K extends TR extends object ? TRelationKeys<TR> : string>(name: K, callback?: Function): this;
|
|
539
|
-
meta(meta:
|
|
539
|
+
meta(meta: "MAIN" | "SUBORDINATE"): this;
|
|
540
540
|
/**
|
|
541
541
|
* The 'typeOfSchema' method is used get type of schema.
|
|
542
542
|
* @returns {TS} type of schema
|
|
@@ -564,7 +564,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
564
564
|
* @param {string[]} ...columns
|
|
565
565
|
* @returns {this} this
|
|
566
566
|
*/
|
|
567
|
-
select<K extends Extract<TSchemaKeys<TS>, string> | `${string}.${string}` | TRawStringQuery |
|
|
567
|
+
select<K extends Extract<TSchemaKeys<TS>, string> | `${string}.${string}` | TRawStringQuery | "*">(...columns: K[]): this;
|
|
568
568
|
/**
|
|
569
569
|
*
|
|
570
570
|
* @override
|
|
@@ -592,7 +592,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
592
592
|
* @param {string?} order by default order = 'asc' but you can used 'asc' or 'desc'
|
|
593
593
|
* @returns {this}
|
|
594
594
|
*/
|
|
595
|
-
orderBy<K extends Extract<TSchemaKeys<TS>, string> | `${string}.${string}`>(column: K, order?:
|
|
595
|
+
orderBy<K extends Extract<TSchemaKeys<TS>, string> | `${string}.${string}`>(column: K, order?: "ASC" | "asc" | "DESC" | "desc"): this;
|
|
596
596
|
/**
|
|
597
597
|
*
|
|
598
598
|
* @override
|
|
@@ -702,7 +702,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
702
702
|
* @property {Function} actions.returnId
|
|
703
703
|
* @returns {this} this
|
|
704
704
|
*/
|
|
705
|
-
protected _actionStatement({ sql, returnId }: {
|
|
705
|
+
protected _actionStatement({ sql, returnId, }: {
|
|
706
706
|
sql: string;
|
|
707
707
|
returnId?: boolean;
|
|
708
708
|
}): Promise<any>;
|
|
@@ -721,7 +721,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
721
721
|
*/
|
|
722
722
|
disableSoftDelete(condition?: boolean): this;
|
|
723
723
|
/**
|
|
724
|
-
|
|
724
|
+
* The 'ignoreSoftDelete' method is used to disable the soft delete.
|
|
725
725
|
* @param {boolean} condition
|
|
726
726
|
* @returns {this} this
|
|
727
727
|
*/
|
|
@@ -876,9 +876,6 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
876
876
|
* @returns {this} this
|
|
877
877
|
* @example
|
|
878
878
|
* import { Model } from 'tspace-mysql'
|
|
879
|
-
import { alias } from 'yargs';
|
|
880
|
-
* import { pattern } from '../../tests/schema-spec';
|
|
881
|
-
* import { TRelationOptions } from '../types';
|
|
882
879
|
* class User extends Model {
|
|
883
880
|
* constructor(){
|
|
884
881
|
* super()
|
|
@@ -906,8 +903,6 @@ import { alias } from 'yargs';
|
|
|
906
903
|
* @returns {this} this
|
|
907
904
|
* @example
|
|
908
905
|
* import { Model } from 'tspace-mysql'
|
|
909
|
-
* import utils from '../utils/index';
|
|
910
|
-
* import { TRelationOptions } from '../types';
|
|
911
906
|
* class User extends Model {
|
|
912
907
|
* constructor(){
|
|
913
908
|
* super()
|
|
@@ -1062,6 +1057,9 @@ import { alias } from 'yargs';
|
|
|
1062
1057
|
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
1058
|
pivot: boolean;
|
|
1064
1059
|
}): this;
|
|
1060
|
+
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?: {
|
|
1061
|
+
pivot: boolean;
|
|
1062
|
+
}): this;
|
|
1065
1063
|
/**
|
|
1066
1064
|
*
|
|
1067
1065
|
* The 'relationQuery' method is particularly useful when you want to filter or add conditions records based on related data.
|
|
@@ -1114,6 +1112,58 @@ import { alias } from 'yargs';
|
|
|
1114
1112
|
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
1113
|
pivot: boolean;
|
|
1116
1114
|
}): this;
|
|
1115
|
+
/**
|
|
1116
|
+
*
|
|
1117
|
+
* The 'relationQueryExists' method is particularly useful when you want to filter or add conditions records based on related data.
|
|
1118
|
+
*
|
|
1119
|
+
* Use relation '${name}' registry models then return callback queries
|
|
1120
|
+
* @param {string} nameRelation name relation in registry in your model
|
|
1121
|
+
* @param {function} callback query callback
|
|
1122
|
+
* @param {object} options pivot the query
|
|
1123
|
+
* @example
|
|
1124
|
+
* import { Model } from 'tspace-mysql'
|
|
1125
|
+
* class User extends Model {
|
|
1126
|
+
* constructor(){
|
|
1127
|
+
* super()
|
|
1128
|
+
* this.hasMany({ name : 'posts' , model : Post })
|
|
1129
|
+
* }
|
|
1130
|
+
* }
|
|
1131
|
+
*
|
|
1132
|
+
* class Post extends Model {
|
|
1133
|
+
* constructor(){
|
|
1134
|
+
* super()
|
|
1135
|
+
* this.hasMany({ name : 'comments' , model : Comment })
|
|
1136
|
+
* this.belongsTo({ name : 'user' , model : User })
|
|
1137
|
+
* }
|
|
1138
|
+
* }
|
|
1139
|
+
*
|
|
1140
|
+
* class Comment extends Model {
|
|
1141
|
+
* constructor(){
|
|
1142
|
+
* super()
|
|
1143
|
+
* this.hasMany({ name : 'users' , model : User })
|
|
1144
|
+
* this.belongsTo({ name : 'post' , model : Post })
|
|
1145
|
+
* }
|
|
1146
|
+
* }
|
|
1147
|
+
*
|
|
1148
|
+
* await new User().relations('posts')
|
|
1149
|
+
* .relationQuery('posts', (query : Post) => {
|
|
1150
|
+
* return query.relations('comments','user')
|
|
1151
|
+
* .relationQuery('comments', (query : Comment) => {
|
|
1152
|
+
* return query.relations('user','post')
|
|
1153
|
+
* })
|
|
1154
|
+
* .relationQuery('user', (query : User) => {
|
|
1155
|
+
* return query.relations('posts').relationsQuery('posts',(query : Post)=> {
|
|
1156
|
+
* return query.relations('comments','user')
|
|
1157
|
+
* // relation n, n, ...n
|
|
1158
|
+
* })
|
|
1159
|
+
* })
|
|
1160
|
+
* })
|
|
1161
|
+
* .findMany()
|
|
1162
|
+
* @returns {this} this
|
|
1163
|
+
*/
|
|
1164
|
+
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?: {
|
|
1165
|
+
pivot: boolean;
|
|
1166
|
+
}): this;
|
|
1117
1167
|
/**
|
|
1118
1168
|
*
|
|
1119
1169
|
* The 'findWithQuery' method is used to find instance call back from relation.
|
|
@@ -1138,7 +1188,7 @@ import { alias } from 'yargs';
|
|
|
1138
1188
|
* @property {string} relation.freezeTable
|
|
1139
1189
|
* @returns {this} this
|
|
1140
1190
|
*/
|
|
1141
|
-
protected hasOne<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
|
|
1191
|
+
protected hasOne<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationOptions<K>): this;
|
|
1142
1192
|
/**
|
|
1143
1193
|
* The 'hasMany' relationship defines a one-to-many relationship between two database tables.
|
|
1144
1194
|
*
|
|
@@ -1155,7 +1205,7 @@ import { alias } from 'yargs';
|
|
|
1155
1205
|
* @property {string} relation.freezeTable
|
|
1156
1206
|
* @returns {this} this
|
|
1157
1207
|
*/
|
|
1158
|
-
protected hasMany<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
|
|
1208
|
+
protected hasMany<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationOptions<K>): this;
|
|
1159
1209
|
/**
|
|
1160
1210
|
* The 'belongsTo' relationship defines a one-to-one or many-to-one relationship between two database tables.
|
|
1161
1211
|
*
|
|
@@ -1172,7 +1222,7 @@ import { alias } from 'yargs';
|
|
|
1172
1222
|
* @property {string} relation.freezeTable
|
|
1173
1223
|
* @returns {this} this
|
|
1174
1224
|
*/
|
|
1175
|
-
protected belongsTo<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable }: TRelationOptions<K>): this;
|
|
1225
|
+
protected belongsTo<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationOptions<K>): this;
|
|
1176
1226
|
/**
|
|
1177
1227
|
* The 'belongsToMany' relationship defines a many-to-many relationship between two database tables.
|
|
1178
1228
|
*
|
|
@@ -1192,7 +1242,7 @@ import { alias } from 'yargs';
|
|
|
1192
1242
|
* @property {class?} relation.modelPivot model for pivot
|
|
1193
1243
|
* @returns {this} this
|
|
1194
1244
|
*/
|
|
1195
|
-
protected belongsToMany<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }: TRelationOptions<K>): this;
|
|
1245
|
+
protected belongsToMany<K extends TR extends object ? TRelationKeys<TR> : string>({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot, }: TRelationOptions<K>): this;
|
|
1196
1246
|
/**
|
|
1197
1247
|
* The 'hasOneBuilder' method is useful for creating 'hasOne' relationship to function
|
|
1198
1248
|
*
|
|
@@ -1207,7 +1257,7 @@ import { alias } from 'yargs';
|
|
|
1207
1257
|
* @param {Function?} callback callback of query
|
|
1208
1258
|
* @returns {this} this
|
|
1209
1259
|
*/
|
|
1210
|
-
protected hasOneBuilder({ name, as, model, localKey, foreignKey, freezeTable }: TRelationQueryOptions, callback?: Function): this;
|
|
1260
|
+
protected hasOneBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1211
1261
|
/**
|
|
1212
1262
|
* The 'hasManyBuilder' method is useful for creating 'hasMany' relationship to function
|
|
1213
1263
|
*
|
|
@@ -1222,7 +1272,7 @@ import { alias } from 'yargs';
|
|
|
1222
1272
|
* @param {function?} callback callback of query
|
|
1223
1273
|
* @returns {this} this
|
|
1224
1274
|
*/
|
|
1225
|
-
protected hasManyBuilder({ name, as, model, localKey, foreignKey, freezeTable }: TRelationQueryOptions, callback?: Function): this;
|
|
1275
|
+
protected hasManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1226
1276
|
/**
|
|
1227
1277
|
* The 'belongsToBuilder' method is useful for creating 'belongsTo' relationship to function
|
|
1228
1278
|
* @param {object} relation registry relation in your model
|
|
@@ -1236,7 +1286,7 @@ import { alias } from 'yargs';
|
|
|
1236
1286
|
* @param {function?} callback callback of query
|
|
1237
1287
|
* @returns {this} this
|
|
1238
1288
|
*/
|
|
1239
|
-
protected belongsToBuilder({ name, as, model, localKey, foreignKey, freezeTable }: TRelationQueryOptions, callback?: Function): this;
|
|
1289
|
+
protected belongsToBuilder({ name, as, model, localKey, foreignKey, freezeTable, }: TRelationQueryOptions, callback?: Function): this;
|
|
1240
1290
|
/**
|
|
1241
1291
|
* The 'belongsToManyBuilder' method is useful for creating 'belongsToMany' relationship to function
|
|
1242
1292
|
*
|
|
@@ -1251,7 +1301,7 @@ import { alias } from 'yargs';
|
|
|
1251
1301
|
* @param {function?} callback callback of query
|
|
1252
1302
|
* @returns {this} this
|
|
1253
1303
|
*/
|
|
1254
|
-
protected belongsToManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot }: TRelationQueryOptions, callback?: Function): this;
|
|
1304
|
+
protected belongsToManyBuilder({ name, as, model, localKey, foreignKey, freezeTable, pivot, oldVersion, modelPivot, }: TRelationQueryOptions, callback?: Function): this;
|
|
1255
1305
|
/**
|
|
1256
1306
|
* The 'trashed' method is used to specify that you want to retrieve only the soft-deleted records from a database table.
|
|
1257
1307
|
*
|
|
@@ -1332,14 +1382,14 @@ import { alias } from 'yargs';
|
|
|
1332
1382
|
[P in K]: any;
|
|
1333
1383
|
}): this;
|
|
1334
1384
|
/**
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1385
|
+
* @override
|
|
1386
|
+
* @param {string} column
|
|
1387
|
+
* @param {object} property object { key , value , operator }
|
|
1388
|
+
* @property {string} property.key
|
|
1389
|
+
* @property {string} property.value
|
|
1390
|
+
* @property {string?} property.operator
|
|
1391
|
+
* @returns {this}
|
|
1392
|
+
*/
|
|
1343
1393
|
whereJSON<K extends TSchemaColumns<TS>>(column: K, { key, value, operator }: {
|
|
1344
1394
|
key: string;
|
|
1345
1395
|
value: string;
|
|
@@ -1603,7 +1653,7 @@ import { alias } from 'yargs';
|
|
|
1603
1653
|
* @property {boolean} options.oldest
|
|
1604
1654
|
* @returns {string} return sql query
|
|
1605
1655
|
*/
|
|
1606
|
-
toString({ latest, oldest }?: {
|
|
1656
|
+
toString({ latest, oldest, }?: {
|
|
1607
1657
|
latest?: boolean;
|
|
1608
1658
|
oldest?: boolean;
|
|
1609
1659
|
}): string;
|
|
@@ -1615,7 +1665,7 @@ import { alias } from 'yargs';
|
|
|
1615
1665
|
* @property {boolean} options.oldest
|
|
1616
1666
|
* @returns {string} return sql query
|
|
1617
1667
|
*/
|
|
1618
|
-
toSQL({ latest, oldest }?: {
|
|
1668
|
+
toSQL({ latest, oldest, }?: {
|
|
1619
1669
|
latest?: boolean;
|
|
1620
1670
|
oldest?: boolean;
|
|
1621
1671
|
}): string;
|
|
@@ -1624,7 +1674,7 @@ import { alias } from 'yargs';
|
|
|
1624
1674
|
* @param {string=} column [column=id]
|
|
1625
1675
|
* @returns {promise<Array>}
|
|
1626
1676
|
*/
|
|
1627
|
-
toArray<K extends Extract<TSchemaKeys<TS>, string> |
|
|
1677
|
+
toArray<K extends Extract<TSchemaKeys<TS>, string> | "id">(column?: K): Promise<any[]>;
|
|
1628
1678
|
/**
|
|
1629
1679
|
*
|
|
1630
1680
|
* @override
|
|
@@ -1636,38 +1686,38 @@ import { alias } from 'yargs';
|
|
|
1636
1686
|
* @override
|
|
1637
1687
|
* @param {Function?} cb callback function return query sql
|
|
1638
1688
|
* @returns {promise<Record<string,any> | null>} Record | null
|
|
1639
|
-
|
|
1689
|
+
*/
|
|
1640
1690
|
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
1691
|
/**
|
|
1642
1692
|
* @override
|
|
1643
1693
|
* @param {Function?} cb callback function return query sql
|
|
1644
1694
|
* @returns {promise<Record<string,any> | null>} Record | null
|
|
1645
|
-
|
|
1695
|
+
*/
|
|
1646
1696
|
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
1697
|
/**
|
|
1648
1698
|
* @override
|
|
1649
1699
|
* @returns {promise<object | Error>} Record | throw error
|
|
1650
|
-
|
|
1651
|
-
firstOrError<K, R = TRelationResults<TR>>(message?: string, options?: Record<string, any>): Promise<
|
|
1700
|
+
*/
|
|
1701
|
+
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
1702
|
/**
|
|
1653
1703
|
*
|
|
1654
1704
|
* @override
|
|
1655
1705
|
* @returns {promise<any>} Record | throw error
|
|
1656
|
-
|
|
1657
|
-
findOneOrError<K, R = TRelationResults<TR>>(message?: string, options?: Record<string, any>): Promise<
|
|
1706
|
+
*/
|
|
1707
|
+
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
1708
|
/**
|
|
1659
1709
|
*
|
|
1660
1710
|
* @override
|
|
1661
1711
|
* @param {Function?} cb callback function return query sql
|
|
1662
1712
|
* @returns {promise<array>} Array
|
|
1663
|
-
|
|
1713
|
+
*/
|
|
1664
1714
|
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
1715
|
/**
|
|
1666
1716
|
*
|
|
1667
1717
|
* @override
|
|
1668
1718
|
* @param {Function?} cb callback function return query sql
|
|
1669
1719
|
* @returns {promise<array>} Array
|
|
1670
|
-
|
|
1720
|
+
*/
|
|
1671
1721
|
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
1722
|
/**
|
|
1673
1723
|
* @override
|
|
@@ -1680,20 +1730,20 @@ import { alias } from 'yargs';
|
|
|
1680
1730
|
limit?: number;
|
|
1681
1731
|
page?: number;
|
|
1682
1732
|
alias?: boolean;
|
|
1683
|
-
}): Promise<TPagination<
|
|
1684
|
-
/**
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1733
|
+
}): Promise<TPagination<TS & K & Partial<R extends any ? TS & Partial<R> : R>>>;
|
|
1734
|
+
/**
|
|
1735
|
+
*
|
|
1736
|
+
* @override
|
|
1737
|
+
* @param {?object} paginationOptions by default page = 1 , limit = 15
|
|
1738
|
+
* @property {number} paginationOptions.limit
|
|
1739
|
+
* @property {number} paginationOptions.page
|
|
1740
|
+
* @returns {promise<Pagination>} Pagination
|
|
1741
|
+
*/
|
|
1692
1742
|
paginate<K, R = TRelationResults<TR>>(paginationOptions?: {
|
|
1693
1743
|
limit?: number;
|
|
1694
1744
|
page?: number;
|
|
1695
1745
|
alias?: boolean;
|
|
1696
|
-
}): Promise<TPagination<
|
|
1746
|
+
}): Promise<TPagination<TS & K & Partial<R extends any ? TS & Partial<R> : R>>>;
|
|
1697
1747
|
/**
|
|
1698
1748
|
* @override
|
|
1699
1749
|
* @param {string} column
|
|
@@ -1831,11 +1881,11 @@ import { alias } from 'yargs';
|
|
|
1831
1881
|
[P in K]: any;
|
|
1832
1882
|
}): this;
|
|
1833
1883
|
/**
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1884
|
+
*
|
|
1885
|
+
* @override
|
|
1886
|
+
* @param {object} data create not exists data
|
|
1887
|
+
* @returns {this} this
|
|
1888
|
+
*/
|
|
1839
1889
|
createNotExists<K extends TSchemaKeys<TS> | TRawStringQuery | TFreezeStringQuery>(data: K extends TSchemaKeys<TS> ? {
|
|
1840
1890
|
[P in K]: TS[K] | TRawStringQuery;
|
|
1841
1891
|
} : {
|
|
@@ -1882,14 +1932,14 @@ import { alias } from 'yargs';
|
|
|
1882
1932
|
* @returns {this} this
|
|
1883
1933
|
*/
|
|
1884
1934
|
updateMultiple<K extends TSchemaKeys<TS> | TRawStringQuery | TFreezeStringQuery>(cases: {
|
|
1885
|
-
when:
|
|
1935
|
+
when: K extends TSchemaKeys<TS> ? Partial<{
|
|
1886
1936
|
[K in TSchemaKeys<TS>]: TS[K];
|
|
1887
1937
|
}> : {
|
|
1888
1938
|
[P in K]: any;
|
|
1889
|
-
}
|
|
1890
|
-
columns:
|
|
1939
|
+
};
|
|
1940
|
+
columns: K extends TSchemaKeys<TS> ? Partial<{
|
|
1891
1941
|
[K in TSchemaKeys<TS>]: TS[K];
|
|
1892
|
-
}> : Record<string, any
|
|
1942
|
+
}> : Record<string, any>;
|
|
1893
1943
|
}[]): this;
|
|
1894
1944
|
/**
|
|
1895
1945
|
* The 'getSchemaModel' method is used get a schema model
|
|
@@ -1933,7 +1983,7 @@ import { alias } from 'yargs';
|
|
|
1933
1983
|
* @property {boolean} options.index - add columns to index
|
|
1934
1984
|
* @returns {Promise<void>}
|
|
1935
1985
|
*/
|
|
1936
|
-
sync({ force, foreign, changed, index }?: {
|
|
1986
|
+
sync({ force, foreign, changed, index, }?: {
|
|
1937
1987
|
force?: boolean | undefined;
|
|
1938
1988
|
foreign?: boolean | undefined;
|
|
1939
1989
|
changed?: boolean | undefined;
|