count时目前对count参数的处理疏漏

This commit is contained in:
Xu Chang 2023-12-07 20:40:31 +08:00
parent 0ff0f385e7
commit d5cfcf7e4d
3 changed files with 29 additions and 3 deletions

View File

@ -902,7 +902,7 @@ class SqlTranslator {
const projText = 'count(1) cnt'; const projText = 'count(1) cnt';
const { stmt: filterText } = this.translateFilter(entity, filter, aliasDict, filterRefAlias, currentNumber, option); const { stmt: filterText } = this.translateFilter(entity, filter, aliasDict, filterRefAlias, currentNumber, option);
if (count && count > 0) { if (count && count > 0) {
const subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, Object.assign({}, selection, { indexFrom: 0, count })); const subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, 0, count, option, Object.assign({}, selection, { indexFrom: 0, count }));
return `select count(1) cnt from (${subQuerySql}) __tmp`; return `select count(1) cnt from (${subQuerySql}) __tmp`;
} }
return this.populateSelectStmt(projText, fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, selection); return this.populateSelectStmt(projText, fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, selection);

View File

@ -1119,7 +1119,7 @@ export abstract class SqlTranslator<ED extends EntityDict & BaseEntityDict> {
const { stmt: filterText } = this.translateFilter(entity, filter, aliasDict, filterRefAlias, currentNumber, option); const { stmt: filterText } = this.translateFilter(entity, filter, aliasDict, filterRefAlias, currentNumber, option);
if (count && count > 0) { if (count && count > 0) {
const subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, Object.assign({}, selection, { indexFrom: 0, count }) as ED[T]['Selection']); const subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, 0, count, option, Object.assign({}, selection, { indexFrom: 0, count }) as ED[T]['Selection']);
return `select count(1) cnt from (${subQuerySql}) __tmp`; return `select count(1) cnt from (${subQuerySql}) __tmp`;
} }
return this.populateSelectStmt(projText, fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, selection as ED[T]['Selection']); return this.populateSelectStmt(projText, fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, selection as ED[T]['Selection']);

View File

@ -1467,7 +1467,6 @@ describe('test mysqlstore', function () {
} }
}, context, {}); }, context, {});
process.env.NODE_ENV = 'development';
const row = await store.select('oper', { const row = await store.select('oper', {
data: { data: {
id: 1, id: 1,
@ -1488,8 +1487,35 @@ describe('test mysqlstore', function () {
} }
}, context, {}); }, context, {});
process.env.NODE_ENV = 'development';
const row2 = await store.select('oper', {
data: {
id: 1,
data: {
name: 1,
price: 1,
},
},
filter: {
id,
data: {
'.$or': [
{
name: 'xc',
},
{
name: {
'.$includes': 'xc',
}
}
],
},
}
}, context, {});
await context.commit(); await context.commit();
assert(row.length === 1); assert(row.length === 1);
assert(row2.length === 1);
}); });
it('[1.12]complicated json filter', async () => { it('[1.12]complicated json filter', async () => {