alasql 4.9.0 → 4.10.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/README.md +5 -1
- package/build.sh +9 -0
- package/dist/alasql-worker.js +4 -4
- package/dist/alasql.fs.js +1170 -859
- package/dist/alasql.js +1170 -859
- package/dist/alasql.min.js +143 -143
- package/dist/precompile/index.js +115 -0
- package/package.json +12 -3
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var index_exports = {};
|
|
29
|
+
__export(index_exports, {
|
|
30
|
+
compileToJS: () => compileToJS
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
var import_alasql_fs = __toESM(require("../../dist/alasql.fs.js"));
|
|
34
|
+
function compileToJS(sql, databaseid) {
|
|
35
|
+
const compiledFn = import_alasql_fs.default.compile(sql, databaseid);
|
|
36
|
+
const query = compiledFn.query;
|
|
37
|
+
const selectfnStr = query.selectfn ? query.selectfn.toString() : "null";
|
|
38
|
+
const wherefnStr = query.wherefn ? query.wherefn.toString() : "null";
|
|
39
|
+
const orderfnStr = query.orderfn ? query.orderfn.toString() : "null";
|
|
40
|
+
const sources = query.sources || [];
|
|
41
|
+
const firstSource = sources[0] || {};
|
|
42
|
+
const alias = firstSource.alias ? JSON.stringify(firstSource.alias) : '"default"';
|
|
43
|
+
const tableid = firstSource.tableid ? JSON.stringify(firstSource.tableid) : "null";
|
|
44
|
+
const srcDatabaseid = firstSource.databaseid ? JSON.stringify(firstSource.databaseid) : JSON.stringify(databaseid || "alasql");
|
|
45
|
+
const wrapper = `(function(params, cb, scope) {
|
|
46
|
+
const alasql = this;
|
|
47
|
+
const selectfn = ${selectfnStr};
|
|
48
|
+
const wherefn = ${wherefnStr};
|
|
49
|
+
const orderfn = ${orderfnStr};
|
|
50
|
+
const removeKeys = ${JSON.stringify(query.removeKeys || [])};
|
|
51
|
+
const distinct = ${JSON.stringify(query.distinct)};
|
|
52
|
+
const limit = ${JSON.stringify(query.limit)};
|
|
53
|
+
const offset = ${JSON.stringify(query.offset)};
|
|
54
|
+
const alias = ${alias};
|
|
55
|
+
|
|
56
|
+
// Get data from source (either params or database table)
|
|
57
|
+
let data;
|
|
58
|
+
if (${tableid}) {
|
|
59
|
+
// Query from database table
|
|
60
|
+
const db = alasql.databases[${srcDatabaseid}];
|
|
61
|
+
data = db.tables[${tableid}].data;
|
|
62
|
+
} else if (params && params[0]) {
|
|
63
|
+
// Query from parameter
|
|
64
|
+
data = params[0];
|
|
65
|
+
} else {
|
|
66
|
+
data = [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Execute query
|
|
70
|
+
let result = [];
|
|
71
|
+
for (let i = 0; i < data.length; i++) {
|
|
72
|
+
const p = {};
|
|
73
|
+
p[alias] = data[i];
|
|
74
|
+
if (!wherefn || wherefn(p, params, alasql)) {
|
|
75
|
+
const row = selectfn ? selectfn(p, params, alasql) : data[i];
|
|
76
|
+
result.push(row);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Apply ORDER BY (before removing keys)
|
|
81
|
+
if (orderfn) {
|
|
82
|
+
result.sort(orderfn);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Remove temporary keys
|
|
86
|
+
if (removeKeys && removeKeys.length > 0) {
|
|
87
|
+
result.forEach(row => {
|
|
88
|
+
removeKeys.forEach(key => delete row[key]);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Apply DISTINCT
|
|
93
|
+
if (distinct) {
|
|
94
|
+
const seen = new Set();
|
|
95
|
+
result = result.filter(row => {
|
|
96
|
+
const key = JSON.stringify(row);
|
|
97
|
+
if (seen.has(key)) return false;
|
|
98
|
+
seen.add(key);
|
|
99
|
+
return true;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Apply OFFSET and LIMIT
|
|
104
|
+
if (offset) {
|
|
105
|
+
result = result.slice(offset);
|
|
106
|
+
}
|
|
107
|
+
if (limit) {
|
|
108
|
+
result = result.slice(0, limit);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (cb) cb(result);
|
|
112
|
+
return result;
|
|
113
|
+
})`;
|
|
114
|
+
return wrapper;
|
|
115
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
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.10.0",
|
|
5
5
|
"author": "Andrey Gershun <agershun@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Mathias Wulff <m@rawu.dk>"
|
|
8
8
|
],
|
|
9
9
|
"main": "dist/alasql.fs.js",
|
|
10
10
|
"browser": "dist/alasql.min.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"node": "./dist/alasql.fs.js",
|
|
14
|
+
"browser": "./dist/alasql.min.js",
|
|
15
|
+
"default": "./dist/alasql.fs.js"
|
|
16
|
+
},
|
|
17
|
+
"./precompile": "./dist/precompile/index.js"
|
|
18
|
+
},
|
|
11
19
|
"directories": {
|
|
12
20
|
"test": "test"
|
|
13
21
|
},
|
|
@@ -59,7 +67,7 @@
|
|
|
59
67
|
"jison": "^0.4.18",
|
|
60
68
|
"mocha": "11.7.5",
|
|
61
69
|
"mocha.parallel": "0.15.6",
|
|
62
|
-
"open": "
|
|
70
|
+
"open": "11.0.0",
|
|
63
71
|
"prettier": "3.6.2",
|
|
64
72
|
"react-native-fetch-blob": "^0.10.8",
|
|
65
73
|
"react-native-fs": "^2.20.0",
|
|
@@ -76,7 +84,8 @@
|
|
|
76
84
|
"glob-parent": "6",
|
|
77
85
|
"decode-uri-component": "0.4",
|
|
78
86
|
"semver": "7",
|
|
79
|
-
"follow-redirects": "1"
|
|
87
|
+
"follow-redirects": "1",
|
|
88
|
+
"js-yaml": "4"
|
|
80
89
|
},
|
|
81
90
|
"engines": {
|
|
82
91
|
"node": ">=15"
|