mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
support for binary values in filters #467
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { isTypeDateTime } from 'dbgate-tools';
|
import { arrayToHexString, isTypeDateTime } from 'dbgate-tools';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
export type FilterMultipleValuesMode = 'is' | 'is_not' | 'contains' | 'begins' | 'ends';
|
export type FilterMultipleValuesMode = 'is' | 'is_not' | 'contains' | 'begins' | 'ends';
|
||||||
@@ -9,6 +9,10 @@ export function getFilterValueExpression(value, dataType?) {
|
|||||||
if (value === true) return 'TRUE';
|
if (value === true) return 'TRUE';
|
||||||
if (value === false) return 'FALSE';
|
if (value === false) return 'FALSE';
|
||||||
if (value.$oid) return `ObjectId("${value.$oid}")`;
|
if (value.$oid) return `ObjectId("${value.$oid}")`;
|
||||||
|
if (value.type == 'Buffer' && Array.isArray(value.data)) {
|
||||||
|
return '0x' + arrayToHexString(value.data);
|
||||||
|
}
|
||||||
|
|
||||||
return `="${value}"`;
|
return `="${value}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Condition } from 'dbgate-sqltree';
|
|||||||
import { interpretEscapes, token, word, whitespace } from './common';
|
import { interpretEscapes, token, word, whitespace } from './common';
|
||||||
import { mongoParser } from './mongoParser';
|
import { mongoParser } from './mongoParser';
|
||||||
import { datetimeParser } from './datetimeParser';
|
import { datetimeParser } from './datetimeParser';
|
||||||
|
import { hexStringToArray } from 'dbgate-tools';
|
||||||
|
|
||||||
const binaryCondition = operator => value => ({
|
const binaryCondition = operator => value => ({
|
||||||
conditionType: 'binary',
|
conditionType: 'binary',
|
||||||
@@ -104,6 +105,14 @@ const createParser = (filterType: FilterType) => {
|
|||||||
.map(Number)
|
.map(Number)
|
||||||
.desc('number'),
|
.desc('number'),
|
||||||
|
|
||||||
|
hexstring: () =>
|
||||||
|
token(P.regexp(/0x(([0-9a-fA-F][0-9a-fA-F])+)/, 1))
|
||||||
|
.map(x => ({
|
||||||
|
type: 'Buffer',
|
||||||
|
data: hexStringToArray(x),
|
||||||
|
}))
|
||||||
|
.desc('hex string'),
|
||||||
|
|
||||||
noQuotedString: () => P.regexp(/[^\s^,^'^"]+/).desc('string unquoted'),
|
noQuotedString: () => P.regexp(/[^\s^,^'^"]+/).desc('string unquoted'),
|
||||||
|
|
||||||
sql: () =>
|
sql: () =>
|
||||||
@@ -113,6 +122,7 @@ const createParser = (filterType: FilterType) => {
|
|||||||
|
|
||||||
value: r => P.alt(...allowedValues.map(x => r[x])),
|
value: r => P.alt(...allowedValues.map(x => r[x])),
|
||||||
valueTestEq: r => r.value.map(binaryCondition('=')),
|
valueTestEq: r => r.value.map(binaryCondition('=')),
|
||||||
|
hexTestEq: r => r.hexstring.map(binaryCondition('=')),
|
||||||
valueTestStr: r => r.value.map(likeCondition('like', '%#VALUE#%')),
|
valueTestStr: r => r.value.map(likeCondition('like', '%#VALUE#%')),
|
||||||
|
|
||||||
comma: () => word(','),
|
comma: () => word(','),
|
||||||
@@ -158,7 +168,7 @@ const createParser = (filterType: FilterType) => {
|
|||||||
allowedElements.push('le', 'ge', 'lt', 'gt');
|
allowedElements.push('le', 'ge', 'lt', 'gt');
|
||||||
}
|
}
|
||||||
if (filterType == 'string') {
|
if (filterType == 'string') {
|
||||||
allowedElements.push('empty', 'notEmpty');
|
allowedElements.push('empty', 'notEmpty', 'hexTestEq');
|
||||||
}
|
}
|
||||||
if (filterType == 'eval' || filterType == 'string') {
|
if (filterType == 'eval' || filterType == 'string') {
|
||||||
allowedElements.push('startsWith', 'endsWith', 'contains', 'startsWithNot', 'endsWithNot', 'containsNot');
|
allowedElements.push('startsWith', 'endsWith', 'contains', 'startsWithNot', 'endsWithNot', 'containsNot');
|
||||||
|
|||||||
Reference in New Issue
Block a user