filter parser

This commit is contained in:
Jan Prochazka
2020-03-12 14:09:13 +01:00
parent 2de6033dc9
commit fc67ad0b0f
3 changed files with 159 additions and 48 deletions

View File

@@ -1,6 +1,7 @@
import { SqlDumper } from '@dbgate/types';
import { Condition, BinaryCondition } from './types';
import { dumpSqlExpression } from './dumpSqlExpression';
import { link } from 'fs';
export function dumpSqlCondition(dmp: SqlDumper, condition: Condition) {
switch (condition.conditionType) {
@@ -34,5 +35,21 @@ export function dumpSqlCondition(dmp: SqlDumper, condition: Condition) {
dumpSqlCondition(dmp, cond);
dmp.putRaw(')');
});
break;
case 'like':
dumpSqlExpression(dmp, condition.left);
dmp.put(' ^like ');
dumpSqlExpression(dmp, condition.right);
break;
case 'notLike':
dumpSqlExpression(dmp, condition.left);
dmp.put(' ^not ^like ');
dumpSqlExpression(dmp, condition.right);
break;
case 'not':
dmp.put('^not (');
dumpSqlCondition(dmp, condition.condition);
dmp.put(')');
break;
}
}

View File

@@ -28,8 +28,14 @@ export interface UnaryCondition {
}
export interface BinaryCondition {
operator: '=' | '!=' | '<' | '>' | '>=' | '<=';
conditionType: 'binary';
operator: '=' | '!=' | '<' | '>' | '>=' | '<=';
left: Expression;
right: Expression;
}
export interface LikeCondition {
conditionType: 'like' | 'notLike';
left: Expression;
right: Expression;
}
@@ -48,7 +54,7 @@ export interface CompoudCondition {
conditions: Condition[];
}
export type Condition = BinaryCondition | NotCondition | TestCondition | CompoudCondition;
export type Condition = BinaryCondition | NotCondition | TestCondition | CompoudCondition | LikeCondition;
export interface Source {
name?: NamedObjectInfo;