alasql 2.1.4 → 2.1.6
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 +1 -1
- package/bin/alasql-cli.js +28 -0
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql-worker.min.js +1 -1
- package/dist/alasql.fs.js +64 -99
- package/dist/alasql.js +64 -99
- package/dist/alasql.min.js +14 -2
- package/package.json +3 -3
package/dist/alasql.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.1.
|
|
1
|
+
//! AlaSQL v2.1.5-develop-eec33e2f | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.1.
|
|
4
|
+
@version 2.1.5-develop-eec33e2f
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -142,7 +142,7 @@ var alasql = function(sql, params, cb, scope) {
|
|
|
142
142
|
Current version of alasql
|
|
143
143
|
@constant {string}
|
|
144
144
|
*/
|
|
145
|
-
alasql.version = '2.1.
|
|
145
|
+
alasql.version = '2.1.5-develop-eec33e2f';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
Debug flag
|
|
@@ -4545,6 +4545,10 @@ alasql.options.excel = {cellDates: true};
|
|
|
4545
4545
|
|
|
4546
4546
|
alasql.options.joinstar = 'overwrite'; // Option for SELECT * FROM a,b
|
|
4547
4547
|
|
|
4548
|
+
alasql.options.loopbreak = 100000;
|
|
4549
|
+
|
|
4550
|
+
alasql.options;
|
|
4551
|
+
|
|
4548
4552
|
//alasql.options.worker = false;
|
|
4549
4553
|
|
|
4550
4554
|
// Variables
|
|
@@ -5691,7 +5695,7 @@ function doSearch(databaseid, params, cb) {
|
|
|
5691
5695
|
// throw new Error('Selector "'+sel.srchid+'" not found');
|
|
5692
5696
|
// };
|
|
5693
5697
|
|
|
5694
|
-
var
|
|
5698
|
+
var INFINITE_LOOP_BREAK = alasql.options.loopbreak || 100000;
|
|
5695
5699
|
|
|
5696
5700
|
if (sel.selid) {
|
|
5697
5701
|
// TODO Process Selector
|
|
@@ -5922,8 +5926,8 @@ function doSearch(databaseid, params, cb) {
|
|
|
5922
5926
|
}
|
|
5923
5927
|
// Security brake
|
|
5924
5928
|
i++;
|
|
5925
|
-
if (i >
|
|
5926
|
-
throw new Error('
|
|
5929
|
+
if (i > INFINITE_LOOP_BREAK) {
|
|
5930
|
+
throw new Error('Infinite loop brake. Number of iterations = ' + i);
|
|
5927
5931
|
}
|
|
5928
5932
|
}
|
|
5929
5933
|
}
|
|
@@ -6103,8 +6107,8 @@ function doSearch(databaseid, params, cb) {
|
|
|
6103
6107
|
|
|
6104
6108
|
// Security brake
|
|
6105
6109
|
i++;
|
|
6106
|
-
if (i >
|
|
6107
|
-
throw new Error('
|
|
6110
|
+
if (i > INFINITE_LOOP_BREAK) {
|
|
6111
|
+
throw new Error('Infinite loop brake. Number of iterations = ' + i);
|
|
6108
6112
|
}
|
|
6109
6113
|
}
|
|
6110
6114
|
return retval;
|
|
@@ -6138,8 +6142,8 @@ function doSearch(databaseid, params, cb) {
|
|
|
6138
6142
|
|
|
6139
6143
|
// Security brake
|
|
6140
6144
|
i++;
|
|
6141
|
-
if (i >
|
|
6142
|
-
throw new Error('
|
|
6145
|
+
if (i > INFINITE_LOOP_BREAK) {
|
|
6146
|
+
throw new Error('Infinite loop brake. Number of iterations = ' + i);
|
|
6143
6147
|
}
|
|
6144
6148
|
}
|
|
6145
6149
|
|
|
@@ -10498,8 +10502,8 @@ yy.Over.prototype.toString = function () {
|
|
|
10498
10502
|
*/
|
|
10499
10503
|
|
|
10500
10504
|
/**
|
|
10501
|
-
|
|
10502
|
-
|
|
10505
|
+
Expression statement ( = 2*2; )
|
|
10506
|
+
@class
|
|
10503
10507
|
@param {object} params Initial parameters
|
|
10504
10508
|
*/
|
|
10505
10509
|
yy.ExpressionStatement = function (params) {
|
|
@@ -10623,8 +10627,7 @@ yy.JavaScript.prototype.toString = function () {
|
|
|
10623
10627
|
return s;
|
|
10624
10628
|
};
|
|
10625
10629
|
|
|
10626
|
-
yy.JavaScript.prototype.toJS = function (
|
|
10627
|
-
|
|
10630
|
+
yy.JavaScript.prototype.toJS = function () {
|
|
10628
10631
|
return '(' + this.value + ')';
|
|
10629
10632
|
};
|
|
10630
10633
|
yy.JavaScript.prototype.execute = function (databaseid, params, cb) {
|
|
@@ -10673,8 +10676,6 @@ yy.Join.prototype.toString = function () {
|
|
|
10673
10676
|
return s;
|
|
10674
10677
|
};
|
|
10675
10678
|
|
|
10676
|
-
// }
|
|
10677
|
-
|
|
10678
10679
|
/**
|
|
10679
10680
|
Table class
|
|
10680
10681
|
@class
|
|
@@ -10752,6 +10753,7 @@ yy.Op.prototype.toString = function () {
|
|
|
10752
10753
|
|
|
10753
10754
|
return s;
|
|
10754
10755
|
}
|
|
10756
|
+
|
|
10755
10757
|
return (
|
|
10756
10758
|
this.left.toString() +
|
|
10757
10759
|
' ' +
|
|
@@ -10763,7 +10765,6 @@ yy.Op.prototype.toString = function () {
|
|
|
10763
10765
|
};
|
|
10764
10766
|
|
|
10765
10767
|
yy.Op.prototype.findAggregator = function (query) {
|
|
10766
|
-
|
|
10767
10768
|
if (this.left && this.left.findAggregator) {
|
|
10768
10769
|
this.left.findAggregator(query);
|
|
10769
10770
|
}
|
|
@@ -10895,17 +10896,28 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10895
10896
|
}
|
|
10896
10897
|
|
|
10897
10898
|
if (this.op === 'IS') {
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10899
|
+
const leftOperand = leftJS();
|
|
10900
|
+
const rightOperand = rightJS();
|
|
10901
|
+
if (
|
|
10902
|
+
this.right instanceof yy.NullValue ||
|
|
10903
|
+
(this.right.op === 'NOT' && this.right.right instanceof yy.NullValue)
|
|
10904
|
+
) {
|
|
10905
|
+
s = `(
|
|
10906
|
+
(${leftOperand}==null) // Cant be ===
|
|
10907
|
+
===
|
|
10908
|
+
(${rightOperand}==null) // Cant be ===
|
|
10909
|
+
)`;
|
|
10910
|
+
} else {
|
|
10911
|
+
s = `(
|
|
10912
|
+
(${leftOperand} == ${rightOperand})
|
|
10913
|
+
||
|
|
10914
|
+
(
|
|
10915
|
+
${leftOperand} < 0
|
|
10916
|
+
&&
|
|
10917
|
+
true == ${rightOperand}
|
|
10918
|
+
)
|
|
10919
|
+
)`;
|
|
10920
|
+
}
|
|
10909
10921
|
}
|
|
10910
10922
|
|
|
10911
10923
|
if (this.op === '==') {
|
|
@@ -10968,7 +10980,6 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10968
10980
|
')' +
|
|
10969
10981
|
')' +
|
|
10970
10982
|
')';
|
|
10971
|
-
|
|
10972
10983
|
}
|
|
10973
10984
|
|
|
10974
10985
|
if (this.op === 'IN') {
|
|
@@ -11004,13 +11015,10 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11004
11015
|
if (this.op === 'NOT IN') {
|
|
11005
11016
|
if (this.right instanceof yy.Select) {
|
|
11006
11017
|
s = '(';
|
|
11007
|
-
//this.query.queriesdata['+this.queriesidx+']
|
|
11008
|
-
// s += 'alasql.utils.flatArray(this.query.queriesfn['+(this.queriesidx)+'](params,null,p))';
|
|
11009
11018
|
s += 'alasql.utils.flatArray(this.queriesfn[' + this.queriesidx + '](params,null,p))';
|
|
11010
11019
|
s += '.indexOf(';
|
|
11011
11020
|
s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
|
|
11012
11021
|
} else if (Array.isArray(this.right)) {
|
|
11013
|
-
// if(this.right.length == 0) return 'true';
|
|
11014
11022
|
s = '([' + this.right.map(ref).join(',') + '].indexOf(';
|
|
11015
11023
|
s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
|
|
11016
11024
|
} else {
|
|
@@ -11024,7 +11032,6 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11024
11032
|
if (this.allsome === 'ALL') {
|
|
11025
11033
|
var s;
|
|
11026
11034
|
if (this.right instanceof yy.Select) {
|
|
11027
|
-
// var s = 'this.query.queriesdata['+this.queriesidx+']';
|
|
11028
11035
|
s = 'alasql.utils.flatArray(this.query.queriesfn[' + this.queriesidx + '](params,null,p))';
|
|
11029
11036
|
|
|
11030
11037
|
s += '.every(function(b){return (';
|
|
@@ -11043,7 +11050,6 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11043
11050
|
if (this.allsome === 'SOME' || this.allsome === 'ANY') {
|
|
11044
11051
|
var s;
|
|
11045
11052
|
if (this.right instanceof yy.Select) {
|
|
11046
|
-
// var s = 'this.query.queriesdata['+this.queriesidx+']';
|
|
11047
11053
|
s = 'alasql.utils.flatArray(this.query.queriesfn[' + this.queriesidx + '](params,null,p))';
|
|
11048
11054
|
s += '.some(function(b){return (';
|
|
11049
11055
|
s += leftJS() + ')' + op + 'b})';
|
|
@@ -11082,12 +11088,9 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11082
11088
|
// // + ')';
|
|
11083
11089
|
// }
|
|
11084
11090
|
|
|
11085
|
-
// Change names
|
|
11086
|
-
|
|
11087
11091
|
var expr = s || '(' + leftJS() + op + rightJS() + ')';
|
|
11088
11092
|
|
|
11089
11093
|
var declareRefs = 'y=[(' + refs.join('), (') + ')]';
|
|
11090
|
-
|
|
11091
11094
|
if (op === '&&' || op === '||' || op === 'IS' || op === 'IS NULL' || op === 'IS NOT NULL') {
|
|
11092
11095
|
return '(' + declareRefs + ', ' + expr + ')';
|
|
11093
11096
|
}
|
|
@@ -11139,8 +11142,6 @@ yy.StringValue.prototype.toType = function () {
|
|
|
11139
11142
|
};
|
|
11140
11143
|
|
|
11141
11144
|
yy.StringValue.prototype.toJS = function () {
|
|
11142
|
-
|
|
11143
|
-
// return "'"+doubleqq(this.value)+"'";
|
|
11144
11145
|
return "'" + escapeq(this.value) + "'";
|
|
11145
11146
|
};
|
|
11146
11147
|
|
|
@@ -11173,8 +11174,6 @@ yy.ArrayValue.prototype.toType = function () {
|
|
|
11173
11174
|
};
|
|
11174
11175
|
|
|
11175
11176
|
yy.ArrayValue.prototype.toJS = function (context, tableid, defcols) {
|
|
11176
|
-
|
|
11177
|
-
// return "'"+doubleqq(this.value)+"'";
|
|
11178
11177
|
return (
|
|
11179
11178
|
'[(' +
|
|
11180
11179
|
this.value
|
|
@@ -11322,7 +11321,6 @@ yy.Column = function (params) {
|
|
|
11322
11321
|
yy.Column.prototype.toString = function () {
|
|
11323
11322
|
var s;
|
|
11324
11323
|
if (this.columnid == +this.columnid) {
|
|
11325
|
-
// jshint ignore:line
|
|
11326
11324
|
s = '[' + this.columnid + ']';
|
|
11327
11325
|
} else {
|
|
11328
11326
|
s = this.columnid;
|
|
@@ -11341,7 +11339,6 @@ yy.Column.prototype.toString = function () {
|
|
|
11341
11339
|
};
|
|
11342
11340
|
|
|
11343
11341
|
yy.Column.prototype.toJS = function (context, tableid, defcols) {
|
|
11344
|
-
|
|
11345
11342
|
var s = '';
|
|
11346
11343
|
if (!this.tableid && tableid === '' && !defcols) {
|
|
11347
11344
|
if (this.columnid !== '_') {
|
|
@@ -11355,17 +11352,10 @@ yy.Column.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11355
11352
|
}
|
|
11356
11353
|
} else {
|
|
11357
11354
|
if (context === 'g') {
|
|
11358
|
-
// if(this.columnid == '_') {
|
|
11359
|
-
// } else {
|
|
11360
11355
|
s = "g['" + this.nick + "']";
|
|
11361
|
-
// }
|
|
11362
11356
|
} else if (this.tableid) {
|
|
11363
11357
|
if (this.columnid !== '_') {
|
|
11364
|
-
// if() {
|
|
11365
|
-
// s = context+'[\''+tableid + '\'][\''+this.tableid+'\'][\''+this.columnid+'\']';
|
|
11366
|
-
// } else {
|
|
11367
11358
|
s = context + "['" + this.tableid + "']['" + this.columnid + "']";
|
|
11368
|
-
// }
|
|
11369
11359
|
} else {
|
|
11370
11360
|
if (context === 'g') {
|
|
11371
11361
|
s = "g['_']";
|
|
@@ -11388,22 +11378,13 @@ yy.Column.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11388
11378
|
|
|
11389
11379
|
} else {
|
|
11390
11380
|
if (this.columnid !== '_') {
|
|
11391
|
-
// if(defcols['.'][this.tableid]) {
|
|
11392
|
-
|
|
11393
|
-
// s = context+'[\''+tableid + '\'][\''+this.tableid + '\'][\''+this.columnid+'\']';
|
|
11394
|
-
// } else {
|
|
11395
11381
|
s = context + "['" + (this.tableid || tableid) + "']['" + this.columnid + "']";
|
|
11396
|
-
// }
|
|
11397
11382
|
} else {
|
|
11398
11383
|
s = context + "['" + (this.tableid || tableid) + "']";
|
|
11399
11384
|
}
|
|
11400
11385
|
}
|
|
11401
11386
|
} else if (tableid === -1) {
|
|
11402
|
-
// if(this.columnid != '') {
|
|
11403
11387
|
s = context + "['" + this.columnid + "']";
|
|
11404
|
-
// } else {
|
|
11405
|
-
// s = context;
|
|
11406
|
-
// }
|
|
11407
11388
|
} else {
|
|
11408
11389
|
if (this.columnid !== '_') {
|
|
11409
11390
|
s = context + "['" + (this.tableid || tableid) + "']['" + this.columnid + "']";
|
|
@@ -11412,9 +11393,6 @@ yy.Column.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11412
11393
|
}
|
|
11413
11394
|
}
|
|
11414
11395
|
}
|
|
11415
|
-
|
|
11416
|
-
// console.trace(new Error());
|
|
11417
|
-
|
|
11418
11396
|
return s;
|
|
11419
11397
|
};
|
|
11420
11398
|
|
|
@@ -11446,16 +11424,8 @@ yy.AggrValue.prototype.toString = function () {
|
|
|
11446
11424
|
};
|
|
11447
11425
|
|
|
11448
11426
|
yy.AggrValue.prototype.findAggregator = function (query) {
|
|
11449
|
-
|
|
11450
|
-
// var colas = this.as || this.toString();
|
|
11451
|
-
|
|
11452
11427
|
var colas = escapeq(this.toString()) + ':' + query.selectGroup.length;
|
|
11453
|
-
|
|
11454
|
-
// if(!query.selectColumns[colas]) {
|
|
11455
|
-
// }
|
|
11456
|
-
|
|
11457
11428
|
var found = false;
|
|
11458
|
-
|
|
11459
11429
|
if (!found) {
|
|
11460
11430
|
if (!this.nick) {
|
|
11461
11431
|
this.nick = colas;
|
|
@@ -11472,8 +11442,6 @@ yy.AggrValue.prototype.findAggregator = function (query) {
|
|
|
11472
11442
|
}
|
|
11473
11443
|
query.selectGroup.push(this);
|
|
11474
11444
|
}
|
|
11475
|
-
|
|
11476
|
-
// this.reduced = true;
|
|
11477
11445
|
return;
|
|
11478
11446
|
};
|
|
11479
11447
|
|
|
@@ -11492,11 +11460,10 @@ yy.AggrValue.prototype.toType = function () {
|
|
|
11492
11460
|
return this.expression.toType();
|
|
11493
11461
|
}
|
|
11494
11462
|
|
|
11495
|
-
|
|
11463
|
+
return this.expression.toType();
|
|
11496
11464
|
};
|
|
11497
11465
|
|
|
11498
|
-
yy.AggrValue.prototype.toJS = function (
|
|
11499
|
-
|
|
11466
|
+
yy.AggrValue.prototype.toJS = function () {
|
|
11500
11467
|
var colas = this.nick;
|
|
11501
11468
|
if (colas === undefined) {
|
|
11502
11469
|
colas = this.toString();
|
|
@@ -11507,6 +11474,7 @@ yy.AggrValue.prototype.toJS = function (/*context, tableid, defcols*/) {
|
|
|
11507
11474
|
yy.OrderExpression = function (params) {
|
|
11508
11475
|
return yy.extend(this, params);
|
|
11509
11476
|
};
|
|
11477
|
+
|
|
11510
11478
|
yy.OrderExpression.prototype.toString = yy.Expression.prototype.toString;
|
|
11511
11479
|
|
|
11512
11480
|
yy.GroupExpression = function (params) {
|
|
@@ -11943,42 +11911,39 @@ alasql.aggr.GROUP_CONCAT = function (v, s, stage) {
|
|
|
11943
11911
|
return s;
|
|
11944
11912
|
};
|
|
11945
11913
|
|
|
11946
|
-
alasql.aggr.MEDIAN = function (v, s, stage) {
|
|
11914
|
+
alasql.aggr.median = alasql.aggr.MEDIAN = function (v, s, stage) {
|
|
11947
11915
|
if (stage === 2) {
|
|
11948
11916
|
if (v !== null) {
|
|
11949
11917
|
s.push(v);
|
|
11950
11918
|
}
|
|
11951
11919
|
return s;
|
|
11952
|
-
}
|
|
11920
|
+
}
|
|
11921
|
+
|
|
11922
|
+
if (stage === 1) {
|
|
11953
11923
|
if (v === null) {
|
|
11954
11924
|
return [];
|
|
11955
11925
|
}
|
|
11956
11926
|
return [v];
|
|
11957
|
-
}
|
|
11958
|
-
if (!s.length) {
|
|
11959
|
-
return s;
|
|
11960
|
-
}
|
|
11927
|
+
}
|
|
11961
11928
|
|
|
11962
|
-
|
|
11963
|
-
|
|
11964
|
-
|
|
11965
|
-
}
|
|
11966
|
-
if (a > b) {
|
|
11967
|
-
return 1;
|
|
11968
|
-
}
|
|
11969
|
-
return -1;
|
|
11970
|
-
});
|
|
11971
|
-
var p = (r.length + 1) / 2;
|
|
11972
|
-
if (Number.isInteger(p)) {
|
|
11973
|
-
return r[p - 1];
|
|
11974
|
-
}
|
|
11929
|
+
if (!s.length) {
|
|
11930
|
+
return null;
|
|
11931
|
+
}
|
|
11975
11932
|
|
|
11976
|
-
|
|
11977
|
-
if (
|
|
11978
|
-
|
|
11979
|
-
|
|
11933
|
+
var r = s.sort((a, b) => {
|
|
11934
|
+
if (a > b) return 1;
|
|
11935
|
+
if (a < b) return -1;
|
|
11936
|
+
return 0;
|
|
11937
|
+
});
|
|
11980
11938
|
|
|
11981
|
-
|
|
11939
|
+
var middle = (r.length + 1) / 2;
|
|
11940
|
+
var middleFloor = middle | 0;
|
|
11941
|
+
var el = r[middleFloor - 1];
|
|
11942
|
+
|
|
11943
|
+
if (middle === middleFloor || (typeof el !== 'number' && !(el instanceof Number))) {
|
|
11944
|
+
return el;
|
|
11945
|
+
} else {
|
|
11946
|
+
return (el + r[middleFloor]) / 2;
|
|
11982
11947
|
}
|
|
11983
11948
|
};
|
|
11984
11949
|
|