mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 22:36:01 +00:00
SYNC: Merge pull request #5 from dbgate/feature/firestore
This commit is contained in:
@@ -6,11 +6,13 @@ import { hexStringToArray, parseNumberSafe } from 'dbgate-tools';
|
||||
import { FilterBehaviour, TransformType } from 'dbgate-types';
|
||||
|
||||
const binaryCondition =
|
||||
(operator, numberDualTesting = false) =>
|
||||
(operator, filterBehaviour: FilterBehaviour = {}) =>
|
||||
value => {
|
||||
const { passNumbers, allowNumberDualTesting } = filterBehaviour;
|
||||
const numValue = parseNumberSafe(value);
|
||||
|
||||
if (
|
||||
numberDualTesting &&
|
||||
allowNumberDualTesting &&
|
||||
// @ts-ignore
|
||||
!isNaN(numValue)
|
||||
) {
|
||||
@@ -43,6 +45,21 @@ const binaryCondition =
|
||||
};
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
if (passNumbers && !isNaN(numValue)) {
|
||||
return {
|
||||
conditionType: 'binary',
|
||||
operator,
|
||||
left: {
|
||||
exprType: 'placeholder',
|
||||
},
|
||||
right: {
|
||||
exprType: 'value',
|
||||
value: numValue,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
conditionType: 'binary',
|
||||
operator,
|
||||
@@ -462,18 +479,18 @@ const createParser = (filterBehaviour: FilterBehaviour) => {
|
||||
null: () => word('NULL').map(unaryCondition('isNull')),
|
||||
isEmpty: r => r.empty.map(unaryCondition('isEmpty')),
|
||||
isNotEmpty: r => r.not.then(r.empty).map(unaryCondition('isNotEmpty')),
|
||||
true: () => P.regexp(/true/i).map(binaryFixedValueCondition('1')),
|
||||
false: () => P.regexp(/false/i).map(binaryFixedValueCondition('0')),
|
||||
true: () => P.regexp(/true/i).map(binaryFixedValueCondition(filterBehaviour.passBooleans ? true : '1')),
|
||||
false: () => P.regexp(/false/i).map(binaryFixedValueCondition(filterBehaviour.passBooleans ? false : '0')),
|
||||
trueNum: () => word('1').map(binaryFixedValueCondition('1')),
|
||||
falseNum: () => word('0').map(binaryFixedValueCondition('0')),
|
||||
|
||||
eq: r => word('=').then(r.value).map(binaryCondition('=', filterBehaviour.allowNumberDualTesting)),
|
||||
ne: r => word('!=').then(r.value).map(binaryCondition('<>', filterBehaviour.allowNumberDualTesting)),
|
||||
ne2: r => word('<>').then(r.value).map(binaryCondition('<>', filterBehaviour.allowNumberDualTesting)),
|
||||
le: r => word('<=').then(r.value).map(binaryCondition('<=', filterBehaviour.allowNumberDualTesting)),
|
||||
ge: r => word('>=').then(r.value).map(binaryCondition('>=', filterBehaviour.allowNumberDualTesting)),
|
||||
lt: r => word('<').then(r.value).map(binaryCondition('<', filterBehaviour.allowNumberDualTesting)),
|
||||
gt: r => word('>').then(r.value).map(binaryCondition('>', filterBehaviour.allowNumberDualTesting)),
|
||||
eq: r => word('=').then(r.value).map(binaryCondition('=', filterBehaviour)),
|
||||
ne: r => word('!=').then(r.value).map(binaryCondition('<>', filterBehaviour)),
|
||||
ne2: r => word('<>').then(r.value).map(binaryCondition('<>', filterBehaviour)),
|
||||
le: r => word('<=').then(r.value).map(binaryCondition('<=', filterBehaviour)),
|
||||
ge: r => word('>=').then(r.value).map(binaryCondition('>=', filterBehaviour)),
|
||||
lt: r => word('<').then(r.value).map(binaryCondition('<', filterBehaviour)),
|
||||
gt: r => word('>').then(r.value).map(binaryCondition('>', filterBehaviour)),
|
||||
startsWith: r => word('^').then(r.value).map(likeCondition('like', '#VALUE#%')),
|
||||
endsWith: r => word('$').then(r.value).map(likeCondition('like', '%#VALUE#')),
|
||||
contains: r => word('+').then(r.value).map(likeCondition('like', '%#VALUE#%')),
|
||||
@@ -526,8 +543,12 @@ const createParser = (filterBehaviour: FilterBehaviour) => {
|
||||
allowedElements.push('exists', 'notExists');
|
||||
}
|
||||
|
||||
if (filterBehaviour.supportArrayTesting) {
|
||||
allowedElements.push('emptyArray', 'notEmptyArray');
|
||||
if (filterBehaviour.supportEmptyArrayTesting) {
|
||||
allowedElements.push('emptyArray');
|
||||
}
|
||||
|
||||
if (filterBehaviour.supportNotEmptyArrayTesting) {
|
||||
allowedElements.push('notEmptyArray');
|
||||
}
|
||||
|
||||
if (filterBehaviour.supportNullTesting) {
|
||||
|
||||
Reference in New Issue
Block a user