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