增加了

This commit is contained in:
Xu Chang 2025-06-09 15:22:37 +08:00
parent d3a25696f1
commit df6bdc721c
3 changed files with 125 additions and 8 deletions

View File

@ -399,6 +399,20 @@ class MySqlTranslator extends sqlTranslator_1.SqlTranslator {
stmt2 += `(JSON_OVERLAPS(${alias}.${attr}, CAST('${value}' AS JSON)))`;
}
}
else if (attr2 === '$length') {
// json length
const length = o[attr2];
(0, assert_1.default)(typeof length == 'number');
if (stmt2) {
stmt2 += ' and ';
}
if (p) {
stmt2 += `(JSON_LENGTH(${alias}.${attr}->>"$${p}") = ${length})`;
}
else {
stmt2 += `(JSON_LENGTH(${alias}.${attr})= ${length})`;
}
}
else if (attr2.startsWith('$')) {
if (stmt2) {
stmt2 += ' and ';

View File

@ -453,6 +453,20 @@ export class MySqlTranslator<ED extends EntityDict & BaseEntityDict> extends Sql
stmt2 += `(JSON_OVERLAPS(${alias}.${attr}, CAST('${value}' AS JSON)))`;
}
}
else if (attr2 === '$length') {
// json length
const length = o[attr2];
assert (typeof length == 'number');
if (stmt2) {
stmt2 += ' and ';
}
if (p) {
stmt2 += `(JSON_LENGTH(${alias}.${attr}->>"$${p}") = ${length})`;
}
else {
stmt2 += `(JSON_LENGTH(${alias}.${attr})= ${length})`;
}
}
else if (attr2.startsWith('$')) {
if (stmt2) {
stmt2 += ' and ';

View File

@ -478,7 +478,10 @@ describe('test mysqlstore', function () {
folder: '/systest',
platformId: 'platform-111',
} as EntityDict['system']['CreateSingle']['data']
}
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}, {
id: id2,
name: 'test2',
@ -506,7 +509,10 @@ describe('test mysqlstore', function () {
folder: '/test2',
platformId: 'platform-111',
}
}
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}]
}, context, {});
@ -588,7 +594,10 @@ describe('test mysqlstore', function () {
folder: '/systest',
platformId: 'platform-111',
}
}
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}, {
id: 'aaaa2',
name: 'test2',
@ -616,7 +625,10 @@ describe('test mysqlstore', function () {
folder: '/test2',
platformId: 'platform-111',
}
}
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}]
}, context, {});
@ -740,7 +752,10 @@ describe('test mysqlstore', function () {
folder: '/systest',
platformId: 'platform-111',
}
}
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}, {
id: 'aaa5-2',
name: 'test2',
@ -768,7 +783,10 @@ describe('test mysqlstore', function () {
folder: '/test2',
platformId: 'platform-111',
} as EntityDict['system']['CreateSingle']['data'],
}
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}]
}, context, {});
@ -880,6 +898,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
},
{
@ -894,6 +915,9 @@ describe('test mysqlstore', function () {
type: 'web',
passport: [],
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}]
}
@ -975,6 +999,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}, {
id: v4(),
@ -993,6 +1020,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}]
}
@ -1104,6 +1134,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
},
{
@ -1118,6 +1151,9 @@ describe('test mysqlstore', function () {
type: 'web',
passport: [],
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}]
},
@ -1142,6 +1178,9 @@ describe('test mysqlstore', function () {
type: 'web',
passport: [],
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
},
{
@ -1156,6 +1195,9 @@ describe('test mysqlstore', function () {
type: 'web',
passport: [],
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}]
}
@ -1225,6 +1267,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
},
{
@ -1244,6 +1289,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}]
},
@ -1273,6 +1321,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
},
{
@ -1292,6 +1343,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}]
}
@ -1353,6 +1407,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}, {});
@ -1396,6 +1453,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}, {});
@ -1628,13 +1688,13 @@ describe('test mysqlstore', function () {
},
{
name: {
'.$includes': 'xc',
'.$includes': 'xc',
}
}
],
},
}
}, context, {});
}, context, {});
await context.commit();
assert(row.length === 1);
@ -1811,6 +1871,22 @@ describe('test mysqlstore', function () {
}
}
}, context, {});
const row9 = await store.select('oper', {
data: {
id: 1,
data: {
name: 1,
price: 1,
},
},
filter: {
data: {
price: {
$length: 3,
},
}
}
}, context, {});
await context.commit();
assert(row.length === 1);
@ -1821,6 +1897,7 @@ describe('test mysqlstore', function () {
assert(row6.length === 0);
assert(row7.length === 1);
assert(row8.length === 1);
assert(row9.length === 1);
// console.log(JSON.stringify(row7));
});
@ -1857,6 +1934,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
},
{
@ -1876,6 +1956,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}]
},
@ -1905,6 +1988,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
},
{
@ -1924,6 +2010,9 @@ describe('test mysqlstore', function () {
port: '',
},
},
dangerousVersions: [],
warningVersions: [],
soaVersion: '',
}
}]
},