filter parser

This commit is contained in:
Jan Prochazka
2020-03-12 13:15:13 +01:00
parent 064121376f
commit 2de6033dc9
3 changed files with 81 additions and 8 deletions

View File

@@ -5,11 +5,34 @@ import { dumpSqlExpression } from './dumpSqlExpression';
export function dumpSqlCondition(dmp: SqlDumper, condition: Condition) {
switch (condition.conditionType) {
case 'binary':
dmp.put('(');
dumpSqlExpression(dmp, condition.left);
dmp.put(' %s ', condition.operator);
dumpSqlExpression(dmp, condition.right);
dmp.put(')');
break;
case 'isNull':
dumpSqlExpression(dmp, condition.expr);
dmp.put(' ^is ^null');
break;
case 'isNotNull':
dumpSqlExpression(dmp, condition.expr);
dmp.put(' ^is ^not ^null');
break;
case 'isEmpty':
dmp.put('^trim(');
dumpSqlExpression(dmp, condition.expr);
dmp.put(") = ''");
break;
case 'isNotEmpty':
dmp.put('^trim(');
dumpSqlExpression(dmp, condition.expr);
dmp.put(") <> ''");
break;
case 'and':
case 'or':
dmp.putCollection(` ^${condition.conditionType} `, condition.conditions, cond => {
dmp.putRaw('(');
dumpSqlCondition(dmp, cond);
dmp.putRaw(')');
});
}
}

View File

@@ -34,11 +34,21 @@ export interface BinaryCondition {
right: Expression;
}
export interface NotCondition extends UnaryCondition {
export interface NotCondition {
conditionType: 'not';
condition: Condition;
}
export type Condition = BinaryCondition | NotCondition;
export interface TestCondition extends UnaryCondition {
conditionType: 'isNull' | 'isNotNull' | 'isEmpty' | 'isNotEmpty';
}
export interface CompoudCondition {
conditionType: 'and' | 'or';
conditions: Condition[];
}
export type Condition = BinaryCondition | NotCondition | TestCondition | CompoudCondition;
export interface Source {
name?: NamedObjectInfo;