refactor: Improve JSON filter handling in StatementGenerator.ts

This commit is contained in:
Simon Larsen 2024-05-16 17:46:43 +01:00
parent 164e6062c9
commit b6adf3fb40
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
2 changed files with 25 additions and 4 deletions

View File

@ -429,7 +429,7 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
) {
whereStatement.append(
SQL`AND JSONExtractString(${key}, ${{
value: key,
value: objKey,
type: TableColumnType.Text,
}}) = ${{
value: flatValue[objKey] as string,
@ -445,7 +445,7 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
) {
whereStatement.append(
SQL`AND JSONExtractInt(${key}, ${{
value: key,
value: objKey,
type: TableColumnType.Text,
}}) = ${{
value: flatValue[objKey] as number,
@ -454,9 +454,23 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
);
continue;
}
}
if (
flatValue[objKey] &&
typeof flatValue[objKey] === 'boolean'
) {
whereStatement.append(
SQL`AND JSONExtractBool(${key}, ${{
value: objKey,
type: TableColumnType.Text,
}}) = ${{
value: flatValue[objKey] as number,
type: TableColumnType.Boolean,
}}`
);
continue;
}
}
} else {
whereStatement.append(
SQL`AND ${key} = ${{ value, type: tableColumn.type }}`

View File

@ -55,6 +55,13 @@ const ServiceDelete: FunctionComponent<PageComponentProps> = (
title: 'Name',
type: FieldType.Text,
},
{
field: {
attributes: true,
},
type: FieldType.JSON,
title: 'Attributes',
},
]}
columns={[
{