测试了select+aggregate,并修改了一个边界

This commit is contained in:
Xu Chang 2023-01-08 18:09:05 +08:00
parent eff1bbb20f
commit 20aa7f7c21
3 changed files with 110 additions and 10 deletions

View File

@ -785,7 +785,8 @@ var TreeStore = /** @class */ (function (_super) {
Object.assign(nodeDict2, nodeDict);
}
var exprResolveFns = [];
if (!filterFn || filterFn(n, nodeDict2, exprResolveFns)) {
// 如果没有filterFn要保证行不为null(本事务remove的case)
if (filterFn ? filterFn(n, nodeDict2, exprResolveFns) : this.constructRow(n, context, option)) {
// 如果有延时处理的expression在这里加以判断此时所有在filter中的node应该都已经加以遍历了
var exprResult = true;
if (exprResolveFns.length > 0) {
@ -991,8 +992,10 @@ var TreeStore = /** @class */ (function (_super) {
}
}
else if (rel instanceof Array) {
if (data[attr] && data[attr] instanceof Array) {
data[attr].map(function (ele) { return _this.formExprInResult(rel[0], projection[attr].data, ele, nodeDict, context); });
if (!attr.endsWith('$$aggr')) {
if (data[attr] && data[attr] instanceof Array) {
data[attr].map(function (ele) { return _this.formExprInResult(rel[0], projection[attr].data, ele, nodeDict, context); });
}
}
}
};

View File

@ -849,7 +849,9 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
Object.assign(nodeDict2, nodeDict);
}
const exprResolveFns: Array<ExprResolveFn> = [];
if (!filterFn || filterFn(n, nodeDict2, exprResolveFns)) {
// 如果没有filterFn要保证行不为null(本事务remove的case)
if (filterFn ? filterFn(n, nodeDict2, exprResolveFns) : this.constructRow(n, context, option)) {
// 如果有延时处理的expression在这里加以判断此时所有在filter中的node应该都已经加以遍历了
let exprResult = true;
if (exprResolveFns.length > 0) {
@ -1046,10 +1048,12 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
}
}
else if (rel instanceof Array) {
if (data[attr] && (data[attr] as any) instanceof Array) {
data[attr].map(
(ele: any) => this.formExprInResult(rel[0], projection[attr].data, ele, nodeDict, context)
)
if (!attr.endsWith('$$aggr')) {
if (data[attr] && (data[attr] as any) instanceof Array) {
data[attr].map(
(ele: any) => this.formExprInResult(rel[0], projection[attr].data, ele, nodeDict, context)
)
}
}
}
}

View File

@ -625,7 +625,7 @@ describe('基础测试', function () {
entity: 1,
},
}, context, {});
assert(me2.length === 2 && !!me2.find(ele => !!ele.$$deleteAt$$));
assert(me2.length === 1 && !me2.find(ele => !!ele.$$deleteAt$$));
context.rollback();
context.begin();
@ -636,7 +636,6 @@ describe('基础测试', function () {
entity: 1,
},
}, context, {});
assert(me3.length === 2);
assert(me3.length === 2 && !me3.find(ele => !!ele.$$deleteAt$$));
context.commit();
@ -726,5 +725,99 @@ describe('基础测试', function () {
// console.log(result);
context.commit();
});
it('[1.9]selection+aggregate', () => {
const store = new FrontendStore(storageSchema);
const context = new FrontendRuntimeContext(store);
context.begin();
store.operate('modi', {
id: generateNewId(),
action: 'create',
data: [{
id: generateNewId(),
targetEntity: 'ddd',
entity: 'user',
entityId: 'user-id-1',
action: 'create',
data: {},
modiEntity$modi: {
action: 'create',
data: [{
id: generateNewId(),
entity: 'user',
entityId: 'user-id-1',
}, {
id: generateNewId(),
entity: 'user',
entityId: 'user-id-1',
}, {
id: generateNewId(),
entity: 'user',
entityId: 'user-id-1',
}, {
id: generateNewId(),
entity: 'user',
entityId: 'user-id-1',
}]
}
}, {
id: generateNewId(),
targetEntity: 'ddd2',
entity: 'user',
entityId: 'user-id-2',
action: 'create',
data: {},
modiEntity$modi: {
action: 'create',
data: [
{
id: generateNewId(),
entity: 'user',
entityId: 'user-id-2',
},
{
id: generateNewId(),
entity: 'user',
entityId: 'user-id-2',
},
{
id: generateNewId(),
entity: 'user',
entityId: 'user-id-2',
}
],
},
}],
}, context, {});
context.commit();
context.begin();
const result = store.select('modi', {
data: {
id: 1,
modiEntity$modi$$aggr: {
$entity: 'modiEntity',
data: {
'$count-1': {
id: 1,
},
'$avg-1': {
$$createAt$$: 1,
},
$aggr: {
modi: {
targetEntity: 1,
}
}
},
filter: {
entity: 'user',
},
}
}
}, context, {});
console.log(result);
context.commit();
})
});