filter parser connected

This commit is contained in:
Jan Prochazka
2020-03-12 17:52:19 +01:00
parent fc67ad0b0f
commit f86ad6ba1e
15 changed files with 356 additions and 1059 deletions

View File

@@ -0,0 +1,19 @@
import { DbTypeCode } from '@dbgate/types';
import { FilterType } from './types';
export function getFilterType(typeCode?: DbTypeCode): FilterType {
if (!typeCode) return 'string';
switch (typeCode) {
case 'int':
case 'numeric':
case 'float':
return 'number';
case 'string':
return 'string';
case 'datetime':
return 'datetime';
case 'logical':
return 'logical';
}
return 'string';
}

View File

@@ -0,0 +1,2 @@
export * from './parseFilter';
export * from './getFilterType';

View File

@@ -1,5 +1,6 @@
import P from 'parsimmon';
import { FilterType } from './types';
import { Condition } from '@dbgate/sqltree';
const whitespace = P.regexp(/\s*/m);
@@ -214,7 +215,7 @@ const parsers = {
logical: createParser('logical'),
};
export function parseFilter(value: string, filterType: FilterType) {
export function parseFilter(value: string, filterType: FilterType): Condition {
const ast = parsers[filterType].list.tryParse(value);
return ast;
}