sqlparser-devexpress 2.2.4 → 2.3.1

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.2.4",
3
+ "version": "2.3.1",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -7,7 +7,7 @@ import { LOGICAL_OPERATORS } from "../constants.js";
7
7
  function DevExpressConverter() {
8
8
  // Global variables accessible throughout the converter
9
9
  let resultObject = null;
10
- const EnableShortCircuit = true;
10
+ let EnableShortCircuit = true;
11
11
 
12
12
  /**
13
13
  * Main conversion function that sets up the global context
@@ -376,5 +376,5 @@ const devExpressConverter = DevExpressConverter();
376
376
  * @returns {Array|null} DevExpress format filter
377
377
  */
378
378
  export function convertToDevExpressFormat({ ast, resultObject = null, enableShortCircuit = true }) {
379
- return devExpressConverter.init(ast, resultObject,enableShortCircuit);
379
+ return devExpressConverter.init(ast, resultObject, enableShortCircuit);
380
380
  }
@@ -6,7 +6,7 @@ const tokenPatterns = {
6
6
  function: "\\b(ISNULL)\\b", // Matches function names like ISNULL (case-insensitive)
7
7
  null: "\\bNULL\\b|\\(\\s*NULL\\s*\\)", // Matches NULL as a keyword
8
8
  number: "\\(\\d+\\)|\\d+", // Matches numbers while stripping unnecessary parentheses
9
- placeholder: "'?\\{[^}]+\\}'?", // Matches placeholders like {variable} or '{variable}'
9
+ placeholder: "\\('?\\{[^}]+\\}'?\\)|'?\\{[^}]+\\}'?", // Matches placeholders like {variable} or '{variable}' or ({variable}) or ('{variable}')
10
10
  string: "\\('\\w+\\'\\)|'(?:''|[^'])*'", // Matches strings, allowing for escaped single quotes ('')
11
11
  operator: "=>|<=|!=|>=|=|<>|>|<|\\bAND\\b|\\bOR\\b|\\bBETWEEN\\b|\\bIN\\b|\\bNOT IN\\b|\\bLIKE\\b|\\bIS NOT\\b|\\bNOT LIKE\\b|\\bIS\\b", // Matches SQL operators and logical keywords
12
12
  identifier: "[\\w.]+|\"[^\"]+\"|\\[[^\\]]+\\]", // Matches regular identifiers, quoted identifiers ("identifier"), and bracketed identifiers [identifier]
@@ -47,7 +47,7 @@ class Tokenizer {
47
47
  let value = match.groups[type];
48
48
 
49
49
  // Remove surrounding single quotes from placeholders
50
- if (type === "placeholder") value = value.replace(/^['"]|['"]$/g, "").replace(" ", "");
50
+ if (type === "placeholder") value = value.replace(/^[\s'"\(\)]+|[\s'"\(\)]+|[\s]+/g, "");
51
51
 
52
52
  if (type === "operator") {
53
53
  const lowerValue = value.toLowerCase();
@@ -59,15 +59,15 @@ class Tokenizer {
59
59
  }
60
60
  }
61
61
 
62
- if (LITERALS.includes(type)){
62
+ if (LITERALS.includes(type)) {
63
63
  value = value.replace(/^[(]|[)]$/g, "");
64
64
  }
65
65
 
66
66
  if (type === "identifier") {
67
67
  value = value.replace(/^["\[]|["\]]$/g, "");
68
68
  }
69
-
70
-
69
+
70
+
71
71
  return { type, value };
72
72
  }
73
73
 
package/src/debug.js CHANGED
@@ -25,10 +25,10 @@
25
25
  // const astTree = parsedResult.ast;
26
26
  // console.log("AST Tree:", JSON.stringify(astTree, null, 2), "\n");
27
27
 
28
- // return convertToDevExpressFormat({ ast: astTree, variables: extractedVariables, resultObject: sampleData });
28
+ // return convertToDevExpressFormat({ ast: astTree, resultObject: sampleData });
29
29
  // }
30
30
 
31
- // const devexpress = parseFilterString("OrderID = {CustomerOrders.OrderID} AND Status IN (1, 3)", sampleData);
31
+ // const devexpress = parseFilterString("AddressType IN ('2', ('4')) OR AddressType =({ServiceOrderDocument .SourceID})", sampleData);
32
32
  // console.log("DevExpress Filter:", JSON.stringify(devexpress, null, 2));
33
33
  // // const devexpress = parseFilterString("(RS2ID in ({LeadStatementGlobalRpt.StateID}) Or ({LeadStatementGlobalRpt.StateID} =0)) And (RS3ID in (0,{LeadStatementGlobalRpt.RegionID}) Or {LeadStatementGlobalRpt.RegionID} =0 )", sampleData);
34
34
 
@@ -185,11 +185,13 @@ describe("Parser SQL to dx Filter Builder", () => {
185
185
  ]
186
186
  },
187
187
  {
188
- input: "AddressType IN ('2', ('4'))",
188
+ input: "AddressType IN ('2', ('4')) OR AddressType =({ServiceOrderDocument .SourceID})",
189
189
  expected: [
190
190
  ["AddressType", "=", '2'],
191
191
  "or",
192
- ["AddressType", "=", '4']
192
+ ["AddressType", "=", '4'],
193
+ "or",
194
+ ["AddressType", "=", 2]
193
195
  ]
194
196
  }
195
197
  ];
@@ -217,7 +219,7 @@ describe("Parser SQL to dx Filter Builder", () => {
217
219
  const variables = astwithVariables.variables;
218
220
  const ast = astwithVariables.ast;
219
221
 
220
- const result = convertAstToDevextreme(ast, variables, sampleData);
222
+ const result = convertAstToDevextreme(ast, sampleData);
221
223
 
222
224
  if (result == null || result == true || result == false) {
223
225
  expect([]).toEqual(expected);