vona-module-a-orm 5.1.24 → 5.1.26
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/model/metadata/generate.ts +5 -11
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/bean.model/bean.model_cache.d.ts +3 -0
- package/dist/lib/bean.model/bean.model_cache.d.ts.map +1 -1
- package/dist/lib/bean.model/bean.model_crud_inner.d.ts.map +1 -1
- package/dist/lib/dto/dtoGet.d.ts.map +1 -1
- package/dist-cli/model/metadata/generate.js +5 -13
- package/package.json +2 -2
- package/src/lib/bean.model/bean.model_cache.ts +52 -0
- package/src/lib/bean.model/bean.model_crud_inner.ts +3 -0
- package/src/lib/bean.model/bean.model_utils.ts +1 -1
- package/src/lib/dto/dtoGet.ts +4 -10
|
@@ -32,6 +32,8 @@ export default async function (options: IMetadataCustomGenerateOptions): Promise
|
|
|
32
32
|
[SymbolKeyEntityMeta]: ${entityMetaName};
|
|
33
33
|
[SymbolKeyModelOptions]: ${opionsName};
|
|
34
34
|
get<T extends IModelGetOptions<${entityName},${className}>>(where: TypeModelWhere<${entityName}>, options?: T): Promise<TypeModelRelationResult<${entityName}, ${className}, T> | undefined>;
|
|
35
|
+
getForUpdate<T extends IModelGetOptions<${entityName},${className}>>(where: TypeModelWhere<${entityName}>, options?: T): Promise<TypeModelRelationResult<${entityName}, ${className}, T> | undefined>;
|
|
36
|
+
getByIdForUpdate<T extends IModelGetOptions<${entityName},${className}>>(id: TableIdentity, options?: T): Promise<TypeModelRelationResult<${entityName}, ${className}, T> | undefined>;
|
|
35
37
|
mget<T extends IModelGetOptions<${entityName},${className}>>(ids: TableIdentity[], options?: T): Promise<TypeModelRelationResult<${entityName}, ${className}, T>[]>;
|
|
36
38
|
selectAndCount<T extends IModelSelectParams<${entityName},${className},ModelJoins>, ModelJoins extends TypeModelsClassLikeGeneral | undefined = undefined>(params?: T, options?: IModelMethodOptions, modelJoins?: ModelJoins): Promise<TypeModelSelectAndCount<${entityName}, ${className}, T>>;
|
|
37
39
|
select<T extends IModelSelectParams<${entityName},${className},ModelJoins>, ModelJoins extends TypeModelsClassLikeGeneral | undefined = undefined>(params?: T, options?: IModelMethodOptions, modelJoins?: ModelJoins): Promise<TypeModelRelationResult<${entityName}, ${className}, T>[]>;
|
|
@@ -245,18 +247,10 @@ function __parseRelation_options(node: t.Node) {
|
|
|
245
247
|
aggrs = options?.aggrs;
|
|
246
248
|
}
|
|
247
249
|
// columns
|
|
248
|
-
if (!options?.columns) {
|
|
249
|
-
|
|
250
|
-
columns = 'undefined';
|
|
251
|
-
} else {
|
|
252
|
-
columns = 'undefined'; // '\'*\'';
|
|
253
|
-
}
|
|
250
|
+
if (!options?.columns || options.columns.includes('*')) {
|
|
251
|
+
columns = "'*'";
|
|
254
252
|
} else {
|
|
255
|
-
|
|
256
|
-
columns = "'*'";
|
|
257
|
-
} else {
|
|
258
|
-
columns = __joinColumnsType(options?.columns, false);
|
|
259
|
-
}
|
|
253
|
+
columns = __joinColumnsType(options.columns, false);
|
|
260
254
|
}
|
|
261
255
|
return { autoload, columns, groups, aggrs };
|
|
262
256
|
}
|
package/dist/index.js
CHANGED
|
@@ -1324,7 +1324,7 @@ class BeanModelUtils extends BeanModelMeta {
|
|
|
1324
1324
|
if (Object.prototype.hasOwnProperty.call(item, columnName)) {
|
|
1325
1325
|
let value = item[columnName];
|
|
1326
1326
|
dataOriginal[columnName] = value;
|
|
1327
|
-
if (column.type === 'json' && value
|
|
1327
|
+
if (column.type === 'json' && !isNil(value)) {
|
|
1328
1328
|
value = JSON.stringify(value);
|
|
1329
1329
|
}
|
|
1330
1330
|
data[columnName] = value;
|
|
@@ -1886,6 +1886,9 @@ class BeanModelCrudInner extends BeanModelView {
|
|
|
1886
1886
|
if (!table) return this.scopeOrm.error.ShouldSpecifyTable.throw();
|
|
1887
1887
|
// data
|
|
1888
1888
|
[data] = await this.prepareData(table, data);
|
|
1889
|
+
for (const key in data) {
|
|
1890
|
+
if (data[key] === undefined) data[key] = null;
|
|
1891
|
+
}
|
|
1889
1892
|
// where
|
|
1890
1893
|
const where = Object.assign({}, options?.where);
|
|
1891
1894
|
// id
|
|
@@ -3878,6 +3881,45 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3878
3881
|
}
|
|
3879
3882
|
return item;
|
|
3880
3883
|
}
|
|
3884
|
+
async getForUpdate(where, options) {
|
|
3885
|
+
if (!this.db.inTransaction) {
|
|
3886
|
+
throw new Error('model error: getForUpdate requires an active transaction');
|
|
3887
|
+
}
|
|
3888
|
+
const optionsLock = Object.assign({}, options, {
|
|
3889
|
+
disableCacheEntity: true,
|
|
3890
|
+
disableCacheQuery: true
|
|
3891
|
+
});
|
|
3892
|
+
const relations = this.relations.handleRelationsCollection(optionsLock);
|
|
3893
|
+
const [options2, refKeys] = this.relations.prepareColumnsByRelations(relations, optionsLock);
|
|
3894
|
+
let item = await this.__getForUpdate_raw(undefined, where, options2);
|
|
3895
|
+
if (!item) return item;
|
|
3896
|
+
item = await this.relations.handleRelationsOne(relations, item, optionsLock, optionsLock);
|
|
3897
|
+
if (refKeys) {
|
|
3898
|
+
for (const refKey of refKeys) {
|
|
3899
|
+
delete item[refKey];
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
return item;
|
|
3903
|
+
}
|
|
3904
|
+
async getByIdForUpdate(id, options) {
|
|
3905
|
+
return await this.getForUpdate({
|
|
3906
|
+
id
|
|
3907
|
+
}, options);
|
|
3908
|
+
}
|
|
3909
|
+
async __getForUpdate_raw(table, where, options) {
|
|
3910
|
+
table = table || this.getTable(where);
|
|
3911
|
+
if (!table) return this.scopeOrm.error.ShouldSpecifyTable.throw();
|
|
3912
|
+
const params = {
|
|
3913
|
+
where,
|
|
3914
|
+
limit: 1
|
|
3915
|
+
};
|
|
3916
|
+
if (options?.columns) {
|
|
3917
|
+
params.columns = options.columns;
|
|
3918
|
+
}
|
|
3919
|
+
const builder = this._select_buildParams(table, params, options).forUpdate();
|
|
3920
|
+
const items = await super._select(table, params, options, builder);
|
|
3921
|
+
return items[0];
|
|
3922
|
+
}
|
|
3881
3923
|
async __get_raw(table, where, options) {
|
|
3882
3924
|
// table
|
|
3883
3925
|
table = table || this.getTable(where);
|