tspace-mysql 1.9.0 → 1.9.1
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 +4357 -133
- package/dist/lib/config/index.d.ts +2 -2
- package/dist/lib/config/index.js +24 -16
- package/dist/lib/config/index.js.map +1 -1
- package/dist/lib/constants/index.d.ts +10 -1
- package/dist/lib/constants/index.js +11 -2
- package/dist/lib/constants/index.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractBuilder.d.ts +11 -7
- package/dist/lib/core/Abstracts/AbstractBuilder.js +11 -13
- package/dist/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractDB.d.ts +4 -1
- package/dist/lib/core/Abstracts/AbstractDB.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractView.js.map +1 -1
- package/dist/lib/core/Blueprint.d.ts +30 -10
- package/dist/lib/core/Blueprint.js +39 -14
- package/dist/lib/core/Blueprint.js.map +1 -1
- package/dist/lib/core/Builder.d.ts +263 -9
- package/dist/lib/core/Builder.js +610 -347
- package/dist/lib/core/Builder.js.map +1 -1
- package/dist/lib/core/Cache/DBCache.js +19 -20
- package/dist/lib/core/Cache/DBCache.js.map +1 -1
- package/dist/lib/core/Cache/MemoryCache.js +3 -3
- package/dist/lib/core/Cache/MemoryCache.js.map +1 -1
- package/dist/lib/core/Cache/RedisCache.js +27 -17
- package/dist/lib/core/Cache/RedisCache.js.map +1 -1
- package/dist/lib/core/Cache/index.js +5 -4
- package/dist/lib/core/Cache/index.js.map +1 -1
- package/dist/lib/core/Contracts/AlterTable.d.ts +152 -0
- package/dist/lib/core/Contracts/AlterTable.js +243 -0
- package/dist/lib/core/Contracts/AlterTable.js.map +1 -0
- package/dist/lib/core/Contracts/Audit.js +2 -5
- package/dist/lib/core/Contracts/Audit.js.map +1 -1
- package/dist/lib/core/DB.d.ts +101 -9
- package/dist/lib/core/DB.js +168 -29
- package/dist/lib/core/DB.js.map +1 -1
- package/dist/lib/core/Decorator.d.ts +144 -16
- package/dist/lib/core/Decorator.js +156 -14
- package/dist/lib/core/Decorator.js.map +1 -1
- package/dist/lib/core/Driver/index.d.ts +43 -9
- package/dist/lib/core/Driver/index.js +9 -7
- package/dist/lib/core/Driver/index.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js +74 -27
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +45 -9
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js +165 -21
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbDriver.d.ts +24 -0
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js +255 -0
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -0
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.d.ts +141 -0
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js +563 -0
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js.map +1 -0
- package/dist/lib/core/Driver/mysql/MysqlDriver.js +105 -95
- package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +45 -9
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js +165 -21
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresDriver.js +97 -72
- package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +50 -9
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js +296 -41
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +20 -0
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js +192 -0
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -0
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.d.ts +144 -0
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js +689 -0
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js.map +1 -0
- package/dist/lib/core/JoinModel.js +2 -2
- package/dist/lib/core/JoinModel.js.map +1 -1
- package/dist/lib/core/Meta.d.ts +17 -11
- package/dist/lib/core/Meta.js +25 -19
- package/dist/lib/core/Meta.js.map +1 -1
- package/dist/lib/core/Model.d.ts +450 -108
- package/dist/lib/core/Model.js +1031 -587
- package/dist/lib/core/Model.js.map +1 -1
- package/dist/lib/{tools/index.d.ts → core/Package.d.ts} +11 -3
- package/dist/lib/{tools/index.js → core/Package.js} +20 -7
- package/dist/lib/core/Package.js.map +1 -0
- package/dist/lib/core/Pool.js +42 -30
- package/dist/lib/core/Pool.js.map +1 -1
- package/dist/lib/core/Queue.d.ts +240 -0
- package/dist/lib/core/Queue.js +686 -0
- package/dist/lib/core/Queue.js.map +1 -0
- package/dist/lib/core/RelationManager.js +27 -25
- package/dist/lib/core/RelationManager.js.map +1 -1
- package/dist/lib/core/Repository.d.ts +73 -207
- package/dist/lib/core/Repository.js +120 -235
- package/dist/lib/core/Repository.js.map +1 -1
- package/dist/lib/core/Schema.d.ts +218 -0
- package/dist/lib/core/Schema.js +370 -65
- package/dist/lib/core/Schema.js.map +1 -1
- package/dist/lib/core/StateManager.d.ts +25 -12
- package/dist/lib/core/StateManager.js +10 -5
- package/dist/lib/core/StateManager.js.map +1 -1
- package/dist/lib/core/UtilityTypes.d.ts +85 -56
- package/dist/lib/core/UtilityTypes.js.map +1 -1
- package/dist/lib/core/index.d.ts +4 -0
- package/dist/lib/core/index.js +6 -2
- package/dist/lib/core/index.js.map +1 -1
- package/dist/lib/types/decorator/index.d.ts +1 -1
- package/dist/lib/types/index.d.ts +69 -22
- package/dist/lib/types/repository/index.d.ts +68 -37
- package/dist/lib/utils/index.d.ts +11 -1
- package/dist/lib/utils/index.js +58 -2
- package/dist/lib/utils/index.js.map +1 -1
- package/package.json +14 -6
- package/dist/lib/tools/index.js.map +0 -1
package/dist/lib/core/Model.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Blueprint } from "./Blueprint";
|
|
|
5
5
|
import { JoinModel } from "./JoinModel";
|
|
6
6
|
import { CONSTANTS } from "../constants";
|
|
7
7
|
import type { T } from "./UtilityTypes";
|
|
8
|
-
import type {
|
|
8
|
+
import type { TRelationOptions, TValidateSchema, TGlobalSetting, TPattern, TRelationQueryOptions, TModelOrObject, TRelationKeys, TLifecycle, TCacheModel, TRawStringQuery } from "../types";
|
|
9
9
|
import { Join } from "./Join";
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -79,11 +79,332 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
79
79
|
* @returns {Model} instance of the Model
|
|
80
80
|
*/
|
|
81
81
|
static get instance(): Model;
|
|
82
|
+
/**
|
|
83
|
+
* The 'query' method is used to return instance
|
|
84
|
+
* @static
|
|
85
|
+
* @example
|
|
86
|
+
* const user = await User.query().where('id',1).findOne();
|
|
87
|
+
* console.log(user);
|
|
88
|
+
*/
|
|
89
|
+
static query<T>(this: new () => T): T;
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* The 'find' method is used to retrieve a single record from a database table by its primary key.
|
|
93
|
+
*
|
|
94
|
+
* It allows you to retrieve a single record from a database table that meets the specified criteria.
|
|
95
|
+
* @type {?object} options
|
|
96
|
+
* @property {?object} options.select
|
|
97
|
+
* @property {?object} options.except
|
|
98
|
+
* @property {?object[]} options.orderBy
|
|
99
|
+
* @property {?string[]} options.groupBy
|
|
100
|
+
* @property {?string} options.having
|
|
101
|
+
* @property {?number} options.limit
|
|
102
|
+
* @property {?number} options.offset
|
|
103
|
+
* @property {?object} options.where
|
|
104
|
+
* @property {?string[]} options.whereRaw
|
|
105
|
+
* @property {?object} options.whereQuery
|
|
106
|
+
* @property {?{condition,callback}} options.when
|
|
107
|
+
* @property {?{localKey , referenceKey}[]} options.join
|
|
108
|
+
* @property {?{localKey , referenceKey}[]} options.rightJoin
|
|
109
|
+
* @property {?{localKey , referenceKey}[]} options.leftJoin
|
|
110
|
+
* @property {?string[]} options.relations
|
|
111
|
+
* @property {string[]} options.relationExists
|
|
112
|
+
* @property {?{condition,callback}} options.relationQuery
|
|
113
|
+
* @property {?boolean} options.debug
|
|
114
|
+
* @returns {promise<object>[]}
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* import { User } from '../Models/User'
|
|
118
|
+
*
|
|
119
|
+
* const users = await User.find({
|
|
120
|
+
* select : { id: true, name: true },
|
|
121
|
+
* where : {
|
|
122
|
+
* id: 1
|
|
123
|
+
* }
|
|
124
|
+
* })
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
static find<Self extends Model, M extends Model = Self, S extends T.SelectOptions<M> | undefined = undefined, SR extends T.RelationOptions<M> | undefined = undefined, E extends T.ExceptOptions<M> | undefined = undefined, SRS extends Record<string, TRawStringQuery> | undefined = undefined, G extends Record<string, T.RepositoryGenericTypeOptions> | undefined = {}>(this: new () => Self, primaryKey: number | string, options?: T.RepositoryOptions<M, S, SR, E, SRS, G>): Promise<T.ResultFiltered<M, S, SR, E, SRS, G> | null>;
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* The 'findOne' method is used to retrieve the get record that matches the query conditions.
|
|
131
|
+
*
|
|
132
|
+
* It allows you to retrieve a single record from a database table that meets the specified criteria.
|
|
133
|
+
* @type {?object} options
|
|
134
|
+
* @property {?object} options.select
|
|
135
|
+
* @property {?object} options.except
|
|
136
|
+
* @property {?object[]} options.orderBy
|
|
137
|
+
* @property {?string[]} options.groupBy
|
|
138
|
+
* @property {?string} options.having
|
|
139
|
+
* @property {?number} options.limit
|
|
140
|
+
* @property {?number} options.offset
|
|
141
|
+
* @property {?object} options.where
|
|
142
|
+
* @property {?string[]} options.whereRaw
|
|
143
|
+
* @property {?object} options.whereQuery
|
|
144
|
+
* @property {?{condition,callback}} options.when
|
|
145
|
+
* @property {?{localKey , referenceKey}[]} options.join
|
|
146
|
+
* @property {?{localKey , referenceKey}[]} options.rightJoin
|
|
147
|
+
* @property {?{localKey , referenceKey}[]} options.leftJoin
|
|
148
|
+
* @property {?string[]} options.relations
|
|
149
|
+
* @property {string[]} options.relationExists
|
|
150
|
+
* @property {?{condition,callback}} options.relationQuery
|
|
151
|
+
* @property {?boolean} options.debug
|
|
152
|
+
* @returns {promise<object>[]}
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* import { User } from '../Models/User'
|
|
156
|
+
*
|
|
157
|
+
* const users = await User.findOne({
|
|
158
|
+
* select : { id: true, name: true },
|
|
159
|
+
* where : {
|
|
160
|
+
* id: 1
|
|
161
|
+
* }
|
|
162
|
+
* })
|
|
163
|
+
*
|
|
164
|
+
*/
|
|
165
|
+
static findOne<Self extends Model, M extends Model = Self, S extends T.SelectOptions<M> | undefined = undefined, SR extends T.RelationOptions<M> | undefined = undefined, E extends T.ExceptOptions<M> | undefined = undefined, SRS extends Record<string, TRawStringQuery> | undefined = undefined, G extends Record<string, T.RepositoryGenericTypeOptions> | undefined = {}>(this: new () => Self, options?: T.RepositoryOptions<M, S, SR, E, SRS, G>): Promise<T.ResultFiltered<M, S, SR, E, SRS, G> | null>;
|
|
166
|
+
/**
|
|
167
|
+
*
|
|
168
|
+
* The 'findMany' method is used to retrieve the get record that matches the query conditions.
|
|
169
|
+
*
|
|
170
|
+
* It allows you to retrieve a single record from a database table that meets the specified criteria.
|
|
171
|
+
* @type {?object} options
|
|
172
|
+
* @property {?object} options.select
|
|
173
|
+
* @property {?object} options.except
|
|
174
|
+
* @property {?object[]} options.orderBy
|
|
175
|
+
* @property {?string[]} options.groupBy
|
|
176
|
+
* @property {?string} options.having
|
|
177
|
+
* @property {?number} options.limit
|
|
178
|
+
* @property {?number} options.offset
|
|
179
|
+
* @property {?object} options.where
|
|
180
|
+
* @property {?string[]} options.whereRaw
|
|
181
|
+
* @property {?object} options.whereQuery
|
|
182
|
+
* @property {?{condition,callback}} options.when
|
|
183
|
+
* @property {?{localKey , referenceKey}[]} options.join
|
|
184
|
+
* @property {?{localKey , referenceKey}[]} options.rightJoin
|
|
185
|
+
* @property {?{localKey , referenceKey}[]} options.leftJoin
|
|
186
|
+
* @property {?string[]} options.relations
|
|
187
|
+
* @property {string[]} options.relationExists
|
|
188
|
+
* @property {?{condition,callback}} options.relationQuery
|
|
189
|
+
* @property {?boolean} options.debug
|
|
190
|
+
* @returns {promise<object>[]}
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* import { User } from '../Models/User'
|
|
194
|
+
*
|
|
195
|
+
* const users = await User.findMany({
|
|
196
|
+
* select : { id: true, name: true },
|
|
197
|
+
* where : {
|
|
198
|
+
* id: 1
|
|
199
|
+
* }
|
|
200
|
+
* })
|
|
201
|
+
*
|
|
202
|
+
*/
|
|
203
|
+
static findMany<Self extends Model, M extends Model = Self, S extends T.SelectOptions<M> | undefined = undefined, SR extends T.RelationOptions<M> | undefined = undefined, E extends T.ExceptOptions<M> | undefined = undefined, SRS extends Record<string, TRawStringQuery> | undefined = undefined, G extends Record<string, T.RepositoryGenericTypeOptions> | undefined = {}>(this: new () => Self, options?: T.RepositoryOptions<M, S, SR, E, SRS, G>): Promise<T.ResultFiltered<M, S, SR, E, SRS, G>[]>;
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* The 'paginate' method is used to perform pagination on a set of database query results obtained through the Query Builder.
|
|
207
|
+
*
|
|
208
|
+
* It allows you to split a large set of query results into smaller, more manageable pages,
|
|
209
|
+
* making it easier to display data in a web application and improve user experience.
|
|
210
|
+
* @type {?object} options
|
|
211
|
+
* @property {?object} options.select
|
|
212
|
+
* @property {?object} options.except
|
|
213
|
+
* @property {?object[]} options.orderBy
|
|
214
|
+
* @property {?string[]} options.groupBy
|
|
215
|
+
* @property {?string} options.having
|
|
216
|
+
* @property {?number} options.limit
|
|
217
|
+
* @property {?number} options.offset
|
|
218
|
+
* @property {?object} options.where
|
|
219
|
+
* @property {?string[]} options.whereRaw
|
|
220
|
+
* @property {?object} options.whereQuery
|
|
221
|
+
* @property {?{condition,callback}} options.when
|
|
222
|
+
* @property {?{localKey , referenceKey}[]} options.join
|
|
223
|
+
* @property {?{localKey , referenceKey}[]} options.rightJoin
|
|
224
|
+
* @property {?{localKey , referenceKey}[]} options.leftJoin
|
|
225
|
+
* @property {?string[]} options.relations
|
|
226
|
+
* @property {string[]} options.relationExists
|
|
227
|
+
* @property {?{condition,callback}} options.relationQuery
|
|
228
|
+
* @property {?boolean} options.debug
|
|
229
|
+
* @property {?number} options.page
|
|
230
|
+
* @returns {promise<{ meta , data[]}>}
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* import { User } from '../Models/User'
|
|
234
|
+
*
|
|
235
|
+
* const users = await User.paginate({
|
|
236
|
+
* limit:15,
|
|
237
|
+
* page: 1,
|
|
238
|
+
* select : { id: true, name: true },
|
|
239
|
+
* where : {
|
|
240
|
+
* id: 1
|
|
241
|
+
* }
|
|
242
|
+
* })
|
|
243
|
+
*/
|
|
244
|
+
static paginate<Self extends Model, M extends Model = Self, S extends T.SelectOptions<M> | undefined = undefined, SR extends T.RelationOptions<M> | undefined = undefined, E extends T.ExceptOptions<M> | undefined = undefined, SRS extends Record<string, TRawStringQuery> | undefined = undefined, G extends Record<string, T.RepositoryGenericTypeOptions> | undefined = {}>(this: new () => Self, options?: Omit<Partial<T.RepositoryOptions<M, S, SR, E, SRS, G>> & {
|
|
245
|
+
page?: number;
|
|
246
|
+
}, 'offset'>): Promise<T.PaginateResultFiltered<M, S, SR, E, SRS, G>>;
|
|
247
|
+
/**
|
|
248
|
+
* The 'exists' method is used to determine if any records exist in the database table that match the query conditions.
|
|
249
|
+
*
|
|
250
|
+
* It returns a boolean value indicating whether there are any matching records.
|
|
251
|
+
* @type {?object} options
|
|
252
|
+
* @property {?object} options.select
|
|
253
|
+
* @property {?object} options.except
|
|
254
|
+
* @property {?object[]} options.orderBy
|
|
255
|
+
* @property {?string[]} options.groupBy
|
|
256
|
+
* @property {?string} options.having
|
|
257
|
+
* @property {?number} options.limit
|
|
258
|
+
* @property {?number} options.offset
|
|
259
|
+
* @property {?object} options.where
|
|
260
|
+
* @property {?string[]} options.whereRaw
|
|
261
|
+
* @property {?object} options.whereQuery
|
|
262
|
+
* @property {?{condition,callback}} options.when
|
|
263
|
+
* @property {?{localKey , referenceKey}[]} options.join
|
|
264
|
+
* @property {?{localKey , referenceKey}[]} options.rightJoin
|
|
265
|
+
* @property {?{localKey , referenceKey}[]} options.leftJoin
|
|
266
|
+
* @property {?boolean} options.debug
|
|
267
|
+
* @property {?number} options.page
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* import { User } from '../Models/User'
|
|
271
|
+
*
|
|
272
|
+
* const users = await User.exists({
|
|
273
|
+
* where : {
|
|
274
|
+
* id: 1
|
|
275
|
+
* }
|
|
276
|
+
* })
|
|
277
|
+
*
|
|
278
|
+
*/
|
|
279
|
+
static exists<Self extends Model, M extends Model = Self>(this: new () => Self, options: Partial<Omit<T.RepositoryOptions<M>, "relations" | "relationQuery">>): Promise<boolean>;
|
|
280
|
+
/**
|
|
281
|
+
* The 'toQuery' method is used to retrieve the raw SQL query that would be executed by a query builder instance without actually executing it.
|
|
282
|
+
*
|
|
283
|
+
* This method is particularly useful for debugging and understanding the SQL queries generated by your application.
|
|
284
|
+
* @type {?object} options
|
|
285
|
+
* @property {?object} options.select
|
|
286
|
+
* @property {?object} options.except
|
|
287
|
+
* @property {?object[]} options.orderBy
|
|
288
|
+
* @property {?string[]} options.groupBy
|
|
289
|
+
* @property {?string} options.having
|
|
290
|
+
* @property {?number} options.limit
|
|
291
|
+
* @property {?number} options.offset
|
|
292
|
+
* @property {?object} options.where
|
|
293
|
+
* @property {?string[]} options.whereRaw
|
|
294
|
+
* @property {?object} options.whereQuery
|
|
295
|
+
* @property {?{condition,callback}} options.when
|
|
296
|
+
* @property {?{localKey , referenceKey}[]} options.join
|
|
297
|
+
* @property {?{localKey , referenceKey}[]} options.rightJoin
|
|
298
|
+
* @property {?{localKey , referenceKey}[]} options.leftJoin
|
|
299
|
+
* @property {?boolean} options.debug
|
|
300
|
+
* @property {?number} options.page
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* import { User } from '../Models/User'
|
|
304
|
+
*
|
|
305
|
+
* const users = await User.exists({
|
|
306
|
+
* where : {
|
|
307
|
+
* id: 1
|
|
308
|
+
* }
|
|
309
|
+
* })
|
|
310
|
+
*
|
|
311
|
+
*/
|
|
312
|
+
static toQuery<Self extends Model, M extends Model = Self>(this: new () => Self, options: Partial<Omit<T.RepositoryOptions<M>, "relations" | "relationQuery">>): string;
|
|
313
|
+
/**
|
|
314
|
+
* The 'create' method is used to insert a new record into a database table associated.
|
|
315
|
+
*
|
|
316
|
+
* It simplifies the process of creating and inserting records.
|
|
317
|
+
* @type {object} options
|
|
318
|
+
* @property {object} options.data
|
|
319
|
+
* @property {?boolean} options.debug
|
|
320
|
+
* @property {?transaction} options.transaction
|
|
321
|
+
* @return {promise<T.Result<M>>}
|
|
322
|
+
*/
|
|
323
|
+
static create<Self extends Model, M extends Model = Self, NR extends boolean | undefined = false>(this: new () => Self, options: T.RepositoryCreate<M, NR>): Promise<NR extends true ? undefined : T.Result<M>>;
|
|
324
|
+
/**
|
|
325
|
+
* The 'createMany' method is used to insert a new records into a database table associated.
|
|
326
|
+
*
|
|
327
|
+
* It simplifies the process of creating and inserting records with an array.
|
|
328
|
+
* @type {object} options
|
|
329
|
+
* @property {object[]} options.data
|
|
330
|
+
* @property {?boolean} options.debug
|
|
331
|
+
* @property {?transaction} options.transaction
|
|
332
|
+
* @return {promise<TS[]>}
|
|
333
|
+
*/
|
|
334
|
+
static createMany<Self extends Model, M extends Model = Self, NR extends boolean | undefined = false>(this: new () => Self, options: T.RepositoryCreateMultiple<M, NR>): Promise<NR extends true ? undefined : T.Result<M>[]>;
|
|
335
|
+
/**
|
|
336
|
+
*
|
|
337
|
+
* The 'createOrUpdate' method allows you to update an existing record in a database table if it exists or create a new record if it does not exist.
|
|
338
|
+
*
|
|
339
|
+
* This method is particularly useful when you want to update a record based on certain conditions and,
|
|
340
|
+
* if the record matching those conditions doesn't exist, create a new one with the provided data.
|
|
341
|
+
* @type {object} options
|
|
342
|
+
* @property {object} options.data
|
|
343
|
+
* @property {object} options.where
|
|
344
|
+
* @property {?boolean} options.debug
|
|
345
|
+
* @return {promise<NR extends true ? undefined : T.Result<M>[]>}
|
|
346
|
+
*/
|
|
347
|
+
static createOrUpdate<Self extends Model, M extends Model = Self, NR extends boolean | undefined = false>(this: new () => Self, options: T.RepositoryCreateOrThings<M, NR>): Promise<NR extends true ? undefined : T.Result<M>[]>;
|
|
348
|
+
/**
|
|
349
|
+
* The 'createNotExists' method to insert data into a database table while ignoring any duplicate key constraint violations.
|
|
350
|
+
*
|
|
351
|
+
* This method is particularly useful when you want to insert records into a table and ensure that duplicates are not inserted,
|
|
352
|
+
* but without raising an error or exception if duplicates are encountered.
|
|
353
|
+
*
|
|
354
|
+
* @type {object} options
|
|
355
|
+
* @property {object} options.data
|
|
356
|
+
* @property {object} options.where
|
|
357
|
+
* @property {?boolean} options.debug
|
|
358
|
+
* @property {?transaction} options.transaction
|
|
359
|
+
* @return {promise<T | null>}
|
|
360
|
+
*/
|
|
361
|
+
static createNotExists<Self extends Model, M extends Model = Self, NR extends boolean | undefined = false>(this: new () => Self, options: T.RepositoryCreateOrThings<M, NR>): Promise<NR extends true ? undefined : T.Result<M> | null>;
|
|
362
|
+
/**
|
|
363
|
+
*
|
|
364
|
+
* The 'createOrSelect' method to insert data into a database table while select any duplicate key constraint violations.
|
|
365
|
+
*
|
|
366
|
+
* This method is particularly useful when you want to insert records into a table and ensure that duplicates are not inserted,
|
|
367
|
+
* but if exists should be returns a result.
|
|
368
|
+
* @type {object} options
|
|
369
|
+
* @property {object} options.data
|
|
370
|
+
* @property {object} options.where
|
|
371
|
+
* @property {?boolean} options.debug
|
|
372
|
+
* @return {promise<T.Result<M>>}
|
|
373
|
+
*/
|
|
374
|
+
static createOrSelect<Self extends Model, M extends Model = Self, NR extends boolean | undefined = false>(this: new () => Self, options: T.RepositoryCreateOrThings<M, NR>): Promise<NR extends true ? undefined : T.Result<M> | null>;
|
|
375
|
+
/**
|
|
376
|
+
* The 'update' method is used to update existing records in a database table that are associated.
|
|
377
|
+
*
|
|
378
|
+
* It simplifies the process of updating records by allowing you to specify the values to be updated using a single call.
|
|
379
|
+
*
|
|
380
|
+
* It allows you to remove one record that match certain criteria.
|
|
381
|
+
* @type {object} options
|
|
382
|
+
* @property {object} options.data
|
|
383
|
+
* @property {object} options.where
|
|
384
|
+
* @property {?boolean} options.debug
|
|
385
|
+
* @property {?transaction} options.transaction
|
|
386
|
+
* @return {promise< NR extends true ? undefined : T.Result<M> | null>}
|
|
387
|
+
*/
|
|
388
|
+
static update<Self extends Model, M extends Model = Self, NR extends boolean | undefined = false>(this: new () => Self, options: T.RepositoryUpdate<M, NR>): Promise<NR extends true ? undefined : T.Result<M> | null>;
|
|
389
|
+
/**
|
|
390
|
+
* The 'updateMany' method is used to update existing records in a database table that are associated.
|
|
391
|
+
*
|
|
392
|
+
* It simplifies the process of updating records by allowing you to specify the values to be updated using a single call.
|
|
393
|
+
*
|
|
394
|
+
* It allows you to remove more records that match certain criteria.
|
|
395
|
+
* @type {object} options
|
|
396
|
+
* @property {object} options.data
|
|
397
|
+
* @property {object} options.where
|
|
398
|
+
* @property {?boolean} options.debug
|
|
399
|
+
* @property {?transaction} options.transaction
|
|
400
|
+
* @return {promise<T.Result<M>[]>}
|
|
401
|
+
*/
|
|
402
|
+
static updateMany<Self extends Model, M extends Model = Self, NR extends boolean | undefined = false>(this: new () => Self, options: T.RepositoryUpdate<M, NR>): Promise<NR extends true ? undefined : T.Result<M>[]>;
|
|
82
403
|
/**
|
|
83
404
|
* The 'cache' method is used get the functions from the Cache
|
|
84
|
-
* @returns {
|
|
405
|
+
* @returns {TCacheModel} cache
|
|
85
406
|
*/
|
|
86
|
-
static get cache():
|
|
407
|
+
static get cache(): TCacheModel;
|
|
87
408
|
/**
|
|
88
409
|
* The 'boot' method is a special method that you can define within a model.
|
|
89
410
|
* @example
|
|
@@ -223,29 +544,29 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
223
544
|
*/
|
|
224
545
|
protected useSchema(schema: Record<string, Blueprint>): this;
|
|
225
546
|
/**
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
547
|
+
* The "useTransform " method is used to define value transformers for model columns..
|
|
548
|
+
*
|
|
549
|
+
* Each transformer defines how a value is converted:
|
|
550
|
+
* - `to` : before persisting to the database
|
|
551
|
+
* - `from` : after retrieving from the database
|
|
552
|
+
*
|
|
553
|
+
* Transformers can be synchronous or asynchronous.
|
|
554
|
+
*
|
|
555
|
+
* @param {object} transforms
|
|
556
|
+
* @example
|
|
557
|
+
* import { Blueprint } from 'tspace-mysql';
|
|
558
|
+
* class User extends Model {
|
|
559
|
+
* boot() {
|
|
560
|
+
* this.useTransform({
|
|
561
|
+
* name : {
|
|
562
|
+
* to : async (v) => `${v}-> transform@before`,
|
|
563
|
+
* from : async (v) => `${v}-> transform@after`,
|
|
564
|
+
* },
|
|
565
|
+
* })
|
|
566
|
+
* }
|
|
567
|
+
* }
|
|
568
|
+
* @returns {this} this
|
|
569
|
+
*/
|
|
249
570
|
protected useTransform(transforms: Record<string, {
|
|
250
571
|
to: (value: unknown) => any | Promise<any>;
|
|
251
572
|
from: (value: unknown) => any | Promise<any>;
|
|
@@ -524,7 +845,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
524
845
|
* this
|
|
525
846
|
* .useLifecycle("beforeInsert", fnA)
|
|
526
847
|
* .useLifecycle("afterInsert", fnB);
|
|
527
|
-
|
|
848
|
+
*/
|
|
528
849
|
protected useLifecycle(type: TLifecycle, funcs: Function | Function[]): this;
|
|
529
850
|
/**
|
|
530
851
|
* The "whenCreatingTable" method is used exection function when creating the table.
|
|
@@ -613,11 +934,13 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
613
934
|
* @param {Object} object
|
|
614
935
|
* @property {string} key key of cache
|
|
615
936
|
* @property {number} expires ms
|
|
937
|
+
* @property {boolean} namespace whether to use namespace for cache key, default is false, namespace is `${database}:${table}:${key}`
|
|
616
938
|
* @returns {this} this
|
|
617
939
|
*/
|
|
618
|
-
cache({ key, expires }: {
|
|
940
|
+
cache({ key, expires, namespace }: {
|
|
619
941
|
key: string;
|
|
620
942
|
expires: number;
|
|
943
|
+
namespace?: boolean;
|
|
621
944
|
}): this;
|
|
622
945
|
/**
|
|
623
946
|
*
|
|
@@ -1404,22 +1727,26 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1404
1727
|
* @returns {string} string
|
|
1405
1728
|
*/
|
|
1406
1729
|
toTableNameAndColumn(column: string): string;
|
|
1730
|
+
where<K extends T.ColumnKeys<this>, V extends (K & keyof T.ColumnOptions<this> extends never ? any : T.ColumnOptions<this>[K & keyof T.ColumnOptions<this>])>(column: K, value: V): this;
|
|
1731
|
+
where<K extends T.ColumnKeys<this>, V extends (K & keyof T.ColumnOptions<this> extends never ? any : T.ColumnOptions<this>[K & keyof T.ColumnOptions<this>])>(column: K, operator: "=" | "<" | ">" | "!=" | "<>" | "<=" | ">=" | "LIKE" | "like", value: V): this;
|
|
1732
|
+
where(column: Partial<{
|
|
1733
|
+
[K in keyof T.ColumnOptions<this>]: T.ColumnOptions<this>[K];
|
|
1734
|
+
}>): this;
|
|
1735
|
+
/**
|
|
1736
|
+
* @override
|
|
1737
|
+
* @param {string | K} column if arguments is object
|
|
1738
|
+
* @param {any?} value
|
|
1739
|
+
* @returns {this} this
|
|
1740
|
+
*/
|
|
1741
|
+
orWhere<K extends T.ColumnKeys<this>, V extends (K & keyof T.ColumnOptions<this> extends never ? any : T.ColumnOptions<this>[K & keyof T.ColumnOptions<this>])>(column: K, value: V): this;
|
|
1407
1742
|
/**
|
|
1408
1743
|
* @override
|
|
1409
1744
|
* @param {string | K} column if arguments is object
|
|
1410
|
-
* @param {string?} operator
|
|
1745
|
+
* @param {string?} operator "=" | "<" | ">" | "!=" | "<>" | "<=" | ">=" | "LIKE" | "like"
|
|
1411
1746
|
* @param {any?} value
|
|
1412
1747
|
* @returns {this} this
|
|
1413
1748
|
*/
|
|
1414
|
-
|
|
1415
|
-
/**
|
|
1416
|
-
* @override
|
|
1417
|
-
* @param {string} column
|
|
1418
|
-
* @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE']
|
|
1419
|
-
* @param {any?} value
|
|
1420
|
-
* @returns {this}
|
|
1421
|
-
*/
|
|
1422
|
-
orWhere<K extends T.ColumnKeys<this>>(column: K, operator?: any, value?: any): this;
|
|
1749
|
+
orWhere<K extends T.ColumnKeys<this>, V extends (K & keyof T.ColumnOptions<this> extends never ? any : T.ColumnOptions<this>[K & keyof T.ColumnOptions<this>])>(column: K, operator: "=" | "<" | ">" | "!=" | "<>" | "<=" | ">=" | "LIKE" | "like", value: V): this;
|
|
1423
1750
|
/**
|
|
1424
1751
|
* @override
|
|
1425
1752
|
* @param {string} column
|
|
@@ -1560,28 +1887,28 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1560
1887
|
* @param {array} array
|
|
1561
1888
|
* @returns {this}
|
|
1562
1889
|
*/
|
|
1563
|
-
whereBetween<K extends T.ColumnKeys<this
|
|
1890
|
+
whereBetween<K extends T.ColumnKeys<this>, V extends (K & keyof T.ColumnOptions<this> extends never ? any : T.ColumnOptions<this>[K & keyof T.ColumnOptions<this>])>(column: K, array: [V, V]): this;
|
|
1564
1891
|
/**
|
|
1565
1892
|
* @override
|
|
1566
1893
|
* @param {string} column
|
|
1567
1894
|
* @param {array} array
|
|
1568
1895
|
* @returns {this}
|
|
1569
1896
|
*/
|
|
1570
|
-
orWhereBetween<K extends T.ColumnKeys<this
|
|
1897
|
+
orWhereBetween<K extends T.ColumnKeys<this>, V extends (K & keyof T.ColumnOptions<this> extends never ? any : T.ColumnOptions<this>[K & keyof T.ColumnOptions<this>])>(column: K, array: [V, V]): this;
|
|
1571
1898
|
/**
|
|
1572
1899
|
* @override
|
|
1573
1900
|
* @param {string} column
|
|
1574
1901
|
* @param {array} array
|
|
1575
1902
|
* @returns {this}
|
|
1576
1903
|
*/
|
|
1577
|
-
whereNotBetween<K extends T.ColumnKeys<this
|
|
1904
|
+
whereNotBetween<K extends T.ColumnKeys<this>, V extends (K & keyof T.ColumnOptions<this> extends never ? any : T.ColumnOptions<this>[K & keyof T.ColumnOptions<this>])>(column: K, array: [V, V]): this;
|
|
1578
1905
|
/**
|
|
1579
1906
|
* @override
|
|
1580
1907
|
* @param {string} column
|
|
1581
1908
|
* @param {array} array
|
|
1582
1909
|
* @returns {this}
|
|
1583
1910
|
*/
|
|
1584
|
-
orWhereNotBetween<K extends T.ColumnKeys<this
|
|
1911
|
+
orWhereNotBetween<K extends T.ColumnKeys<this>, V extends (K & keyof T.ColumnOptions<this> extends never ? any : T.ColumnOptions<this>[K & keyof T.ColumnOptions<this>])>(column: K, array: [V, V]): this;
|
|
1585
1912
|
/**
|
|
1586
1913
|
* @override
|
|
1587
1914
|
* @param {string} column
|
|
@@ -1653,6 +1980,12 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1653
1980
|
* @returns {this}
|
|
1654
1981
|
*/
|
|
1655
1982
|
whereQuery<T extends Model | unknown, M = T extends this ? this : T extends Model ? T : this>(callback: (query: M) => M): this;
|
|
1983
|
+
/**
|
|
1984
|
+
* @override
|
|
1985
|
+
* @param {Function} callback callback query
|
|
1986
|
+
* @returns {this}
|
|
1987
|
+
*/
|
|
1988
|
+
orWhereQuery<T extends Model | unknown, M = T extends this ? this : T extends Model ? T : this>(callback: (query: M) => M): this;
|
|
1656
1989
|
/**
|
|
1657
1990
|
* @override
|
|
1658
1991
|
* @param {string[]} columns
|
|
@@ -1802,6 +2135,40 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1802
2135
|
* @returns {this}
|
|
1803
2136
|
*/
|
|
1804
2137
|
crossJoinModel(m1: TModelOrObject | ((join: JoinModel) => JoinModel), m2?: TModelOrObject): this;
|
|
2138
|
+
/**
|
|
2139
|
+
*
|
|
2140
|
+
* @override
|
|
2141
|
+
* @param {string=} column [column=id]
|
|
2142
|
+
* @returns {promise<number>}
|
|
2143
|
+
*/
|
|
2144
|
+
count<K extends T.ColumnKeys<this> | "id" | "_id">(c?: K): Promise<number>;
|
|
2145
|
+
/**
|
|
2146
|
+
*
|
|
2147
|
+
* @override
|
|
2148
|
+
* @param {string=} column [column=id]
|
|
2149
|
+
* @returns {promise<number>}
|
|
2150
|
+
*/
|
|
2151
|
+
avg<K extends T.ColumnKeys<this> | "id" | "_id">(c?: K): Promise<number>;
|
|
2152
|
+
/**
|
|
2153
|
+
*
|
|
2154
|
+
* @override
|
|
2155
|
+
* @param {string=} column [column=id]
|
|
2156
|
+
* @returns {promise<number>}
|
|
2157
|
+
*/
|
|
2158
|
+
sum<K extends T.ColumnKeys<this> | "id" | "_id">(c?: K): Promise<number>;
|
|
2159
|
+
/**
|
|
2160
|
+
*
|
|
2161
|
+
* @override
|
|
2162
|
+
* @param {string=} column [column=id]
|
|
2163
|
+
* @returns {promise<number>}
|
|
2164
|
+
*/
|
|
2165
|
+
max<K extends T.ColumnKeys<this> | "id" | "_id">(c?: K): Promise<number>;
|
|
2166
|
+
/**
|
|
2167
|
+
* @override
|
|
2168
|
+
* @param {string} c
|
|
2169
|
+
* @returns {promise<number>}
|
|
2170
|
+
*/
|
|
2171
|
+
min<K extends T.ColumnKeys<this> | "id" | "_id">(c: K): Promise<number>;
|
|
1805
2172
|
/**
|
|
1806
2173
|
* @override
|
|
1807
2174
|
* @returns {promise<boolean>} promise boolean
|
|
@@ -1871,6 +2238,12 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1871
2238
|
* @returns {promise<Record<string,any> | null>} Record | null
|
|
1872
2239
|
*/
|
|
1873
2240
|
findOne<K>(cb?: Function): Promise<T.Result<this, K> | null>;
|
|
2241
|
+
/**
|
|
2242
|
+
* @override
|
|
2243
|
+
* @param {number} id callback function return query sql
|
|
2244
|
+
* @returns {promise<Record<string,any> | null>} Record | null
|
|
2245
|
+
*/
|
|
2246
|
+
find<K>(primaryKey: number | string): Promise<T.Result<this, K> | null>;
|
|
1874
2247
|
/**
|
|
1875
2248
|
* @override
|
|
1876
2249
|
* @returns {promise<object | Error>} Record | throw error
|
|
@@ -1951,52 +2324,46 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
1951
2324
|
* @returns {this} this
|
|
1952
2325
|
*/
|
|
1953
2326
|
insert<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: {
|
|
1954
|
-
[P in Exclude<K & keyof C, "id"> as null extends C[P] ? any :
|
|
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;
|
|
1955
2328
|
}): this;
|
|
1956
2329
|
/**
|
|
1957
2330
|
* @override
|
|
1958
2331
|
* @param {object} data for insert
|
|
1959
2332
|
* @returns {this} this
|
|
1960
2333
|
*/
|
|
1961
|
-
create<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data:
|
|
1962
|
-
[P in Exclude<K & keyof C, "id"> as null extends C[P] ? any : undefined extends C[P] ? never : P]: Extract<C[P], Date> extends never ? C[P] : any;
|
|
1963
|
-
}): this;
|
|
2334
|
+
create<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
1964
2335
|
/**
|
|
1965
2336
|
* @override
|
|
1966
2337
|
* @param {object} data
|
|
1967
2338
|
* @param {array?} updateNotExists options for except update some records in your ${data}
|
|
1968
2339
|
* @returns {this} this
|
|
1969
2340
|
*/
|
|
1970
|
-
update<K extends T.ColumnKeys<this>,
|
|
1971
|
-
[P in K & keyof T]: T[P];
|
|
1972
|
-
}, updateNotExists?: T.ColumnKeys<this>[]): this;
|
|
2341
|
+
update<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>, updateNotExists?: T.ColumnKeys<this>[]): this;
|
|
1973
2342
|
/**
|
|
1974
2343
|
* @override
|
|
1975
2344
|
* @param {object} data
|
|
1976
2345
|
* @param {array?} updateNotExists options for except update some records in your ${data}
|
|
1977
2346
|
* @returns {this} this
|
|
1978
2347
|
*/
|
|
1979
|
-
updateMany<K extends T.ColumnKeys<this>,
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
* @returns {this} this
|
|
1993
|
-
*/
|
|
2348
|
+
updateMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>, updateNotExists?: string[]): this;
|
|
2349
|
+
/**
|
|
2350
|
+
*
|
|
2351
|
+
* @override
|
|
2352
|
+
* @param {Array<{when: Record<string, string | number | boolean | null | undefined>, columns: Record<string, string | number | boolean | null | undefined>}>>} cases
|
|
2353
|
+
* An array of update cases.
|
|
2354
|
+
* - `when` is an object specifying the conditions to match records.
|
|
2355
|
+
* - `columns` is an object specifying the new values to set for the matched records.
|
|
2356
|
+
*
|
|
2357
|
+
* @property {Record<string,string | number | boolean | null | undefined>} cases.when
|
|
2358
|
+
* @property {Record<string,string | number | boolean | null | undefined>} cases.columns
|
|
2359
|
+
* @returns {this} this
|
|
2360
|
+
*/
|
|
1994
2361
|
updateCases<T extends T.ColumnOptions<this>, K extends keyof T, U extends Model | unknown, M = U extends this ? this : U extends Model ? U : this>(cases: {
|
|
1995
2362
|
condition: ((query: M) => M) | Partial<{
|
|
1996
|
-
[P in K & keyof T]: T[P];
|
|
2363
|
+
[P in K & keyof T]: Extract<T[P], Record<string, unknown>> extends never ? T[P] : string;
|
|
1997
2364
|
}>;
|
|
1998
2365
|
columns: Partial<{
|
|
1999
|
-
[P in K & keyof T]: T[P];
|
|
2366
|
+
[P in K & keyof T]: Extract<T[P], Record<string, unknown>> extends never ? T[P] : string;
|
|
2000
2367
|
}>;
|
|
2001
2368
|
}[]): this;
|
|
2002
2369
|
/**
|
|
@@ -2004,110 +2371,84 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2004
2371
|
* @param {object} data
|
|
2005
2372
|
* @returns {this} this
|
|
2006
2373
|
*/
|
|
2007
|
-
updateNotExists<K extends T.ColumnKeys<this>,
|
|
2008
|
-
[P in K & keyof T]: T[P];
|
|
2009
|
-
}): this;
|
|
2374
|
+
updateNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.UpdateInput<K, C>): this;
|
|
2010
2375
|
/**
|
|
2011
2376
|
* @override
|
|
2012
2377
|
* @param {object} data for update or create
|
|
2013
2378
|
* @returns {this} this
|
|
2014
2379
|
*/
|
|
2015
|
-
updateOrCreate<K extends T.ColumnKeys<this>,
|
|
2016
|
-
[P in K & keyof T]: T[P];
|
|
2017
|
-
}): this;
|
|
2380
|
+
updateOrCreate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
2018
2381
|
/**
|
|
2019
2382
|
* @override
|
|
2020
2383
|
* @param {object} data for update or create
|
|
2021
2384
|
* @returns {this} this
|
|
2022
2385
|
*/
|
|
2023
|
-
updateOrInsert<K extends T.ColumnKeys<this>,
|
|
2024
|
-
[P in K & keyof T]: T[P];
|
|
2025
|
-
}): this;
|
|
2386
|
+
updateOrInsert<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
2026
2387
|
/**
|
|
2027
2388
|
* @override
|
|
2028
2389
|
* @param {object} data for update or create
|
|
2029
2390
|
* @returns {this} this
|
|
2030
2391
|
*/
|
|
2031
|
-
insertOrUpdate<K extends T.ColumnKeys<this>,
|
|
2032
|
-
[P in K & keyof T]: T[P];
|
|
2033
|
-
}): this;
|
|
2392
|
+
insertOrUpdate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
2034
2393
|
/**
|
|
2035
2394
|
* @override
|
|
2036
2395
|
* @param {object} data for update or create
|
|
2037
2396
|
* @returns {this} this
|
|
2038
2397
|
*/
|
|
2039
|
-
createOrUpdate<K extends T.ColumnKeys<this>,
|
|
2040
|
-
[P in K & keyof T]: T[P];
|
|
2041
|
-
}): this;
|
|
2398
|
+
createOrUpdate<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
2042
2399
|
/**
|
|
2043
2400
|
* @override
|
|
2044
2401
|
* @param {object} data for create
|
|
2045
2402
|
* @returns {this} this
|
|
2046
2403
|
*/
|
|
2047
|
-
createOrSelect<K extends T.ColumnKeys<this>,
|
|
2048
|
-
[P in K & keyof T]: T[P];
|
|
2049
|
-
}): this;
|
|
2404
|
+
createOrSelect<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
2050
2405
|
/**
|
|
2051
2406
|
* @override
|
|
2052
2407
|
* @param {object} data for update or create
|
|
2053
2408
|
* @returns {this} this
|
|
2054
2409
|
*/
|
|
2055
|
-
insertOrSelect<K extends T.ColumnKeys<this>,
|
|
2056
|
-
[P in K & keyof T]: T[P];
|
|
2057
|
-
}): this;
|
|
2410
|
+
insertOrSelect<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
2058
2411
|
/**
|
|
2059
2412
|
*
|
|
2060
2413
|
* @override
|
|
2061
2414
|
* @param {object} data create not exists data
|
|
2062
2415
|
* @returns {this} this
|
|
2063
2416
|
*/
|
|
2064
|
-
createNotExists<K extends T.ColumnKeys<this>,
|
|
2065
|
-
[P in K & keyof T]: T[P];
|
|
2066
|
-
}): this;
|
|
2417
|
+
createNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
2067
2418
|
/**
|
|
2068
2419
|
*
|
|
2069
2420
|
* @override
|
|
2070
2421
|
* @param {object} data create not exists data
|
|
2071
2422
|
* @returns {this} this this
|
|
2072
2423
|
*/
|
|
2073
|
-
insertNotExists<K extends T.ColumnKeys<this>,
|
|
2074
|
-
[P in K & keyof T]: T[P];
|
|
2075
|
-
}): this;
|
|
2424
|
+
insertNotExists<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>): this;
|
|
2076
2425
|
/**
|
|
2077
2426
|
* @override
|
|
2078
2427
|
* @param {Record<string,any>[]} data create multiple data
|
|
2079
2428
|
* @returns {this} this this
|
|
2080
2429
|
*/
|
|
2081
|
-
createMultiple<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data:
|
|
2082
|
-
[P in Exclude<K & keyof C, "id"> as null extends C[P] ? any : undefined extends C[P] ? never : P]: Extract<C[P], Date> extends never ? C[P] : any;
|
|
2083
|
-
}[]): this;
|
|
2430
|
+
createMultiple<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]): this;
|
|
2084
2431
|
/**
|
|
2085
2432
|
*
|
|
2086
2433
|
* @override
|
|
2087
2434
|
* @param {Record<string,any>[]} data create multiple data
|
|
2088
2435
|
* @returns {this} this
|
|
2089
2436
|
*/
|
|
2090
|
-
createMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data:
|
|
2091
|
-
[P in Exclude<K & keyof C, "id"> as null extends C[P] ? any : undefined extends C[P] ? never : P]: Extract<C[P], Date> extends never ? C[P] : any;
|
|
2092
|
-
}[]): this;
|
|
2437
|
+
createMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]): this;
|
|
2093
2438
|
/**
|
|
2094
2439
|
*
|
|
2095
2440
|
* @override
|
|
2096
2441
|
* @param {Record<string,any>[]} data create multiple data
|
|
2097
2442
|
* @returns {this} this
|
|
2098
2443
|
*/
|
|
2099
|
-
insertMultiple<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data:
|
|
2100
|
-
[P in Exclude<K & keyof C, "id"> as null extends C[P] ? any : undefined extends C[P] ? never : P]: Extract<C[P], Date> extends never ? C[P] : any;
|
|
2101
|
-
}[]): this;
|
|
2444
|
+
insertMultiple<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]): this;
|
|
2102
2445
|
/**
|
|
2103
2446
|
*
|
|
2104
2447
|
* @override
|
|
2105
2448
|
* @param {Record<string,any>[]} data create multiple data
|
|
2106
2449
|
* @returns {this} this
|
|
2107
2450
|
*/
|
|
2108
|
-
insertMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data:
|
|
2109
|
-
[P in Exclude<K & keyof C, "id"> as null extends C[P] ? any : undefined extends C[P] ? never : P]: Extract<C[P], Date> extends never ? C[P] : any;
|
|
2110
|
-
}[]): this;
|
|
2451
|
+
insertMany<K extends T.ColumnKeys<this>, C extends T.ColumnOptions<this>>(data: T.InsertInput<K, C>[]): this;
|
|
2111
2452
|
/**
|
|
2112
2453
|
* The 'getSchemaModel' method is used get a schema model
|
|
2113
2454
|
* @returns {Record<string, Blueprint> | null} Record<string, Blueprint> | null
|
|
@@ -2180,6 +2521,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2180
2521
|
private _makeTableName;
|
|
2181
2522
|
private _handleSoftDelete;
|
|
2182
2523
|
private _prepareQueryPipeline;
|
|
2524
|
+
private _ensureRelationOwnerKeysSelected;
|
|
2183
2525
|
private _handleGlobalScope;
|
|
2184
2526
|
/**
|
|
2185
2527
|
* @override
|
|
@@ -2191,9 +2533,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2191
2533
|
* generate sql statements
|
|
2192
2534
|
* @override
|
|
2193
2535
|
*/
|
|
2194
|
-
protected _queryBuilder(
|
|
2195
|
-
onFormat?: boolean | undefined;
|
|
2196
|
-
}): any;
|
|
2536
|
+
protected _queryBuilder(): any;
|
|
2197
2537
|
private _runBefore;
|
|
2198
2538
|
private _runAfter;
|
|
2199
2539
|
private _validateSchema;
|
|
@@ -2213,6 +2553,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2213
2553
|
private _insertOrSelectModel;
|
|
2214
2554
|
private _updateModel;
|
|
2215
2555
|
private _assertError;
|
|
2556
|
+
disabledRetry(): this;
|
|
2216
2557
|
private _checkSchemaOrNextError;
|
|
2217
2558
|
private _stoppedRetry;
|
|
2218
2559
|
private _observer;
|
|
@@ -2221,6 +2562,7 @@ declare class Model<TS extends Record<string, any> = any, TR = unknown> extends
|
|
|
2221
2562
|
private _isModel;
|
|
2222
2563
|
private _getBlueprintByColumn;
|
|
2223
2564
|
private _handleJoinModel;
|
|
2565
|
+
private _formatedInputData;
|
|
2224
2566
|
private _initialModel;
|
|
2225
2567
|
}
|
|
2226
2568
|
export { Model };
|