支持在json数据查询中增加对escape字符

This commit is contained in:
Xu Chang 2023-11-30 14:40:49 +08:00
parent 90a4b1c0a3
commit 0ff0f385e7
3 changed files with 53 additions and 2 deletions

View File

@ -411,7 +411,8 @@ class MySqlTranslator extends sqlTranslator_1.SqlTranslator {
}
else {
// 继续子对象解构
const part = translateInner(o[attr2], `${p}.${attr2}`);
const attr3 = attr2.startsWith('.') ? attr2.slice(1) : attr2;
const part = translateInner(o[attr2], `${p}.${attr3}`);
if (stmt2) {
stmt2 += ' and ';
}

View File

@ -465,7 +465,8 @@ export class MySqlTranslator<ED extends EntityDict & BaseEntityDict> extends Sql
}
else {
// 继续子对象解构
const part = translateInner(o[attr2], `${p}.${attr2}`);
const attr3 = attr2.startsWith('.') ? attr2.slice(1) : attr2;
const part = translateInner(o[attr2], `${p}.${attr3}`);
if (stmt2) {
stmt2 += ' and ';
}

View File

@ -1443,6 +1443,55 @@ describe('test mysqlstore', function () {
assert(row2.length === 0, JSON.stringify(row2));
});
it('[1.11.3]json escape', async () => {
const context = new TestContext(store);
await context.begin();
const id = await generateNewIdAsync();
await store.operate('oper', {
id: await generateNewIdAsync(),
action: 'create',
data: {
id,
action: 'test',
data: {
$or: [{
name: 'xc',
}, {
name: {
$includes: 'xc',
}
}],
},
targetEntity: 'bbb',
}
}, context, {});
process.env.NODE_ENV = 'development';
const row = await store.select('oper', {
data: {
id: 1,
data: {
name: 1,
price: 1,
},
},
filter: {
id,
data: {
'.$or': {
$contains: {
name: 'xc',
},
},
},
}
}, context, {});
await context.commit();
assert(row.length === 1);
});
it('[1.12]complicated json filter', async () => {
const context = new TestContext(store);
await context.begin();