mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 19:36:00 +00:00
filter parser
This commit is contained in:
@@ -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(')');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user