mongo filtering via sql tree

This commit is contained in:
Jan Prochazka
2024-08-19 16:25:16 +02:00
parent 9fedfcbb0e
commit 303bd659ad
6 changed files with 129 additions and 7 deletions

View File

@@ -89,6 +89,38 @@ function convertToMongoCondition(filter) {
$options: 'i',
},
};
case 'specificPredicate':
switch (filter.predicate) {
case 'exists':
return {
[convertLeftOperandToMongoColumn(filter.expr)]: {
$exists: true,
},
};
case 'notExists':
return {
[convertLeftOperandToMongoColumn(filter.expr)]: {
$exists: false,
},
};
case 'emptyArray':
return {
[convertLeftOperandToMongoColumn(filter.expr)]: {
$exists: true,
$eq: [],
},
};
case 'notEmptyArray':
return {
[convertLeftOperandToMongoColumn(filter.expr)]: {
$exists: true,
$type: 'array',
$ne: [],
},
};
}
default:
throw new Error(`Unknown condition type ${filter.conditionType}`);
}