mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 01:26:01 +00:00
filter parser connected
This commit is contained in:
19
packages/filterparser/src/getFilterType.ts
Normal file
19
packages/filterparser/src/getFilterType.ts
Normal 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';
|
||||
}
|
||||
2
packages/filterparser/src/index.ts
Normal file
2
packages/filterparser/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './parseFilter';
|
||||
export * from './getFilterType';
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user