alasql 4.1.3 → 4.1.4
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 +3 -3
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql-worker.min.js +1 -1
- package/dist/alasql.d.ts +14 -0
- package/dist/alasql.fs.js +63 -41
- package/dist/alasql.js +63 -41
- package/dist/alasql.min.js +2 -2
- package/package.json +19 -22
- package/types/alasql.d.ts +14 -0
- package/test239.json +0 -3
package/dist/alasql.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v4.1.
|
|
1
|
+
//! AlaSQL v4.1.3 build: develop-04e3bf66 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 4.1.
|
|
4
|
+
@version 4.1.3
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2023 Andrey Gershun & Mathias Wulff
|
|
@@ -142,8 +142,8 @@ var alasql = function(sql, params, cb, scope) {
|
|
|
142
142
|
Current version of alasql
|
|
143
143
|
@constant {string}
|
|
144
144
|
*/
|
|
145
|
-
alasql.version = '4.1.
|
|
146
|
-
alasql.build = 'develop-
|
|
145
|
+
alasql.version = '4.1.3';
|
|
146
|
+
alasql.build = 'develop-04e3bf66';
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
149
|
Debug flag
|
|
@@ -3490,7 +3490,7 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
|
|
|
3490
3490
|
});
|
|
3491
3491
|
} else {
|
|
3492
3492
|
if (/^[a-z]+:\/\//i.test(path)) {
|
|
3493
|
-
fetchData(path,
|
|
3493
|
+
fetchData(path, x => success(cutbom(x)), error, asy);
|
|
3494
3494
|
} else {
|
|
3495
3495
|
//If async callthen call async
|
|
3496
3496
|
if (asy) {
|
|
@@ -3553,7 +3553,7 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
|
|
|
3553
3553
|
Simply read file from HTTP request, like:
|
|
3554
3554
|
SELECT * FROM TXT('http://alasql.org/README.md');
|
|
3555
3555
|
*/
|
|
3556
|
-
fetchData(path,
|
|
3556
|
+
fetchData(path, x => success(cutbom(x)), error, asy);
|
|
3557
3557
|
}
|
|
3558
3558
|
} else if (path instanceof Event) {
|
|
3559
3559
|
/*
|
|
@@ -3594,13 +3594,13 @@ async function fetchData(path, success, error, async) {
|
|
|
3594
3594
|
|
|
3595
3595
|
function getData(path, success, error) {
|
|
3596
3596
|
return _fetch(path)
|
|
3597
|
-
.then(
|
|
3598
|
-
.then(
|
|
3597
|
+
.then(response => response.arrayBuffer())
|
|
3598
|
+
.then(buf => {
|
|
3599
3599
|
var a = new Uint8Array(buf);
|
|
3600
|
-
var b = [...a].map(
|
|
3600
|
+
var b = [...a].map(e => String.fromCharCode(e)).join('');
|
|
3601
3601
|
success(b);
|
|
3602
3602
|
})
|
|
3603
|
-
.catch(
|
|
3603
|
+
.catch(e => {
|
|
3604
3604
|
if (error) return error(e);
|
|
3605
3605
|
console.error(e);
|
|
3606
3606
|
throw e;
|
|
@@ -3622,7 +3622,7 @@ var loadBinaryFile = (utils.loadBinaryFile = function (
|
|
|
3622
3622
|
path,
|
|
3623
3623
|
runAsync,
|
|
3624
3624
|
success,
|
|
3625
|
-
error =
|
|
3625
|
+
error = x => {
|
|
3626
3626
|
throw x;
|
|
3627
3627
|
}
|
|
3628
3628
|
) {
|
|
@@ -4866,9 +4866,9 @@ var promiseExec = function (sql, params, counterStep, counterTotal) {
|
|
|
4866
4866
|
|
|
4867
4867
|
const sequentialPromiseResolver = (promiseData, Promise) => {
|
|
4868
4868
|
var startingPoint = Promise.resolve([]);
|
|
4869
|
-
promiseData.forEach(
|
|
4870
|
-
startingPoint = startingPoint.then(
|
|
4871
|
-
promiseExec(p.sql, p.params, p.i, p.length).then(
|
|
4869
|
+
promiseData.forEach(p => {
|
|
4870
|
+
startingPoint = startingPoint.then(previousResult =>
|
|
4871
|
+
promiseExec(p.sql, p.params, p.i, p.length).then(result => [...previousResult, result])
|
|
4872
4872
|
);
|
|
4873
4873
|
});
|
|
4874
4874
|
|
|
@@ -5272,16 +5272,16 @@ yy.Statements = class Statements {
|
|
|
5272
5272
|
}
|
|
5273
5273
|
|
|
5274
5274
|
toString() {
|
|
5275
|
-
return this.statements.map(
|
|
5275
|
+
return this.statements.map(st => st.toString()).join('; ');
|
|
5276
5276
|
}
|
|
5277
5277
|
|
|
5278
5278
|
// Compile array of statements into single statement
|
|
5279
5279
|
compile(db) {
|
|
5280
|
-
const statements = this.statements.map(
|
|
5280
|
+
const statements = this.statements.map(st => st.compile(db));
|
|
5281
5281
|
return statements.length === 1
|
|
5282
5282
|
? statements[0]
|
|
5283
5283
|
: (params, cb) => {
|
|
5284
|
-
const res = statements.map(
|
|
5284
|
+
const res = statements.map(st => st(params));
|
|
5285
5285
|
if (cb) cb(res);
|
|
5286
5286
|
return res;
|
|
5287
5287
|
};
|
|
@@ -5973,7 +5973,7 @@ alasql.srch = {
|
|
|
5973
5973
|
PROP(val, args, stope) {
|
|
5974
5974
|
|
|
5975
5975
|
if (stope.mode === 'XML') {
|
|
5976
|
-
const values = val.children.filter(
|
|
5976
|
+
const values = val.children.filter(v => v.name.toUpperCase() === args[0].toUpperCase());
|
|
5977
5977
|
|
|
5978
5978
|
return {
|
|
5979
5979
|
status: values.length ? 1 : -1,
|
|
@@ -6311,7 +6311,7 @@ alasql.srch = {
|
|
|
6311
6311
|
|
|
6312
6312
|
ROW(val, args, stope, params) {
|
|
6313
6313
|
var s = 'var y;return [';
|
|
6314
|
-
s += args.map(
|
|
6314
|
+
s += args.map(arg => arg.toJS('x', '')).join(',');
|
|
6315
6315
|
s += ']';
|
|
6316
6316
|
var setfn = new Function('x,params,alasql', s);
|
|
6317
6317
|
var rv = setfn(val, params, alasql);
|
|
@@ -8700,7 +8700,7 @@ yy.Select.prototype.compileGroup = function (query) {
|
|
|
8700
8700
|
// if(col instanceof yy.Column) colas = col.columnid;
|
|
8701
8701
|
// else colas = col.toString();
|
|
8702
8702
|
// };
|
|
8703
|
-
let colExpIfFunIdExists =
|
|
8703
|
+
let colExpIfFunIdExists = expression => {
|
|
8704
8704
|
let colexpression = expression.args[0];
|
|
8705
8705
|
return colexpression.toJS('p', tableid, defcols);
|
|
8706
8706
|
};
|
|
@@ -8825,7 +8825,7 @@ yy.Select.prototype.compileGroup = function (query) {
|
|
|
8825
8825
|
var colas = col.nick;
|
|
8826
8826
|
|
|
8827
8827
|
var colexp = col.expression.toJS('p', tableid, defcols);
|
|
8828
|
-
let colExpIfFunIdExists =
|
|
8828
|
+
let colExpIfFunIdExists = expression => {
|
|
8829
8829
|
let colexpression = expression.args[0];
|
|
8830
8830
|
return colexpression.toJS('p', tableid, defcols);
|
|
8831
8831
|
};
|
|
@@ -11665,7 +11665,7 @@ stdlib.UPPER = stdlib.UCASE = function (s) {
|
|
|
11665
11665
|
// Concatination of strings
|
|
11666
11666
|
stdfn.CONCAT_WS = function () {
|
|
11667
11667
|
var args = Array.prototype.slice.call(arguments);
|
|
11668
|
-
args = args.filter(
|
|
11668
|
+
args = args.filter(x => !(x === null || typeof x === 'undefined'));
|
|
11669
11669
|
return args.slice(1, args.length).join(args[0] || '');
|
|
11670
11670
|
};
|
|
11671
11671
|
|
|
@@ -12601,7 +12601,11 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
|
|
|
12601
12601
|
};
|
|
12602
12602
|
}
|
|
12603
12603
|
if (checkfn) {
|
|
12604
|
-
table.checks.push({
|
|
12604
|
+
table.checks.push({
|
|
12605
|
+
fn: checkfn,
|
|
12606
|
+
id: con.constraintid,
|
|
12607
|
+
fk: con.type === 'FOREIGN KEY',
|
|
12608
|
+
});
|
|
12605
12609
|
}
|
|
12606
12610
|
});
|
|
12607
12611
|
|
|
@@ -13991,7 +13995,9 @@ yy.WithSelect.prototype.execute = function (databaseid, params, cb) {
|
|
|
13991
13995
|
var savedTables = [];
|
|
13992
13996
|
self.withs.forEach(function (w) {
|
|
13993
13997
|
savedTables.push(alasql.databases[databaseid].tables[w.name]);
|
|
13994
|
-
var tb = (alasql.databases[databaseid].tables[w.name] = new Table({
|
|
13998
|
+
var tb = (alasql.databases[databaseid].tables[w.name] = new Table({
|
|
13999
|
+
tableid: w.name,
|
|
14000
|
+
}));
|
|
13995
14001
|
tb.data = w.select.execute(databaseid, params);
|
|
13996
14002
|
});
|
|
13997
14003
|
|
|
@@ -15240,7 +15246,11 @@ yy.ShowColumns.prototype.execute = function (databaseid, params, cb) {
|
|
|
15240
15246
|
|
|
15241
15247
|
if (table && table.columns) {
|
|
15242
15248
|
var res = table.columns.map(function (col) {
|
|
15243
|
-
return {
|
|
15249
|
+
return {
|
|
15250
|
+
columnid: col.columnid,
|
|
15251
|
+
dbtypeid: col.dbtypeid,
|
|
15252
|
+
dbsize: col.dbsize,
|
|
15253
|
+
};
|
|
15244
15254
|
});
|
|
15245
15255
|
if (cb) cb(res);
|
|
15246
15256
|
return res;
|
|
@@ -16898,7 +16908,9 @@ alasql.into.XLSX = function (filename, opts, data, columns, cb) {
|
|
|
16898
16908
|
|
|
16899
16909
|
if (opt.headers) {
|
|
16900
16910
|
columns.forEach(function (col, idx) {
|
|
16901
|
-
cells[alasql.utils.xlsnc(col0 + idx) + '' + i] = {
|
|
16911
|
+
cells[alasql.utils.xlsnc(col0 + idx) + '' + i] = {
|
|
16912
|
+
v: col.columnid.trim(),
|
|
16913
|
+
};
|
|
16902
16914
|
});
|
|
16903
16915
|
i++;
|
|
16904
16916
|
}
|
|
@@ -17331,9 +17343,17 @@ function XLSXLSX(X, filename, opts, cb, idx, query) {
|
|
|
17331
17343
|
// function processData(data) {
|
|
17332
17344
|
if (data instanceof ArrayBuffer) {
|
|
17333
17345
|
var arr = fixdata(data);
|
|
17334
|
-
var workbook = X.read(btoa(arr), {
|
|
17346
|
+
var workbook = X.read(btoa(arr), {
|
|
17347
|
+
type: 'base64',
|
|
17348
|
+
...alasql.options.excel,
|
|
17349
|
+
...opts,
|
|
17350
|
+
});
|
|
17335
17351
|
} else {
|
|
17336
|
-
var workbook = X.read(data, {
|
|
17352
|
+
var workbook = X.read(data, {
|
|
17353
|
+
type: 'binary',
|
|
17354
|
+
...alasql.options.excel,
|
|
17355
|
+
...opts,
|
|
17356
|
+
});
|
|
17337
17357
|
}
|
|
17338
17358
|
|
|
17339
17359
|
var sheetid;
|
|
@@ -17851,7 +17871,7 @@ async function _databaseExists(name) {
|
|
|
17851
17871
|
|
|
17852
17872
|
if (indexedDB.databases) {
|
|
17853
17873
|
const dbs = await indexedDB.databases();
|
|
17854
|
-
const db = dbs.find(
|
|
17874
|
+
const db = dbs.find(db => db.name === name);
|
|
17855
17875
|
// @ts-ignore
|
|
17856
17876
|
return db || 0;
|
|
17857
17877
|
}
|
|
@@ -17865,7 +17885,7 @@ async function _databaseExists(name) {
|
|
|
17865
17885
|
resolve({name, version: req.result.version});
|
|
17866
17886
|
};
|
|
17867
17887
|
|
|
17868
|
-
req.onupgradeneeded =
|
|
17888
|
+
req.onupgradeneeded = evt => {
|
|
17869
17889
|
evt.target.transaction.abort();
|
|
17870
17890
|
resolve(0);
|
|
17871
17891
|
};
|
|
@@ -17890,7 +17910,7 @@ IDB.showDatabases = function (like, cb) {
|
|
|
17890
17910
|
return;
|
|
17891
17911
|
}
|
|
17892
17912
|
|
|
17893
|
-
indexedDB.databases().then(
|
|
17913
|
+
indexedDB.databases().then(dblist => {
|
|
17894
17914
|
const res = [];
|
|
17895
17915
|
const relike = like && new RegExp(like.value.replace(/\%/g, '.*'), 'g');
|
|
17896
17916
|
|
|
@@ -17905,7 +17925,7 @@ IDB.showDatabases = function (like, cb) {
|
|
|
17905
17925
|
};
|
|
17906
17926
|
|
|
17907
17927
|
IDB.createDatabase = async function (ixdbid, args, ifnotexists, dbid, cb) {
|
|
17908
|
-
const found = await _databaseExists(ixdbid).catch(
|
|
17928
|
+
const found = await _databaseExists(ixdbid).catch(err => {
|
|
17909
17929
|
if (cb) cb(null, err);
|
|
17910
17930
|
throw err;
|
|
17911
17931
|
});
|
|
@@ -17929,7 +17949,7 @@ IDB.createDatabase = async function (ixdbid, args, ifnotexists, dbid, cb) {
|
|
|
17929
17949
|
};
|
|
17930
17950
|
|
|
17931
17951
|
IDB.dropDatabase = async function (ixdbid, ifexists, cb) {
|
|
17932
|
-
const found = await _databaseExists(ixdbid).catch(
|
|
17952
|
+
const found = await _databaseExists(ixdbid).catch(err => {
|
|
17933
17953
|
if (cb) cb(null, err);
|
|
17934
17954
|
throw err;
|
|
17935
17955
|
});
|
|
@@ -17953,7 +17973,7 @@ IDB.dropDatabase = async function (ixdbid, ifexists, cb) {
|
|
|
17953
17973
|
};
|
|
17954
17974
|
|
|
17955
17975
|
IDB.attachDatabase = async function (ixdbid, dbid, args, params, cb) {
|
|
17956
|
-
const found = await _databaseExists(ixdbid).catch(
|
|
17976
|
+
const found = await _databaseExists(ixdbid).catch(err => {
|
|
17957
17977
|
if (cb) cb(null, err);
|
|
17958
17978
|
throw err;
|
|
17959
17979
|
});
|
|
@@ -17988,7 +18008,7 @@ IDB.attachDatabase = async function (ixdbid, dbid, args, params, cb) {
|
|
|
17988
18008
|
|
|
17989
18009
|
IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
|
|
17990
18010
|
const ixdbid = alasql.databases[databaseid].ixdbid;
|
|
17991
|
-
const found = await _databaseExists(ixdbid).catch(
|
|
18011
|
+
const found = await _databaseExists(ixdbid).catch(err => {
|
|
17992
18012
|
if (cb) cb(null, err);
|
|
17993
18013
|
throw err;
|
|
17994
18014
|
});
|
|
@@ -18009,7 +18029,7 @@ IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
|
|
|
18009
18029
|
request.result.close();
|
|
18010
18030
|
if (cb) cb(1);
|
|
18011
18031
|
};
|
|
18012
|
-
request.onerror =
|
|
18032
|
+
request.onerror = evt => {
|
|
18013
18033
|
cb(null, evt);
|
|
18014
18034
|
};
|
|
18015
18035
|
request.onblocked = function (event) {
|
|
@@ -18022,7 +18042,7 @@ IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
|
|
|
18022
18042
|
|
|
18023
18043
|
IDB.dropTable = async function (databaseid, tableid, ifexists, cb) {
|
|
18024
18044
|
const ixdbid = alasql.databases[databaseid].ixdbid;
|
|
18025
|
-
const found = await _databaseExists(ixdbid).catch(
|
|
18045
|
+
const found = await _databaseExists(ixdbid).catch(err => {
|
|
18026
18046
|
if (cb) cb(null, err);
|
|
18027
18047
|
throw err;
|
|
18028
18048
|
});
|
|
@@ -18071,7 +18091,7 @@ IDB.intoTable = function (databaseid, tableid, value, columns, cb) {
|
|
|
18071
18091
|
var db = alasql.databases[databaseid];
|
|
18072
18092
|
var table = db.tables[tableid];
|
|
18073
18093
|
|
|
18074
|
-
request.onupgradeneeded =
|
|
18094
|
+
request.onupgradeneeded = evt => {
|
|
18075
18095
|
evt.target.transaction.abort();
|
|
18076
18096
|
const err = new Error(
|
|
18077
18097
|
`Cannot insert into table "${tableid}" because database "${databaseid}" does not exist`
|
|
@@ -18107,7 +18127,7 @@ IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
|
|
|
18107
18127
|
const ixdbid = alasql.databases[databaseid].ixdbid;
|
|
18108
18128
|
const request = indexedDB.open(ixdbid);
|
|
18109
18129
|
|
|
18110
|
-
request.onupgradeneeded =
|
|
18130
|
+
request.onupgradeneeded = evt => {
|
|
18111
18131
|
evt.target.transaction.abort();
|
|
18112
18132
|
const err = new Error(
|
|
18113
18133
|
`Cannot select from table "${tableid}" because database "${databaseid}" does not exist`
|
|
@@ -18124,7 +18144,7 @@ IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
|
|
|
18124
18144
|
const cursor = cur.result;
|
|
18125
18145
|
if (cursor) {
|
|
18126
18146
|
// if keyPath(columns) is not present then we take the key and value as object.
|
|
18127
|
-
const cursorValue = typeof cursor === Object ? cursor.value : {
|
|
18147
|
+
const cursorValue = typeof cursor === Object ? cursor.value : {[cursor.key]: cursor.value};
|
|
18128
18148
|
res.push(cursorValue);
|
|
18129
18149
|
cursor.continue();
|
|
18130
18150
|
} else {
|
|
@@ -19163,7 +19183,9 @@ var saveAs =
|
|
|
19163
19183
|
blob.type
|
|
19164
19184
|
)
|
|
19165
19185
|
) {
|
|
19166
|
-
return new Blob([String.fromCharCode(0xfeff), blob], {
|
|
19186
|
+
return new Blob([String.fromCharCode(0xfeff), blob], {
|
|
19187
|
+
type: blob.type,
|
|
19188
|
+
});
|
|
19167
19189
|
}
|
|
19168
19190
|
return blob;
|
|
19169
19191
|
},
|