sqlparser-devexpress 2.3.18 → 2.3.19

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core/parser.js +15 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlparser-devexpress",
3
- "version": "2.3.18",
3
+ "version": "2.3.19",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -142,15 +142,12 @@ export function parse(input, variables = []) {
142
142
  left = { type: "logical", operator, left, right };
143
143
  } else if (currentToken?.type == "identifier") {
144
144
  const right = parseValue(operator);
145
- let newOp = operator;
146
- if (operator === '>') newOp = '<';
147
- else if (operator === '<') newOp = '>';
148
- else if (operator === '>=') newOp = '<=';
149
- else if (operator === '<=') newOp = '>=';
145
+ let newOperator = inverseOperator(operator);
146
+
150
147
  left = {
151
148
  type: "comparison",
152
149
  right: left,
153
- operator: newOp,
150
+ operator: newOperator,
154
151
  left: { type: "field", value: right }
155
152
  };
156
153
  }
@@ -233,7 +230,8 @@ export function parse(input, variables = []) {
233
230
 
234
231
  // Swap the field and value if the field is a placeholder and the value is an identifier
235
232
  if (valueType == "identifier" && fieldType == "placeholder") {
236
- return { type: "comparison", value: field, operator, field: value, originalOperator };
233
+ let newOperator = inverseOperator(operator);
234
+ return { type: "comparison", value: field, operator: newOperator, field: value, originalOperator };
237
235
  }
238
236
 
239
237
  return { type: "comparison", field, operator, value, originalOperator };
@@ -242,6 +240,16 @@ export function parse(input, variables = []) {
242
240
  return { type: "field", value: field };
243
241
  }
244
242
 
243
+ function inverseOperator(operator) {
244
+ switch (operator.toUpperCase()) {
245
+ case ">": return "<";
246
+ case "<": return ">";
247
+ case ">=": return "<=";
248
+ case "<=": return ">=";
249
+ default: return operator; // Return the operator as is if no inverse is defined
250
+ }
251
+ }
252
+
245
253
  // Parses values including numbers, strings, placeholders, and IN lists
246
254
  function parseValue(operatorToken) {
247
255
  if (!currentToken) throw new Error("Unexpected end of input");