vona-module-a-orm 5.1.5 → 5.1.7
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/cli/entity/metadata/generate.ts +13 -3
- package/cli/model/metadata/generate.ts +6 -3
- package/cli/model/metadata/magic.ts +6 -1
- package/dist/.metadata/index.d.ts +25 -25
- package/dist/.metadata/index.d.ts.map +1 -1
- package/dist/.metadata/locales.d.ts.map +1 -1
- package/dist/bean/aopMethod.transaction.d.ts.map +1 -1
- package/dist/bean/bean.database.d.ts.map +1 -1
- package/dist/bean/bean.databaseDialectBase.d.ts.map +1 -1
- package/dist/bean/bean.model/bean.model_cache.d.ts.map +1 -1
- package/dist/bean/bean.model/bean.model_crud.d.ts.map +1 -1
- package/dist/bean/bean.model/bean.model_crud_inner.d.ts.map +1 -1
- package/dist/bean/bean.model/bean.model_crud_table.d.ts.map +1 -1
- package/dist/bean/bean.model/bean.model_knex.d.ts.map +1 -1
- package/dist/bean/bean.model/bean.model_meta.d.ts.map +1 -1
- package/dist/bean/bean.model/bean.model_utils.d.ts.map +1 -1
- package/dist/bean/bean.model/bean.model_view.d.ts.map +1 -1
- package/dist/bean/event.clientNameReal.d.ts.map +1 -1
- package/dist/bean/event.columnsClear.d.ts.map +1 -1
- package/dist/bean/queue.doubleDelete.d.ts.map +1 -1
- package/dist/bean/schedule.softDeletionPrune.d.ts.map +1 -1
- package/dist/common/buildWhere.d.ts.map +1 -1
- package/dist/common/utils.d.ts.map +1 -1
- package/dist/extend/schemaBuilder.d.ts.map +1 -1
- package/dist/extend/tableBuilder.d.ts.map +1 -1
- package/dist/index.js +33 -33
- package/dist/index.js.map +1 -1
- package/dist/lib/const.d.ts.map +1 -1
- package/dist/lib/databaseDialect.d.ts.map +1 -1
- package/dist/lib/dto/dtoAggregate.d.ts.map +1 -1
- package/dist/lib/dto/dtoCreate.d.ts.map +1 -1
- package/dist/lib/dto/dtoGet.d.ts.map +1 -1
- package/dist/lib/dto/dtoGroup.d.ts.map +1 -1
- package/dist/lib/dto/dtoListAndCount.d.ts.map +1 -1
- package/dist/lib/dto/dtoMutate.d.ts.map +1 -1
- package/dist/lib/dto/dtoQueryPage.d.ts.map +1 -1
- package/dist/lib/dto/dtoSelectAndCount.d.ts.map +1 -1
- package/dist/lib/dto/dtoUpdate.d.ts.map +1 -1
- package/dist/lib/entity.d.ts.map +1 -1
- package/dist/lib/modelCacheBase.d.ts.map +1 -1
- package/dist/lib/relations.d.ts.map +1 -1
- package/dist/lib/relationsDynamic.d.ts.map +1 -1
- package/dist/lib/relationsMutate.d.ts.map +1 -1
- package/dist/lib/relationsStatic.d.ts.map +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/service/columnsCache_.d.ts.map +1 -1
- package/dist/service/database.d.ts.map +1 -1
- package/dist/service/databaseClient_.d.ts.map +1 -1
- package/dist/service/relations_.d.ts.map +1 -1
- package/dist/service/transaction_.d.ts.map +1 -1
- package/dist/types/dto/dtoGet.d.ts.map +1 -1
- package/dist/types/dto/dtoGroup.d.ts.map +1 -1
- package/dist/types/dto/dtoMutate.d.ts.map +1 -1
- package/dist/types/dto/dtoQueryBase.d.ts.map +1 -1
- package/dist/types/dto/dtoSelectAndCount.d.ts.map +1 -1
- package/dist/types/entity.d.ts.map +1 -1
- package/dist/types/model.d.ts +5 -1
- package/dist/types/model.d.ts.map +1 -1
- package/dist/types/modelAggr.d.ts.map +1 -1
- package/dist/types/modelCount.d.ts.map +1 -1
- package/dist/types/modelGeneral.d.ts.map +1 -1
- package/dist/types/modelGroup.d.ts.map +1 -1
- package/dist/types/modelIncrement.d.ts.map +1 -1
- package/dist/types/modelWhere.d.ts.map +1 -1
- package/dist/types/onion/entity.d.ts +2 -2
- package/dist/types/onion/entity.d.ts.map +1 -1
- package/dist/types/onion/model.d.ts.map +1 -1
- package/dist/types/relations.d.ts.map +1 -1
- package/dist/types/relationsAggr.d.ts +1 -1
- package/dist/types/relationsAggr.d.ts.map +1 -1
- package/dist/types/relationsColumns.d.ts.map +1 -1
- package/dist/types/relationsDef.d.ts.map +1 -1
- package/dist/types/relationsDefDynamic.d.ts.map +1 -1
- package/dist/types/relationsDefMutate.d.ts.map +1 -1
- package/dist/types/relationsGroup.d.ts.map +1 -1
- package/dist/types/relationsMutate.d.ts.map +1 -1
- package/dist/types/relationsTables.d.ts.map +1 -1
- package/dist/types/transaction.d.ts.map +1 -1
- package/dist-cli/entity/metadata/generate.js +4 -1
- package/dist-cli/model/metadata/generate.js +4 -2
- package/package.json +1 -1
- package/src/.metadata/index.ts +39 -39
- package/src/.metadata/locales.ts +6 -1
- package/src/bean/aopMethod.transaction.ts +9 -2
- package/src/bean/bean.database.ts +33 -8
- package/src/bean/bean.databaseDialectBase.ts +42 -9
- package/src/bean/bean.model/bean.model_cache.ts +130 -46
- package/src/bean/bean.model/bean.model_crud.ts +28 -7
- package/src/bean/bean.model/bean.model_crud_inner.ts +17 -4
- package/src/bean/bean.model/bean.model_crud_table.ts +25 -5
- package/src/bean/bean.model/bean.model_knex.ts +18 -5
- package/src/bean/bean.model/bean.model_meta.ts +23 -5
- package/src/bean/bean.model/bean.model_utils.ts +55 -12
- package/src/bean/bean.model/bean.model_view.ts +20 -5
- package/src/bean/event.clientNameReal.ts +4 -1
- package/src/bean/event.columnsClear.ts +4 -1
- package/src/bean/queue.doubleDelete.ts +9 -2
- package/src/bean/schedule.softDeletionPrune.ts +3 -1
- package/src/common/buildWhere.ts +30 -5
- package/src/common/utils.ts +6 -2
- package/src/extend/schemaBuilder.ts +2 -1
- package/src/extend/tableBuilder.ts +32 -19
- package/src/lib/const.ts +3 -1
- package/src/lib/databaseDialect.ts +3 -1
- package/src/lib/dto/dtoAggregate.ts +18 -6
- package/src/lib/dto/dtoCreate.ts +24 -4
- package/src/lib/dto/dtoGet.ts +82 -17
- package/src/lib/dto/dtoGroup.ts +24 -8
- package/src/lib/dto/dtoListAndCount.ts +3 -1
- package/src/lib/dto/dtoMutate.ts +26 -7
- package/src/lib/dto/dtoQueryPage.ts +4 -1
- package/src/lib/dto/dtoSelectAndCount.ts +3 -1
- package/src/lib/dto/dtoUpdate.ts +24 -4
- package/src/lib/entity.ts +10 -4
- package/src/lib/modelCacheBase.ts +9 -3
- package/src/lib/relations.ts +22 -4
- package/src/lib/relationsDynamic.ts +29 -7
- package/src/lib/relationsMutate.ts +28 -5
- package/src/lib/relationsStatic.ts +4 -1
- package/src/lib/utils.ts +11 -2
- package/src/main.ts +10 -2
- package/src/service/columnsCache_.ts +8 -6
- package/src/service/database.ts +34 -10
- package/src/service/databaseClient_.ts +4 -1
- package/src/service/relations_.ts +98 -23
- package/src/service/transaction_.ts +14 -4
- package/src/types/dto/dtoGet.ts +14 -6
- package/src/types/dto/dtoGroup.ts +2 -1
- package/src/types/dto/dtoMutate.ts +102 -20
- package/src/types/dto/dtoQueryBase.ts +5 -1
- package/src/types/dto/dtoSelectAndCount.ts +4 -1
- package/src/types/entity.ts +3 -1
- package/src/types/entityBase.ts +1 -1
- package/src/types/entityBaseInner.ts +4 -4
- package/src/types/entityBaseSimple.ts +1 -1
- package/src/types/model.ts +73 -16
- package/src/types/modelAggr.ts +18 -6
- package/src/types/modelCount.ts +4 -1
- package/src/types/modelGeneral.ts +26 -5
- package/src/types/modelGroup.ts +8 -2
- package/src/types/modelIncrement.ts +4 -1
- package/src/types/modelWhere.ts +12 -3
- package/src/types/onion/entity.ts +2 -2
- package/src/types/onion/model.ts +20 -4
- package/src/types/relations.ts +151 -47
- package/src/types/relationsAggr.ts +35 -11
- package/src/types/relationsColumns.ts +80 -57
- package/src/types/relationsDef.ts +82 -29
- package/src/types/relationsDefDynamic.ts +59 -13
- package/src/types/relationsDefMutate.ts +3 -1
- package/src/types/relationsGroup.ts +32 -10
- package/src/types/relationsMutate.ts +60 -19
- package/src/types/relationsTables.ts +16 -14
- package/src/types/transaction.ts +14 -2
|
@@ -45,7 +45,10 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
45
45
|
public cacheEntity: ServiceCacheEntity;
|
|
46
46
|
protected relations: ServiceRelations;
|
|
47
47
|
|
|
48
|
-
protected __init__(
|
|
48
|
+
protected __init__(
|
|
49
|
+
clientName?: keyof IDatabaseClientRecord | ServiceDb,
|
|
50
|
+
table?: keyof ITableRecord,
|
|
51
|
+
) {
|
|
49
52
|
super.__init__(clientName, table);
|
|
50
53
|
this.cacheQuery = this.bean._newBean(ServiceCacheQuery, this);
|
|
51
54
|
this.cacheEntity = this.bean._newBean(ServiceCacheEntity, this);
|
|
@@ -57,18 +60,29 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
57
60
|
await disposeInstance(this.cacheEntity);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
async insert<T extends IModelInsertOptions<TRecord>>(
|
|
63
|
+
async insert<T extends IModelInsertOptions<TRecord>>(
|
|
64
|
+
data?: Partial<TRecord>,
|
|
65
|
+
options?: T,
|
|
66
|
+
): Promise<TRecord> {
|
|
61
67
|
if (!data) data = {};
|
|
62
68
|
const items = await this.insertBulk([data], options);
|
|
63
69
|
return items[0];
|
|
64
70
|
}
|
|
65
71
|
|
|
66
|
-
async insertBulk<T extends IModelInsertOptions<TRecord>>(
|
|
72
|
+
async insertBulk<T extends IModelInsertOptions<TRecord>>(
|
|
73
|
+
items: Partial<TRecord>[],
|
|
74
|
+
options?: T,
|
|
75
|
+
): Promise<TRecord[]> {
|
|
67
76
|
const itemsResult = await this.__insertBulk_raw(undefined, items, options);
|
|
68
77
|
const itemsNew = items.map((item, index) => {
|
|
69
78
|
return Object.assign({}, item, { id: cast(itemsResult[index]).id });
|
|
70
79
|
});
|
|
71
|
-
return await this.relations.handleRelationsMutate(
|
|
80
|
+
return await this.relations.handleRelationsMutate(
|
|
81
|
+
itemsResult,
|
|
82
|
+
itemsNew as any,
|
|
83
|
+
options as any,
|
|
84
|
+
options,
|
|
85
|
+
);
|
|
72
86
|
}
|
|
73
87
|
|
|
74
88
|
async __insertBulk_raw(
|
|
@@ -88,13 +102,19 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
88
102
|
return res;
|
|
89
103
|
}
|
|
90
104
|
|
|
91
|
-
async mutate<T extends IModelMutateOptions<TRecord>>(
|
|
105
|
+
async mutate<T extends IModelMutateOptions<TRecord>>(
|
|
106
|
+
data?: Partial<TRecord>,
|
|
107
|
+
options?: T,
|
|
108
|
+
): Promise<Partial<TRecord>> {
|
|
92
109
|
if (!data) data = {};
|
|
93
110
|
const items = await this.mutateBulk([data], options);
|
|
94
111
|
return items[0];
|
|
95
112
|
}
|
|
96
113
|
|
|
97
|
-
async mutateBulk<T extends IModelMutateOptions<TRecord>>(
|
|
114
|
+
async mutateBulk<T extends IModelMutateOptions<TRecord>>(
|
|
115
|
+
items: Partial<TRecord>[],
|
|
116
|
+
options?: T,
|
|
117
|
+
): Promise<Partial<TRecord>[]> {
|
|
98
118
|
return await this.__mutateBulk_raw(undefined, items, options);
|
|
99
119
|
}
|
|
100
120
|
|
|
@@ -140,7 +160,12 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
140
160
|
.concat(itemsUpdate as any);
|
|
141
161
|
let itemsMutateResult = itemsInsertNew.concat(itemsUpdate as any);
|
|
142
162
|
const indexesMutate = indexesInsert.concat(indexesUpdate);
|
|
143
|
-
itemsMutateResult = await this.relations.handleRelationsMutate(
|
|
163
|
+
itemsMutateResult = await this.relations.handleRelationsMutate(
|
|
164
|
+
itemsMutateResult,
|
|
165
|
+
itemsMutate as any,
|
|
166
|
+
options as any,
|
|
167
|
+
options,
|
|
168
|
+
);
|
|
144
169
|
let result: TRecord[] = [];
|
|
145
170
|
for (let index = 0; index < indexesMutate.length; index++) {
|
|
146
171
|
result[indexesMutate[index]] = itemsMutateResult[index] as any;
|
|
@@ -153,7 +178,10 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
153
178
|
return result;
|
|
154
179
|
}
|
|
155
180
|
|
|
156
|
-
async mget<T extends IModelGetOptions<TRecord>>(
|
|
181
|
+
async mget<T extends IModelGetOptions<TRecord>>(
|
|
182
|
+
ids: TableIdentity[],
|
|
183
|
+
options?: T,
|
|
184
|
+
): Promise<Partial<TRecord>[]> {
|
|
157
185
|
if (ids.length === 0) return [];
|
|
158
186
|
const relations = this.relations.handleRelationsCollection(options as any);
|
|
159
187
|
const [options2, refKeys] = this.relations.prepareColumnsByRelations(relations, options);
|
|
@@ -170,7 +198,11 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
170
198
|
return items;
|
|
171
199
|
}
|
|
172
200
|
|
|
173
|
-
private async __mget_raw(
|
|
201
|
+
private async __mget_raw(
|
|
202
|
+
table: keyof ITableRecord | undefined,
|
|
203
|
+
ids: TableIdentity[],
|
|
204
|
+
options?: IModelGetOptions<TRecord>,
|
|
205
|
+
): Promise<TRecord[]> {
|
|
174
206
|
// table
|
|
175
207
|
table = table || this.getTable(undefined);
|
|
176
208
|
if (!table) return this.scopeOrm.error.ShouldSpecifyTable.throw();
|
|
@@ -195,7 +227,10 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
195
227
|
return this.__filterMGetColumns(items, options?.columns);
|
|
196
228
|
}
|
|
197
229
|
|
|
198
|
-
async count<
|
|
230
|
+
async count<
|
|
231
|
+
T extends IModelSelectCountParams<TRecord>,
|
|
232
|
+
ModelJoins extends TypeModelsClassLikeGeneral | undefined,
|
|
233
|
+
>(
|
|
199
234
|
params?: T,
|
|
200
235
|
options?: IModelMethodOptions,
|
|
201
236
|
_modelJoins?: ModelJoins,
|
|
@@ -206,19 +241,17 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
206
241
|
return this.extractFirstValue(item);
|
|
207
242
|
}
|
|
208
243
|
|
|
209
|
-
async increment<
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
): Promise<number> {
|
|
244
|
+
async increment<
|
|
245
|
+
T extends IModelIncrementParams<TRecord>,
|
|
246
|
+
ModelJoins extends TypeModelsClassLikeGeneral | undefined,
|
|
247
|
+
>(params: T, options?: IModelMethodOptions, _modelJoins?: ModelJoins): Promise<number> {
|
|
214
248
|
return await this.__increment_raw(undefined, params, options);
|
|
215
249
|
}
|
|
216
250
|
|
|
217
|
-
async decrement<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
): Promise<number> {
|
|
251
|
+
async decrement<
|
|
252
|
+
T extends IModelIncrementParams<TRecord>,
|
|
253
|
+
ModelJoins extends TypeModelsClassLikeGeneral | undefined,
|
|
254
|
+
>(params: T, options?: IModelMethodOptions, _modelJoins?: ModelJoins): Promise<number> {
|
|
222
255
|
const columns = {} as TypeModelIncrementParamsColumns<TRecord>;
|
|
223
256
|
for (const key in params.columns) {
|
|
224
257
|
columns[key] = -params.columns[key]!;
|
|
@@ -259,7 +292,10 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
259
292
|
return res;
|
|
260
293
|
}
|
|
261
294
|
|
|
262
|
-
async aggregate<
|
|
295
|
+
async aggregate<
|
|
296
|
+
T extends IModelSelectAggrParams<TRecord>,
|
|
297
|
+
ModelJoins extends TypeModelsClassLikeGeneral | undefined,
|
|
298
|
+
>(
|
|
263
299
|
params?: T,
|
|
264
300
|
options?: IModelMethodOptions,
|
|
265
301
|
_modelJoins?: ModelJoins,
|
|
@@ -280,7 +316,10 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
280
316
|
return items;
|
|
281
317
|
}
|
|
282
318
|
|
|
283
|
-
async group<
|
|
319
|
+
async group<
|
|
320
|
+
T extends IModelSelectGroupParams<TRecord>,
|
|
321
|
+
ModelJoins extends TypeModelsClassLikeGeneral | undefined,
|
|
322
|
+
>(
|
|
284
323
|
params?: T,
|
|
285
324
|
options?: IModelMethodOptions,
|
|
286
325
|
_modelJoins?: ModelJoins,
|
|
@@ -300,16 +339,20 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
300
339
|
return items;
|
|
301
340
|
}
|
|
302
341
|
|
|
303
|
-
async selectAndCount<
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
): Promise<any> {
|
|
342
|
+
async selectAndCount<
|
|
343
|
+
T extends IModelSelectParams<TRecord>,
|
|
344
|
+
ModelJoins extends TypeModelsClassLikeGeneral | undefined,
|
|
345
|
+
>(params?: T, options?: IModelMethodOptions, modelJoins?: ModelJoins): Promise<any> {
|
|
308
346
|
// pageNo/pageSize
|
|
309
347
|
const pageSize = params?.limit ?? this.scopeOrm.config.rest.query.pageSize.default;
|
|
310
348
|
const pageNo = Math.floor((params?.offset ?? 0) / pageSize) + 1;
|
|
311
349
|
// count
|
|
312
|
-
const paramsCount = Object.assign({}, params, {
|
|
350
|
+
const paramsCount = Object.assign({}, params, {
|
|
351
|
+
columns: undefined,
|
|
352
|
+
orders: undefined,
|
|
353
|
+
limit: undefined,
|
|
354
|
+
offset: undefined,
|
|
355
|
+
});
|
|
313
356
|
let count = await this.count(paramsCount, options, modelJoins);
|
|
314
357
|
if (!count) count = '0';
|
|
315
358
|
// list
|
|
@@ -325,11 +368,10 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
325
368
|
return { list, total: count, pageCount, pageSize, pageNo };
|
|
326
369
|
}
|
|
327
370
|
|
|
328
|
-
async select<
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
): Promise<any[]> {
|
|
371
|
+
async select<
|
|
372
|
+
T extends IModelSelectParams<TRecord>,
|
|
373
|
+
ModelJoins extends TypeModelsClassLikeGeneral | undefined,
|
|
374
|
+
>(params?: T, options?: IModelMethodOptions, _modelJoins?: ModelJoins): Promise<any[]> {
|
|
333
375
|
const relations = this.relations.handleRelationsCollection(params as any);
|
|
334
376
|
const [params2, refKeys] = this.relations.prepareColumnsByRelations(relations, params);
|
|
335
377
|
let items = await this.__select_raw(undefined, params2, options);
|
|
@@ -375,11 +417,17 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
375
417
|
}
|
|
376
418
|
// 2: mget
|
|
377
419
|
const ids = items.map(item => cast(item).id);
|
|
378
|
-
const options3 = params?.columns
|
|
420
|
+
const options3 = params?.columns
|
|
421
|
+
? Object.assign({}, options, { columns: params?.columns })
|
|
422
|
+
: options;
|
|
379
423
|
return await this.__mget_raw(table, ids, options3);
|
|
380
424
|
}
|
|
381
425
|
|
|
382
|
-
private async __select_cache(
|
|
426
|
+
private async __select_cache(
|
|
427
|
+
table: keyof ITableRecord,
|
|
428
|
+
params?: IModelSelectParams<TRecord>,
|
|
429
|
+
options?: IModelMethodOptions,
|
|
430
|
+
): Promise<TRecord[]> {
|
|
383
431
|
// check if cache
|
|
384
432
|
if (this._checkDisableCacheQueryByOptions(options)) {
|
|
385
433
|
return await super._select(table, params, options);
|
|
@@ -400,7 +448,10 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
400
448
|
return items;
|
|
401
449
|
}
|
|
402
450
|
|
|
403
|
-
async get<T extends IModelGetOptions<TRecord>>(
|
|
451
|
+
async get<T extends IModelGetOptions<TRecord>>(
|
|
452
|
+
where: TypeModelWhere<TRecord>,
|
|
453
|
+
options?: T,
|
|
454
|
+
): Promise<Partial<TRecord> | undefined> {
|
|
404
455
|
const relations = this.relations.handleRelationsCollection(options);
|
|
405
456
|
const [options2, refKeys] = this.relations.prepareColumnsByRelations(relations, options);
|
|
406
457
|
let item: TRecord | undefined = await this.__get_raw(undefined, where, options2);
|
|
@@ -444,19 +495,33 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
444
495
|
return items[0];
|
|
445
496
|
}
|
|
446
497
|
// key
|
|
447
|
-
return this.__filterGetColumns(
|
|
498
|
+
return this.__filterGetColumns(
|
|
499
|
+
await this.__get_key(id, table, where, options),
|
|
500
|
+
options?.columns,
|
|
501
|
+
);
|
|
448
502
|
}
|
|
449
503
|
|
|
450
|
-
async update<T extends IModelUpdateOptions<TRecord>>(
|
|
504
|
+
async update<T extends IModelUpdateOptions<TRecord>>(
|
|
505
|
+
data: Partial<TRecord>,
|
|
506
|
+
options?: T,
|
|
507
|
+
): Promise<Partial<TRecord>> {
|
|
451
508
|
const ids = await this.__update_raw(undefined, data, options);
|
|
452
509
|
if (!ids || ids.length !== 1) return data;
|
|
453
510
|
// only support =1
|
|
454
511
|
const dataNew = [Object.assign({}, data, { id: ids[0] })];
|
|
455
|
-
const items = await this.relations.handleRelationsMutate(
|
|
512
|
+
const items = await this.relations.handleRelationsMutate(
|
|
513
|
+
dataNew,
|
|
514
|
+
dataNew,
|
|
515
|
+
options as any,
|
|
516
|
+
options,
|
|
517
|
+
);
|
|
456
518
|
return items[0];
|
|
457
519
|
}
|
|
458
520
|
|
|
459
|
-
async updateBulk<T extends IModelUpdateOptions<TRecord>>(
|
|
521
|
+
async updateBulk<T extends IModelUpdateOptions<TRecord>>(
|
|
522
|
+
items: Partial<TRecord>[],
|
|
523
|
+
options?: T,
|
|
524
|
+
): Promise<Partial<TRecord>[]> {
|
|
460
525
|
await this.__updateBulk_raw(undefined, items, options);
|
|
461
526
|
return await this.relations.handleRelationsMutate(items, items, options as any, options);
|
|
462
527
|
}
|
|
@@ -525,14 +590,20 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
525
590
|
return Array.isArray(id) ? id : [id];
|
|
526
591
|
}
|
|
527
592
|
|
|
528
|
-
async delete<T extends IModelDeleteOptions<TRecord>>(
|
|
593
|
+
async delete<T extends IModelDeleteOptions<TRecord>>(
|
|
594
|
+
where?: TypeModelWhere<TRecord>,
|
|
595
|
+
options?: T,
|
|
596
|
+
): Promise<void> {
|
|
529
597
|
const ids = await this.__delete_raw(undefined, where, options);
|
|
530
598
|
if (!isNil(ids)) {
|
|
531
599
|
await this.relations.handleRelationsDelete(ids as [], options as any, options);
|
|
532
600
|
}
|
|
533
601
|
}
|
|
534
602
|
|
|
535
|
-
async deleteBulk<T extends IModelDeleteOptions<TRecord>>(
|
|
603
|
+
async deleteBulk<T extends IModelDeleteOptions<TRecord>>(
|
|
604
|
+
ids: TableIdentity[],
|
|
605
|
+
options?: T,
|
|
606
|
+
): Promise<void> {
|
|
536
607
|
return await this.__deleteBulk_raw_with_relations(undefined, ids, options);
|
|
537
608
|
}
|
|
538
609
|
|
|
@@ -639,7 +710,10 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
639
710
|
});
|
|
640
711
|
}
|
|
641
712
|
|
|
642
|
-
public async cacheEntityDelInner(
|
|
713
|
+
public async cacheEntityDelInner(
|
|
714
|
+
id: TableIdentity | TableIdentity[],
|
|
715
|
+
table?: keyof ITableRecord,
|
|
716
|
+
) {
|
|
643
717
|
await this.cacheEntity.del(id, table);
|
|
644
718
|
await this.cacheQueryClearInner(table);
|
|
645
719
|
}
|
|
@@ -729,7 +803,11 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
729
803
|
return !(options?.cache?.enable ?? this.cacheEntity.enabled);
|
|
730
804
|
}
|
|
731
805
|
|
|
732
|
-
private __checkIfOnlyKey(
|
|
806
|
+
private __checkIfOnlyKey(
|
|
807
|
+
keys: (string | TypeModelColumn<TRecord>)[],
|
|
808
|
+
table: keyof ITableRecord,
|
|
809
|
+
noCheckLength?: boolean,
|
|
810
|
+
): string | false {
|
|
733
811
|
const columnId = `${table}.id`;
|
|
734
812
|
if (!noCheckLength) {
|
|
735
813
|
const keysAux = this.cacheEntity.keysAux;
|
|
@@ -748,11 +826,17 @@ export class BeanModelCache<TRecord extends {} = {}> extends BeanModelCrud<TReco
|
|
|
748
826
|
}
|
|
749
827
|
}
|
|
750
828
|
|
|
751
|
-
private __checkCacheKeyValid(
|
|
829
|
+
private __checkCacheKeyValid(
|
|
830
|
+
where: {} | undefined,
|
|
831
|
+
table: keyof ITableRecord,
|
|
832
|
+
noCheckLength?: boolean,
|
|
833
|
+
) {
|
|
752
834
|
if (!where) return undefined;
|
|
753
835
|
const columnId = this.__checkIfOnlyKey(Object.keys(where), table, noCheckLength);
|
|
754
836
|
if (!columnId) return undefined;
|
|
755
|
-
return ['number', 'string', 'bigint', 'array'].includes(typeof where[columnId])
|
|
837
|
+
return ['number', 'string', 'bigint', 'array'].includes(typeof where[columnId])
|
|
838
|
+
? where[columnId]
|
|
839
|
+
: undefined;
|
|
756
840
|
}
|
|
757
841
|
|
|
758
842
|
protected __get__(prop: string) {
|
|
@@ -12,19 +12,31 @@ import type {
|
|
|
12
12
|
import { BeanModelCrudInner } from './bean.model_crud_inner.ts';
|
|
13
13
|
|
|
14
14
|
export class BeanModelCrud<TRecord extends {} = {}> extends BeanModelCrudInner<TRecord> {
|
|
15
|
-
async mget(
|
|
15
|
+
async mget(
|
|
16
|
+
ids: TableIdentity[],
|
|
17
|
+
options?: IModelGetOptionsGeneral<TRecord>,
|
|
18
|
+
): Promise<Partial<TRecord>[]> {
|
|
16
19
|
return await this._mget(undefined, ids, options);
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
async select(
|
|
22
|
+
async select(
|
|
23
|
+
params?: IModelSelectParams<TRecord>,
|
|
24
|
+
options?: IModelMethodOptionsGeneral,
|
|
25
|
+
): Promise<Partial<TRecord>[]> {
|
|
20
26
|
return await this._select(undefined, params, options);
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
async get(
|
|
29
|
+
async get(
|
|
30
|
+
where: TypeModelWhere<TRecord>,
|
|
31
|
+
options?: IModelGetOptionsGeneral<TRecord>,
|
|
32
|
+
): Promise<Partial<TRecord> | undefined> {
|
|
24
33
|
return await this._get(undefined, where, options);
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
async count(
|
|
36
|
+
async count(
|
|
37
|
+
params?: IModelCountParams<TRecord>,
|
|
38
|
+
options?: IModelMethodOptionsGeneral,
|
|
39
|
+
): Promise<string | undefined> {
|
|
28
40
|
return await this._count(undefined, params, options);
|
|
29
41
|
}
|
|
30
42
|
|
|
@@ -32,15 +44,24 @@ export class BeanModelCrud<TRecord extends {} = {}> extends BeanModelCrudInner<T
|
|
|
32
44
|
return (await this._insertBulk(undefined, data, options)) as Promise<TRecord>;
|
|
33
45
|
}
|
|
34
46
|
|
|
35
|
-
async insertBulk(
|
|
47
|
+
async insertBulk(
|
|
48
|
+
data: Partial<TRecord>[],
|
|
49
|
+
options?: IModelMethodOptionsGeneral,
|
|
50
|
+
): Promise<TRecord[]> {
|
|
36
51
|
return (await this._insertBulk(undefined, data, options)) as Promise<TRecord[]>;
|
|
37
52
|
}
|
|
38
53
|
|
|
39
|
-
async update(
|
|
54
|
+
async update(
|
|
55
|
+
data: Partial<TRecord>,
|
|
56
|
+
options?: IModelUpdateOptionsGeneral<TRecord>,
|
|
57
|
+
): Promise<Partial<TRecord>> {
|
|
40
58
|
return await this._update(undefined, data, options);
|
|
41
59
|
}
|
|
42
60
|
|
|
43
|
-
async delete(
|
|
61
|
+
async delete(
|
|
62
|
+
where?: TypeModelWhere<TRecord>,
|
|
63
|
+
options?: IModelMethodOptionsGeneral,
|
|
64
|
+
): Promise<void> {
|
|
44
65
|
return await this._delete(undefined, where, options);
|
|
45
66
|
}
|
|
46
67
|
}
|
|
@@ -19,7 +19,11 @@ import type {
|
|
|
19
19
|
import { BeanModelView } from './bean.model_view.ts';
|
|
20
20
|
|
|
21
21
|
export class BeanModelCrudInner<TRecord extends {}> extends BeanModelView<TRecord> {
|
|
22
|
-
protected async _mget(
|
|
22
|
+
protected async _mget(
|
|
23
|
+
table?: keyof ITableRecord,
|
|
24
|
+
ids?: TableIdentity[],
|
|
25
|
+
options?: IModelGetOptionsGeneral<TRecord>,
|
|
26
|
+
): Promise<TRecord[]> {
|
|
23
27
|
const items = await this._mget_original(table, ids, options);
|
|
24
28
|
return items.filter(item => !isNil(item));
|
|
25
29
|
}
|
|
@@ -45,7 +49,9 @@ export class BeanModelCrudInner<TRecord extends {}> extends BeanModelView<TRecor
|
|
|
45
49
|
params.columns = options?.columns as any;
|
|
46
50
|
}
|
|
47
51
|
// select
|
|
48
|
-
const options2 = options?.columns
|
|
52
|
+
const options2 = options?.columns
|
|
53
|
+
? Object.assign({}, options, { columns: undefined })
|
|
54
|
+
: options;
|
|
49
55
|
const items = await this._select(table, params, options2);
|
|
50
56
|
// sort
|
|
51
57
|
const result: (TRecord | undefined)[] = [];
|
|
@@ -201,7 +207,10 @@ export class BeanModelCrudInner<TRecord extends {}> extends BeanModelView<TRecor
|
|
|
201
207
|
const dataTemp2 = this._prepareInsertDataByOptions(table, dataTemp, options);
|
|
202
208
|
// then
|
|
203
209
|
const [dataNew, dataNewOriginal] = await this.prepareData(table, dataTemp2);
|
|
204
|
-
if (
|
|
210
|
+
if (
|
|
211
|
+
isNil(cast(dataNewOriginal).id) &&
|
|
212
|
+
Object.prototype.hasOwnProperty.call(dataNewOriginal, 'id')
|
|
213
|
+
) {
|
|
205
214
|
delete cast(dataNewOriginal).id;
|
|
206
215
|
}
|
|
207
216
|
datas.push(dataNew);
|
|
@@ -275,7 +284,11 @@ export class BeanModelCrudInner<TRecord extends {}> extends BeanModelView<TRecor
|
|
|
275
284
|
return data;
|
|
276
285
|
}
|
|
277
286
|
|
|
278
|
-
protected async _delete(
|
|
287
|
+
protected async _delete(
|
|
288
|
+
table?: keyof ITableRecord,
|
|
289
|
+
where?: TypeModelWhere<TRecord>,
|
|
290
|
+
options?: IModelMethodOptionsGeneral,
|
|
291
|
+
): Promise<void> {
|
|
279
292
|
// table
|
|
280
293
|
table = table || this.getTable(where);
|
|
281
294
|
if (!table) return this.scopeOrm.error.ShouldSpecifyTable.throw();
|
|
@@ -37,23 +37,43 @@ export class BeanModelCrudTable<TRecord extends {}> extends BeanModelCrudInner<T
|
|
|
37
37
|
return await this._get(table, where, options);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
async count(
|
|
40
|
+
async count(
|
|
41
|
+
table: keyof ITableRecord,
|
|
42
|
+
params?: IModelCountParams<TRecord>,
|
|
43
|
+
options?: IModelMethodOptionsGeneral,
|
|
44
|
+
): Promise<string | undefined> {
|
|
41
45
|
return await this._count(table, params, options);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
async insert(
|
|
48
|
+
async insert(
|
|
49
|
+
table: keyof ITableRecord,
|
|
50
|
+
data?: Partial<TRecord>,
|
|
51
|
+
options?: IModelMethodOptionsGeneral,
|
|
52
|
+
): Promise<TRecord> {
|
|
45
53
|
return (await this._insertBulk(table, data, options)) as Promise<TRecord>;
|
|
46
54
|
}
|
|
47
55
|
|
|
48
|
-
async insertBulk(
|
|
56
|
+
async insertBulk(
|
|
57
|
+
table: keyof ITableRecord,
|
|
58
|
+
data: Partial<TRecord>[],
|
|
59
|
+
options?: IModelMethodOptionsGeneral,
|
|
60
|
+
): Promise<TRecord[]> {
|
|
49
61
|
return (await this._insertBulk(table, data, options)) as Promise<TRecord[]>;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
|
-
async update(
|
|
64
|
+
async update(
|
|
65
|
+
table: keyof ITableRecord,
|
|
66
|
+
data: Partial<TRecord>,
|
|
67
|
+
options?: IModelUpdateOptionsGeneral<TRecord>,
|
|
68
|
+
): Promise<Partial<TRecord>> {
|
|
53
69
|
return await this._update(table, data, options);
|
|
54
70
|
}
|
|
55
71
|
|
|
56
|
-
async delete(
|
|
72
|
+
async delete(
|
|
73
|
+
table: keyof ITableRecord,
|
|
74
|
+
where?: TypeModelWhere<TRecord>,
|
|
75
|
+
options?: IModelMethodOptionsGeneral,
|
|
76
|
+
): Promise<void> {
|
|
57
77
|
return await this._delete(table, where, options);
|
|
58
78
|
}
|
|
59
79
|
}
|
|
@@ -9,7 +9,9 @@ export class BeanModelKnex<TRecord extends {}> extends BeanModelUtils<TRecord> {
|
|
|
9
9
|
return this.connection.schema;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
builder<TRecord2 extends {} = TRecord, TResult2 = TRecord2>(
|
|
12
|
+
builder<TRecord2 extends {} = TRecord, TResult2 = TRecord2>(
|
|
13
|
+
table?: Knex.TableDescriptor,
|
|
14
|
+
): Knex.QueryBuilder<TRecord2, TResult2[]> {
|
|
13
15
|
// table
|
|
14
16
|
table = table || this.getTable(undefined);
|
|
15
17
|
if (table) {
|
|
@@ -18,12 +20,17 @@ export class BeanModelKnex<TRecord extends {}> extends BeanModelUtils<TRecord> {
|
|
|
18
20
|
return this.connection.queryBuilder<TRecord2, TResult2[]>();
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
builderSelect<TRecord2 extends {} = TRecord, TResult2 = TRecord2>(
|
|
23
|
+
builderSelect<TRecord2 extends {} = TRecord, TResult2 = TRecord2>(
|
|
24
|
+
options?: IModelMethodOptionsGeneral,
|
|
25
|
+
): Knex.QueryBuilder<TRecord2, TResult2[]>;
|
|
22
26
|
builderSelect<TRecord2 extends {} = TRecord, TResult2 = TRecord2>(
|
|
23
27
|
table: keyof ITableRecord,
|
|
24
28
|
options?: IModelMethodOptionsGeneral,
|
|
25
29
|
): Knex.QueryBuilder<TRecord2, TResult2[]>;
|
|
26
|
-
builderSelect<TRecord2 extends {} = TRecord, TResult2 = TRecord2>(
|
|
30
|
+
builderSelect<TRecord2 extends {} = TRecord, TResult2 = TRecord2>(
|
|
31
|
+
table?,
|
|
32
|
+
options?,
|
|
33
|
+
): Knex.QueryBuilder<TRecord2, TResult2[]> {
|
|
27
34
|
if (typeof table !== 'string') {
|
|
28
35
|
options = table;
|
|
29
36
|
table = undefined;
|
|
@@ -41,7 +48,10 @@ export class BeanModelKnex<TRecord extends {}> extends BeanModelUtils<TRecord> {
|
|
|
41
48
|
|
|
42
49
|
async query(value: Knex.Value): Promise<TRecord[]>;
|
|
43
50
|
async query(sql: string, binding: Knex.RawBinding): Promise<TRecord[]>;
|
|
44
|
-
async query(
|
|
51
|
+
async query(
|
|
52
|
+
sql: string,
|
|
53
|
+
bindings: readonly Knex.RawBinding[] | Knex.ValueDict,
|
|
54
|
+
): Promise<TRecord[]>;
|
|
45
55
|
async query(sql, bindings?): Promise<TRecord[]> {
|
|
46
56
|
const raw = this.connection.raw(sql, bindings);
|
|
47
57
|
const result = await raw;
|
|
@@ -51,7 +61,10 @@ export class BeanModelKnex<TRecord extends {}> extends BeanModelUtils<TRecord> {
|
|
|
51
61
|
|
|
52
62
|
async queryOne(value: Knex.Value): Promise<TRecord | undefined>;
|
|
53
63
|
async queryOne(sql: string, binding: Knex.RawBinding): Promise<TRecord | undefined>;
|
|
54
|
-
async queryOne(
|
|
64
|
+
async queryOne(
|
|
65
|
+
sql: string,
|
|
66
|
+
bindings: readonly Knex.RawBinding[] | Knex.ValueDict,
|
|
67
|
+
): Promise<TRecord | undefined>;
|
|
55
68
|
async queryOne(sql, bindings?): Promise<TRecord | undefined> {
|
|
56
69
|
const res = await this.query(sql, bindings);
|
|
57
70
|
if (!res[0]) return undefined;
|
|
@@ -31,7 +31,10 @@ export class BeanModelMeta<TRecord extends {} = {}> extends BeanBase {
|
|
|
31
31
|
private [SymbolModelDb]?: ServiceDb;
|
|
32
32
|
private [SymbolModelTable]?: TypeModelOptionsTable;
|
|
33
33
|
|
|
34
|
-
protected __init__(
|
|
34
|
+
protected __init__(
|
|
35
|
+
clientName?: keyof IDatabaseClientRecord | ServiceDb,
|
|
36
|
+
table?: TypeModelOptionsTable,
|
|
37
|
+
) {
|
|
35
38
|
// clientName
|
|
36
39
|
if (!isNil(clientName)) {
|
|
37
40
|
if (typeof clientName === 'string') {
|
|
@@ -115,7 +118,12 @@ export class BeanModelMeta<TRecord extends {} = {}> extends BeanBase {
|
|
|
115
118
|
return this.options.disableUpdateTime ?? this.scopeOrm.config.model.disableUpdateTime;
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
protected _prepareDisableInstanceByOptions(
|
|
121
|
+
protected _prepareDisableInstanceByOptions(
|
|
122
|
+
table: keyof ITableRecord,
|
|
123
|
+
data: any,
|
|
124
|
+
options?: IModelMethodOptionsGeneral,
|
|
125
|
+
useRaw?: boolean,
|
|
126
|
+
) {
|
|
119
127
|
const columnNameInstance = useRaw ? 'iid' : `${getTableOrTableAlias(table)}.iid`;
|
|
120
128
|
if (this._checkDisableInstanceByOptions(options)) {
|
|
121
129
|
delete data.iid;
|
|
@@ -130,7 +138,12 @@ export class BeanModelMeta<TRecord extends {} = {}> extends BeanBase {
|
|
|
130
138
|
return data;
|
|
131
139
|
}
|
|
132
140
|
|
|
133
|
-
protected _prepareDisableDeletedByOptions(
|
|
141
|
+
protected _prepareDisableDeletedByOptions(
|
|
142
|
+
table: keyof ITableRecord,
|
|
143
|
+
data: any,
|
|
144
|
+
options?: IModelMethodOptionsGeneral,
|
|
145
|
+
useRaw?: boolean,
|
|
146
|
+
) {
|
|
134
147
|
const columnNameDeleted = useRaw ? 'deleted' : `${getTableOrTableAlias(table)}.deleted`;
|
|
135
148
|
const deleted = this._prepareDisableDeletedByOptionsSimple(options);
|
|
136
149
|
if (!isNil(deleted)) {
|
|
@@ -140,7 +153,9 @@ export class BeanModelMeta<TRecord extends {} = {}> extends BeanBase {
|
|
|
140
153
|
return data;
|
|
141
154
|
}
|
|
142
155
|
|
|
143
|
-
protected _prepareDisableDeletedByOptionsSimple(
|
|
156
|
+
protected _prepareDisableDeletedByOptionsSimple(
|
|
157
|
+
options?: IModelMethodOptionsGeneral,
|
|
158
|
+
): boolean | undefined {
|
|
144
159
|
if (!isNil(options?.deleted)) {
|
|
145
160
|
if (!this.disableDeleted) {
|
|
146
161
|
return options?.deleted;
|
|
@@ -177,7 +192,10 @@ export class BeanModelMeta<TRecord extends {} = {}> extends BeanBase {
|
|
|
177
192
|
return options?.disableUpdateTime ?? this.disableUpdateTime;
|
|
178
193
|
}
|
|
179
194
|
|
|
180
|
-
public newInstance(
|
|
195
|
+
public newInstance(
|
|
196
|
+
client?: keyof IDatabaseClientRecord | ServiceDb,
|
|
197
|
+
table?: TypeModelOptionsTable,
|
|
198
|
+
): this {
|
|
181
199
|
return this.app.bean._newBean(this.$beanFullName as any, client ?? this.db, table);
|
|
182
200
|
}
|
|
183
201
|
|