alasql 4.18.0 → 4.19.0
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/dist/alasql-worker.js +2 -2
- package/dist/alasql.d.ts +59 -0
- package/dist/alasql.fs.js +394 -227
- package/dist/alasql.js +394 -227
- package/dist/alasql.min.js +56 -56
- package/dist/precompile/index.js +15 -6
- package/package.json +3 -3
- package/types/alasql.d.ts +59 -0
package/dist/precompile/index.js
CHANGED
|
@@ -49,8 +49,11 @@ function compileToJS(sql, databaseid) {
|
|
|
49
49
|
const orderfn = ${orderfnStr};
|
|
50
50
|
const removeKeys = ${JSON.stringify(query.removeKeys || [])};
|
|
51
51
|
const distinct = ${JSON.stringify(query.distinct)};
|
|
52
|
-
const
|
|
53
|
-
const
|
|
52
|
+
const fixedLimit = ${JSON.stringify(query.limit)};
|
|
53
|
+
const fixedOffset = ${JSON.stringify(query.offset)};
|
|
54
|
+
const limitParam = ${JSON.stringify(query.limitParam)};
|
|
55
|
+
const offsetParam = ${JSON.stringify(query.offsetParam)};
|
|
56
|
+
const percent = ${JSON.stringify(query.percent)};
|
|
54
57
|
const alias = ${alias};
|
|
55
58
|
|
|
56
59
|
// Get data from source (either params or database table)
|
|
@@ -67,6 +70,8 @@ function compileToJS(sql, databaseid) {
|
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
// Execute query
|
|
73
|
+
const limit = typeof limitParam !== 'undefined' ? (params ? params[limitParam] : undefined) : fixedLimit;
|
|
74
|
+
const offset = typeof offsetParam !== 'undefined' ? (params ? params[offsetParam] : undefined) : fixedOffset;
|
|
70
75
|
let result = [];
|
|
71
76
|
for (let i = 0; i < data.length; i++) {
|
|
72
77
|
const p = {};
|
|
@@ -101,11 +106,15 @@ function compileToJS(sql, databaseid) {
|
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
// Apply OFFSET and LIMIT
|
|
104
|
-
if (offset) {
|
|
105
|
-
result = result.slice(offset);
|
|
106
|
-
}
|
|
107
109
|
if (limit) {
|
|
108
|
-
|
|
110
|
+
let start = offset | 0 || 0;
|
|
111
|
+
start = start < 0 ? 0 : start;
|
|
112
|
+
const end = percent ? (((result.length * limit) / 100) | 0) + start : (limit | 0) + start;
|
|
113
|
+
result = result.slice(start, end);
|
|
114
|
+
} else if (offset) {
|
|
115
|
+
let start = offset | 0 || 0;
|
|
116
|
+
start = start < 0 ? 0 : start;
|
|
117
|
+
result = result.slice(start);
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
if (cb) cb(result);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alasql",
|
|
3
3
|
"description": "Use SQL to select and filter javascript data - including relational joins and search in nested objects (JSON). Export to and import from Excel and CSV",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.19.0",
|
|
5
5
|
"author": "Andrey Gershun <agershun@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Mathias Wulff <m@rawu.dk>"
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"blueimp-md5": "2.19.0",
|
|
65
65
|
"cmdmix": "2.2.2",
|
|
66
66
|
"dom-storage": "2.1.0",
|
|
67
|
-
"esbuild": "0.28.
|
|
67
|
+
"esbuild": "0.28.2",
|
|
68
68
|
"git-branch-is": "5.0.0",
|
|
69
69
|
"husky": "9.1.7",
|
|
70
70
|
"jison": "^0.4.18",
|
|
71
|
-
"open": "11.0.
|
|
71
|
+
"open": "11.0.1",
|
|
72
72
|
"prettier": "3.8.3",
|
|
73
73
|
"react-native-fetch-blob": "^0.10.8",
|
|
74
74
|
"rexreplace": "7.1.14",
|
package/types/alasql.d.ts
CHANGED
|
@@ -39,8 +39,67 @@ declare module 'alasql' {
|
|
|
39
39
|
<T = unknown>(params?: any, cb?: AlaSQLCallback<T>, scope?: unknown): T;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
type AlaSQLDefaultColumns = {[columnName: string]: string};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Base parsed expression node.
|
|
46
|
+
* Node shapes below are part of the public parser AST surface and follow semver.
|
|
47
|
+
*/
|
|
48
|
+
interface AlaSQLExpression {
|
|
49
|
+
toJS(context: string, tableid: string | number, defcols: AlaSQLDefaultColumns | null): string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface Op extends AlaSQLExpression {
|
|
53
|
+
left: ExpressionNode;
|
|
54
|
+
op: string;
|
|
55
|
+
right?: ExpressionNode;
|
|
56
|
+
right1?: ExpressionNode;
|
|
57
|
+
right2?: ExpressionNode;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface Column extends AlaSQLExpression {
|
|
61
|
+
columnid: string;
|
|
62
|
+
tableid?: string;
|
|
63
|
+
databaseid?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface ParamValue extends AlaSQLExpression {
|
|
67
|
+
param: string | number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface NumValue extends AlaSQLExpression {
|
|
71
|
+
value: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface StringValue extends AlaSQLExpression {
|
|
75
|
+
value: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface LogicValue extends AlaSQLExpression {
|
|
79
|
+
value: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface UniOp extends AlaSQLExpression {
|
|
83
|
+
op: string | null;
|
|
84
|
+
right: ExpressionNode;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type ExpressionNode = Op | Column | ParamValue | NumValue | StringValue | LogicValue | UniOp;
|
|
88
|
+
|
|
89
|
+
interface ExpressionWrapper extends AlaSQLExpression {
|
|
90
|
+
expression: ExpressionNode;
|
|
91
|
+
reduced?: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface Statement {
|
|
95
|
+
compile(databaseid: string): AlaSQLStatement;
|
|
96
|
+
where?: ExpressionWrapper;
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
}
|
|
99
|
+
|
|
42
100
|
// abstract Syntax Tree
|
|
43
101
|
interface AlaSQLAST {
|
|
102
|
+
statements: Statement[];
|
|
44
103
|
compile(databaseid: string): AlaSQLStatement;
|
|
45
104
|
}
|
|
46
105
|
|