sqlparser-devexpress 2.3.4 → 2.3.5

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/README.md CHANGED
@@ -126,6 +126,60 @@ console.log("DevExpress Filter:", JSON.stringify(devexpressFilter, null, 2));
126
126
  const devexpressFilter = convertAstToDevextreme(ast, sampleState, false); // Disables short-circuiting
127
127
  ```
128
128
 
129
+ ### **DevExtreme with React Example**
130
+
131
+ First, install the necessary DevExtreme packages:
132
+
133
+ ```sh
134
+ npm install devextreme devextreme-react
135
+ ```
136
+
137
+ Now, create a simple React component that integrates DevExtreme with the `sqlparser-devexpress` library:
138
+
139
+ ```javascript
140
+ import React, { useState } from 'react';
141
+ import DataGrid, { Column, FilterRow, HeaderFilter } from 'devextreme-react/data-grid';
142
+ import 'devextreme/dist/css/dx.light.css';
143
+ import { convertSQLToAst, convertAstToDevextreme } from 'sqlparser-devexpress';
144
+
145
+ const App = () => {
146
+ const [data, setData] = useState([
147
+ { OrderID: 76548, Status: 1 },
148
+ { OrderID: 76549, Status: 3 },
149
+ { OrderID: 76550, Status: 2 },
150
+ ]);
151
+
152
+ const sqlQuery = "OrderID = {CustomerOrders.OrderID} OR Status IN (1, 3)";
153
+ const { ast, variables } = convertSQLToAst(sqlQuery);
154
+
155
+ // Extracted state for dynamic variables (usually fetched from your app state)
156
+ const sampleState = { "CustomerOrders.OrderID": 76548 };
157
+
158
+ const devexpressFilter = convertAstToDevextreme(ast, sampleState);
159
+
160
+ return (
161
+ <div>
162
+ <DataGrid dataSource={data} filterValue={devexpressFilter}>
163
+ <Column dataField="OrderID" />
164
+ <Column dataField="Status" />
165
+ <FilterRow visible={true} />
166
+ <HeaderFilter visible={true} />
167
+ </DataGrid>
168
+ </div>
169
+ );
170
+ };
171
+
172
+ export default App;
173
+ ```
174
+
175
+ ### **Explanation**:
176
+ 1. **DataGrid**: Displays the data with filtering.
177
+ 2. **convertSQLToAst**: Converts the SQL `WHERE` clause into an AST.
178
+ 3. **convertAstToDevextreme**: Converts the AST to the DevExtreme filter format.
179
+ 4. **filterValue**: Applies the filter to the `DataGrid`.
180
+
181
+ This is a simple integration where the filter from SQLParser is used to filter the grid data in a React app using DevExtreme's `DataGrid`.
182
+
129
183
  ## Roadmap
130
184
 
131
185
  - Support for additional SQL operators and functions.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlparser-devexpress",
3
- "version": "2.3.4",
3
+ "version": "2.3.5",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -12,7 +12,7 @@ export interface ParsedResult {
12
12
 
13
13
  export interface ConvertToDevExpressFormatParams {
14
14
  ast: any; // Define a more specific type if possible
15
- resultObject: StateDataObject;
15
+ resultObject?: StateDataObject | null;
16
16
  enableShortCircuit?: boolean;
17
17
  }
18
18
 
@@ -136,7 +136,13 @@ function DevExpressConverter() {
136
136
 
137
137
  const left = ast.left !== undefined ? processAstNode(ast.left) : convertValue(ast.field);
138
138
  const right = ast.right !== undefined ? processAstNode(ast.right) : convertValue(ast.value);
139
- const operatorToken = ast.operator.toLowerCase();
139
+ let operatorToken = ast.operator.toLowerCase();
140
+
141
+ if(operatorToken === "like") {
142
+ operatorToken = "contains";
143
+ }else if (operatorToken === "not like") {
144
+ operatorToken = "notcontains";
145
+ }
140
146
 
141
147
  let comparison = [left, operatorToken, right];
142
148
 
@@ -173,6 +173,15 @@ export function parse(input, variables = []) {
173
173
  if (currentToken.type === "function") {
174
174
  const functionNode = parseFunction();
175
175
 
176
+ if(fieldType === "identifier" && functionNode.type === "function") {
177
+ return {
178
+ type: "comparison",
179
+ field,
180
+ operator,
181
+ value: functionNode
182
+ }
183
+ }
184
+
176
185
  // Wrap the function inside a comparison if it's directly after an operator
177
186
  const leftComparison = {
178
187
  type: "comparison",
package/src/debug.js CHANGED
@@ -28,7 +28,7 @@
28
28
  // return convertToDevExpressFormat({ ast: astTree, resultObject: sampleData });
29
29
  // }
30
30
 
31
- // const devexpress = parseFilterString("CompanyID = ISNULL({LeadDocument.CompanyID},0) OR (ISNULL(CompanyID,0) = 0))", sampleData);
31
+ // const devexpress = parseFilterString("CompanyID not like '{CustomerOrders.OrderID}'", 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
 
package/src/index.js CHANGED
@@ -16,7 +16,7 @@ export function convertSQLToAst(filterString, enableConsoleLogs = false) {
16
16
  return parsedResult;
17
17
  }
18
18
 
19
- export function convertAstToDevextreme(ast, state, enableShortCircuit = true) {
19
+ export function convertAstToDevextreme(ast, state = null, enableShortCircuit = true) {
20
20
  return convertToDevExpressFormat({ ast, resultObject: state, enableShortCircuit })
21
21
  }
22
22
 
@@ -204,6 +204,14 @@ describe("Parser SQL to dx Filter Builder", () => {
204
204
  ]
205
205
 
206
206
  ]
207
+ },
208
+ {
209
+ input: "CompanyName like '{LeadDocument.CompanyID}' AND BranchName not like '{LeadDocument.BranchID}'",
210
+ expected: [
211
+ ["CompanyName", "contains", "7"],
212
+ "and",
213
+ ["BranchName", "notcontains", "42"]
214
+ ]
207
215
  }
208
216
  ];
209
217