sqlparser-devexpress 2.3.11 → 2.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/constants.js +3 -1
- package/src/core/converter.js +19 -1
- package/tests/parser.test.js +3 -4
package/package.json
CHANGED
package/src/constants.js
CHANGED
|
@@ -10,4 +10,6 @@ export const OPERATOR_PRECEDENCE = {
|
|
|
10
10
|
// Regular expression to check for unsupported SQL patterns (like SELECT-FROM or JOIN statements)
|
|
11
11
|
export const UNSUPPORTED_PATTERN = /\bSELECT\b.*\bFROM\b|\bINNER\s+JOIN\b/i;
|
|
12
12
|
|
|
13
|
-
export const LOGICAL_OPERATORS = ['and', 'or'];
|
|
13
|
+
export const LOGICAL_OPERATORS = ['and', 'or'];
|
|
14
|
+
|
|
15
|
+
export const LITERAL_TYPES = ["value", "placeholder"];
|
package/src/core/converter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LOGICAL_OPERATORS } from "../constants.js";
|
|
1
|
+
import { LITERAL_TYPES, LOGICAL_OPERATORS } from "../constants.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Main conversion function that sets up the global context
|
|
@@ -206,6 +206,24 @@ function DevExpressConverter() {
|
|
|
206
206
|
resolvedValue = resolvedValue.split(',').map(v => v.trim());
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
// handle short circuit evaluation for IN operator
|
|
210
|
+
if (EnableShortCircuit && (LITERAL_TYPES.includes(ast.field?.type) && LITERAL_TYPES.includes(ast.value?.type))) {
|
|
211
|
+
const fieldVal = convertValue(ast.field);
|
|
212
|
+
if (Array.isArray(resolvedValue)) {
|
|
213
|
+
// normalize numeric strings if LHS is number
|
|
214
|
+
const list = resolvedValue.map(x =>
|
|
215
|
+
(typeof x === "string" && !isNaN(x) && typeof fieldVal === "number")
|
|
216
|
+
? Number(x)
|
|
217
|
+
: x
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
if (operator === "IN")
|
|
221
|
+
return list.includes(fieldVal);
|
|
222
|
+
else if (operator === "NOT IN")
|
|
223
|
+
return !list.includes(fieldVal);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
209
227
|
let operatorToken = operator === "IN" ? '=' : operator === "NOT IN" ? '!=' : operator;
|
|
210
228
|
let joinOperatorToken = operator === "IN" ? 'or' : operator === "NOT IN" ? 'and' : operator;
|
|
211
229
|
let field = convertValue(ast.field);
|
package/tests/parser.test.js
CHANGED
|
@@ -216,12 +216,11 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
216
216
|
expected: []
|
|
217
217
|
},
|
|
218
218
|
{
|
|
219
|
-
input: "
|
|
219
|
+
input: "ID IN ('1,2') AND 0 IN ('0,2')",
|
|
220
220
|
expected: [
|
|
221
|
-
[
|
|
221
|
+
["ID", "=", "1"],
|
|
222
222
|
"or",
|
|
223
|
-
[
|
|
224
|
-
|
|
223
|
+
["ID", "=", "2"]
|
|
225
224
|
]
|
|
226
225
|
}
|
|
227
226
|
];
|