Skip to content

Commit ad77869

Browse files
authored
Merge pull request #7 from RohitM-IN/development
Bug Fixes
2 parents 83cd196 + 1f58a77 commit ad77869

File tree

7 files changed

+283
-213
lines changed

7 files changed

+283
-213
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sqlparser-devexpress",
3-
"version": "2.0.7",
3+
"version": "2.1.0",
44
"main": "src/index.js",
55
"type": "module",
66
"scripts": {
@@ -10,6 +10,7 @@
1010
"import": "./src/index.js",
1111
"require": "./src/index.js"
1212
},
13+
"types": "src/@types/default.d.ts",
1314
"keywords": [
1415
"sql",
1516
"parser",

src/@types/default.d.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export type StateDataObject = Record<string, any>;
2+
3+
export interface SanitizedQuery {
4+
sanitizedSQL: string;
5+
extractedVariables: string[];
6+
}
7+
8+
export interface ParsedResult {
9+
ast: any; // Define a more specific type if possible
10+
variables: string[];
11+
}
12+
13+
export interface ConvertToDevExpressFormatParams {
14+
ast: any; // Define a more specific type if possible
15+
variables: string[];
16+
resultObject: StateDataObject;
17+
}
18+
19+
export function sanitizeQuery(filterString: string): SanitizedQuery;
20+
21+
export function parse(query: string, variables: string[]): ParsedResult;
22+
23+
export function convertToDevExpressFormat(params: ConvertToDevExpressFormatParams): any;
24+
25+
export function convertSQLToAst(
26+
filterString: string,
27+
SampleData?: StateDataObject | null,
28+
enableConsoleLogs?: boolean
29+
): ParsedResult;
30+
31+
export function convertAstToDevextreme(
32+
ast: any, // Define a more specific type if possible
33+
variables: string[],
34+
state: StateDataObject
35+
): any;

src/core/converter.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ function DevExpressConverter() {
2020
* @param {Object} ast - The abstract syntax tree
2121
* @param {Array} vars - Array of variable names
2222
* @param {Object} ResultObject - Optional object for placeholder resolution
23-
* @param {string} primaryEntity - Optional primary entity name
24-
* @param {string} primaryKey - Optional primary key value
2523
* @returns {Array|null} DevExpress format filter
2624
*/
27-
function convert(ast, vars, ResultObject = null, PrimaryEntity = null, PrimaryKey = null) {
25+
function convert(ast, vars, ResultObject = null) {
2826
// Set up global context
2927
variables = vars;
30-
primaryKey = PrimaryKey;
31-
primaryEntity = PrimaryEntity;
3228
resultObject = ResultObject;
3329

3430
// Process the AST
31+
let result = processAstNode(ast);
32+
33+
// Handle special cases for short circuit
34+
if(result === true || result === false || result === null) return [];
35+
3536
return processAstNode(ast);
3637
}
3738

@@ -191,6 +192,16 @@ function DevExpressConverter() {
191192
}
192193
}
193194

195+
if(Array.isArray(resolvedValue) && resolvedValue.length){
196+
197+
return Array.prototype.concat
198+
.apply(
199+
[],
200+
resolvedValue.map((i) => [[ast.field, '=', i], 'or']),
201+
)
202+
.slice(0, -1)
203+
}
204+
194205
return [ast.field, "in", resolvedValue];
195206
}
196207

@@ -346,6 +357,6 @@ const devExpressConverter = DevExpressConverter();
346357
* @param {string} primaryKey - Optional primary key value
347358
* @returns {Array|null} DevExpress format filter
348359
*/
349-
export function convertToDevExpressFormat({ ast, variables, resultObject = null, primaryEntity = null, primaryKey = null }) {
350-
return devExpressConverter.init(ast, variables, resultObject, primaryEntity, primaryKey);
360+
export function convertToDevExpressFormat({ ast, variables, resultObject = null }) {
361+
return devExpressConverter.init(ast, variables, resultObject);
351362
}

0 commit comments

Comments
 (0)