sqlparser-devexpress 2.3.11 → 2.3.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlparser-devexpress",
3
- "version": "2.3.11",
3
+ "version": "2.3.12",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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 && ast.field?.type === "value" && ast.value?.type === "value") {
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);
@@ -216,12 +216,11 @@ describe("Parser SQL to dx Filter Builder", () => {
216
216
  expected: []
217
217
  },
218
218
  {
219
- input: "0 IN ('1,2')",
219
+ input: "ID IN ('1,2') AND 0 IN ('0,2')",
220
220
  expected: [
221
- [0, "=", "1"],
221
+ ["ID", "=", "1"],
222
222
  "or",
223
- [0, "=", "2"]
224
-
223
+ ["ID", "=", "2"]
225
224
  ]
226
225
  }
227
226
  ];