mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 04:23:57 +00:00
mongo filters fixed
This commit is contained in:
@@ -5,7 +5,15 @@ import { interpretEscapes, token, word, whitespace } from './common';
|
|||||||
import { hexStringToArray } from 'dbgate-tools';
|
import { hexStringToArray } from 'dbgate-tools';
|
||||||
import { FilterBehaviour, TransformType } from 'dbgate-types';
|
import { FilterBehaviour, TransformType } from 'dbgate-types';
|
||||||
|
|
||||||
const binaryCondition = operator => value => ({
|
const binaryCondition =
|
||||||
|
(operator, numberDualTesting = false) =>
|
||||||
|
value => {
|
||||||
|
const numValue = parseFloat(value);
|
||||||
|
if (numberDualTesting && !isNaN(numValue)) {
|
||||||
|
return {
|
||||||
|
conditionType: 'or',
|
||||||
|
conditions: [
|
||||||
|
{
|
||||||
conditionType: 'binary',
|
conditionType: 'binary',
|
||||||
operator,
|
operator,
|
||||||
left: {
|
left: {
|
||||||
@@ -15,7 +23,34 @@ const binaryCondition = operator => value => ({
|
|||||||
exprType: 'value',
|
exprType: 'value',
|
||||||
value,
|
value,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
{
|
||||||
|
conditionType: 'binary',
|
||||||
|
operator,
|
||||||
|
left: {
|
||||||
|
exprType: 'placeholder',
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
exprType: 'value',
|
||||||
|
value: numValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
conditionType: 'binary',
|
||||||
|
operator,
|
||||||
|
left: {
|
||||||
|
exprType: 'placeholder',
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
exprType: 'value',
|
||||||
|
value,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const likeCondition = (conditionType, likeString) => value => ({
|
const likeCondition = (conditionType, likeString) => value => ({
|
||||||
conditionType,
|
conditionType,
|
||||||
@@ -95,48 +130,6 @@ const numberTestCondition = () => value => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const numberTestIfNumberCondition = () => value => {
|
|
||||||
const numValue = parseFloat(value);
|
|
||||||
if (isNaN(numValue)) {
|
|
||||||
return {
|
|
||||||
conditionType: 'like',
|
|
||||||
left: {
|
|
||||||
exprType: 'placeholder',
|
|
||||||
},
|
|
||||||
right: {
|
|
||||||
exprType: 'value',
|
|
||||||
value: `.*${value}.*`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
conditionType: 'or',
|
|
||||||
conditions: [
|
|
||||||
{
|
|
||||||
conditionType: 'like',
|
|
||||||
left: {
|
|
||||||
exprType: 'placeholder',
|
|
||||||
},
|
|
||||||
right: {
|
|
||||||
exprType: 'value',
|
|
||||||
value: `.*${value}.*`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
conditionType: 'binary',
|
|
||||||
operator: '=',
|
|
||||||
left: {
|
|
||||||
exprType: 'placeholder',
|
|
||||||
},
|
|
||||||
right: {
|
|
||||||
exprType: 'value',
|
|
||||||
value: numValue,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const idRegex = /[('"]([0-9a-f]{24})['")]/;
|
const idRegex = /[('"]([0-9a-f]{24})['")]/;
|
||||||
|
|
||||||
const objectIdTestCondition = () => value => ({
|
const objectIdTestCondition = () => value => ({
|
||||||
@@ -455,14 +448,13 @@ const createParser = (filterBehaviour: FilterBehaviour) => {
|
|||||||
trueNum: () => word('1').map(binaryFixedValueCondition('1')),
|
trueNum: () => word('1').map(binaryFixedValueCondition('1')),
|
||||||
falseNum: () => word('0').map(binaryFixedValueCondition('0')),
|
falseNum: () => word('0').map(binaryFixedValueCondition('0')),
|
||||||
|
|
||||||
eq: r => word('=').then(r.value).map(binaryCondition('=')),
|
eq: r => word('=').then(r.value).map(binaryCondition('=', filterBehaviour.allowNumberDualTesting)),
|
||||||
eqNum: r => word('=').then(r.value).map(numberTestIfNumberCondition()),
|
ne: r => word('!=').then(r.value).map(binaryCondition('<>', filterBehaviour.allowNumberDualTesting)),
|
||||||
ne: r => word('!=').then(r.value).map(binaryCondition('<>')),
|
ne2: r => word('<>').then(r.value).map(binaryCondition('<>', filterBehaviour.allowNumberDualTesting)),
|
||||||
ne2: r => word('<>').then(r.value).map(binaryCondition('<>')),
|
le: r => word('<=').then(r.value).map(binaryCondition('<=', filterBehaviour.allowNumberDualTesting)),
|
||||||
le: r => word('<=').then(r.value).map(binaryCondition('<=')),
|
ge: r => word('>=').then(r.value).map(binaryCondition('>=', filterBehaviour.allowNumberDualTesting)),
|
||||||
ge: r => word('>=').then(r.value).map(binaryCondition('>=')),
|
lt: r => word('<').then(r.value).map(binaryCondition('<', filterBehaviour.allowNumberDualTesting)),
|
||||||
lt: r => word('<').then(r.value).map(binaryCondition('<')),
|
gt: r => word('>').then(r.value).map(binaryCondition('>', filterBehaviour.allowNumberDualTesting)),
|
||||||
gt: r => word('>').then(r.value).map(binaryCondition('>')),
|
|
||||||
startsWith: r => word('^').then(r.value).map(likeCondition('like', '#VALUE#%')),
|
startsWith: r => word('^').then(r.value).map(likeCondition('like', '#VALUE#%')),
|
||||||
endsWith: 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#%')),
|
contains: r => word('+').then(r.value).map(likeCondition('like', '%#VALUE#%')),
|
||||||
@@ -523,12 +515,7 @@ const createParser = (filterBehaviour: FilterBehaviour) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filterBehaviour.supportEquals) {
|
if (filterBehaviour.supportEquals) {
|
||||||
if (filterBehaviour.allowNumberDualTesting) {
|
allowedElements.push('eq', 'ne', 'ne2');
|
||||||
allowedElements.push('eqNum');
|
|
||||||
} else {
|
|
||||||
allowedElements.push('eq');
|
|
||||||
}
|
|
||||||
allowedElements.push('ne', 'ne2');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filterBehaviour.supportSqlCondition) {
|
if (filterBehaviour.supportSqlCondition) {
|
||||||
|
|||||||
Reference in New Issue
Block a user