mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 18:06:01 +00:00
filter behaviour WIP
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
import { isTypeNumber, isTypeString, isTypeLogical, isTypeDateTime } from 'dbgate-tools';
|
||||
import { FilterBehaviour } from 'dbgate-types';
|
||||
import { DatetimeFilterBehaviour, LogicalFilterBehaviour, NumberFilterBehaviour, StringFilterBehaviour } from './filterTypes';
|
||||
|
||||
export function detectSqlFilterType(dataType: string): FilterBehaviour {
|
||||
if (!dataType) return StringFilterBehaviour;
|
||||
if (isTypeNumber(dataType)) return NumberFilterBehaviour;
|
||||
if (isTypeString(dataType)) return StringFilterBehaviour;
|
||||
if (isTypeLogical(dataType)) return LogicalFilterBehaviour;
|
||||
if (isTypeDateTime(dataType)) return DatetimeFilterBehaviour;
|
||||
return StringFilterBehaviour;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
import { FilterBehaviour } from 'dbgate-types';
|
||||
|
||||
export const NumberFilterBehaviour: FilterBehaviour = {
|
||||
compilerType: 'sqlTree',
|
||||
supportEquals: true,
|
||||
supportNumberLikeComparison: true,
|
||||
supportNullTesting: true,
|
||||
supportSqlCondition: true,
|
||||
|
||||
allowNumberToken: true,
|
||||
};
|
||||
|
||||
export const StringFilterBehaviour: FilterBehaviour = {
|
||||
compilerType: 'sqlTree',
|
||||
supportEquals: true,
|
||||
supportStringInclusion: true,
|
||||
supportEmpty: true,
|
||||
supportNumberLikeComparison: true,
|
||||
supportNullTesting: true,
|
||||
supportSqlCondition: true,
|
||||
|
||||
allowStringToken: true,
|
||||
allowHexString: true,
|
||||
};
|
||||
|
||||
export const LogicalFilterBehaviour: FilterBehaviour = {
|
||||
compilerType: 'sqlTree',
|
||||
supportBooleanValues: true,
|
||||
supportNullTesting: true,
|
||||
supportSqlCondition: true,
|
||||
};
|
||||
|
||||
export const DatetimeFilterBehaviour: FilterBehaviour = {
|
||||
compilerType: 'sqlTree',
|
||||
supportNullTesting: true,
|
||||
supportSqlCondition: true,
|
||||
supportDatetimeSymbols: true,
|
||||
supportDatetimeComparison: true,
|
||||
};
|
||||
|
||||
export const MongoFilterBehaviour: FilterBehaviour = {
|
||||
compilerType: 'mongoCondition',
|
||||
supportEquals: true,
|
||||
supportArrayTesting: true,
|
||||
supportNumberLikeComparison: true,
|
||||
supportStringInclusion: true,
|
||||
supportBooleanValues: true,
|
||||
supportExistsTesting: true,
|
||||
};
|
||||
|
||||
export const EvalFilterBehaviour: FilterBehaviour = {
|
||||
compilerType: 'sqlTree',
|
||||
supportEquals: true,
|
||||
supportStringInclusion: true,
|
||||
supportEmpty: true,
|
||||
supportNumberLikeComparison: true,
|
||||
supportNullTesting: true,
|
||||
|
||||
allowStringToken: true,
|
||||
};
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from './parseFilter';
|
||||
export * from './detectSqlFilterBehaviour';
|
||||
export * from './filterTool';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const { parseFilter } = require('./parseFilter');
|
||||
const { StringFilterType } = require('./filterTypes');
|
||||
const { stringFilterBehaviour } = require('dbgate-tools');
|
||||
|
||||
test('parse string', () => {
|
||||
const ast = parseFilter('"123"', StringFilterType);
|
||||
const ast = parseFilter('"123"', stringFilterBehaviour);
|
||||
console.log(JSON.stringify(ast));
|
||||
expect(ast).toEqual({
|
||||
conditionType: 'like',
|
||||
|
||||
Reference in New Issue
Block a user