alasql 2.1.4 → 2.1.5

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/bin/alasql-cli.js CHANGED
@@ -44,6 +44,14 @@ let yargs = require('yargs')
44
44
  .nargs('f', 1)
45
45
  .normalize('f')
46
46
 
47
+ .boolean('ast')
48
+ .describe('ast', 'Print AST instead of result')
49
+ .normalize('ast')
50
+
51
+ /*.boolean('comp')
52
+ .describe('comp', 'Print compiled function instead of result')
53
+ .normalize('comp')*/
54
+
47
55
  .help('h')
48
56
  .alias('h', 'help')
49
57
 
@@ -115,6 +123,26 @@ function execute(sql, params) {
115
123
  }
116
124
  }
117
125
 
126
+ if (argv.ast) {
127
+ try {
128
+ console.log(formatOutput(alasql.parse(sql, params)));
129
+ process.exit(0);
130
+ } catch (e) {
131
+ console.error(e);
132
+ process.exit(1);
133
+ }
134
+ }
135
+
136
+ /*if (argv.comp) {
137
+ try {
138
+ console.log(alasql.compile(sql, params));
139
+ process.exit(0);
140
+ } catch (e) {
141
+ console.error(e);
142
+ process.exit(1);
143
+ }
144
+ }*/
145
+
118
146
  alasql
119
147
  .promise(sql, params)
120
148
  .then(function (res) {
@@ -1,7 +1,7 @@
1
- //! AlaSQL v2.1.3-develop-dc864f6c | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.1.4-develop-5f5b471d | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.1.3-develop-dc864f6c
4
+ @version 2.1.4-develop-5f5b471d
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2016 Andrey Gershun & Mathias Rangel Wulff
@@ -1,2 +1,2 @@
1
- //! AlaSQL v2.1.3-develop-dc864f6c | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.1.4-develop-5f5b471d | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  !function(r,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():r.alasql=e()}(this,function(){function i(r,e,o){"function"==typeof(e=e||[])&&(scope=o,o=e,e=[]),"object"!=typeof e&&(e=[e]);var t=i.lastid++;i.buffer[t]=o,i.webworker.postMessage({id:t,sql:r,params:e})}var a;if(i.options={},i.options.progress=function(){},isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)},i.promise=function(){throw new Error("Please include a Promise/A+ library")},"undefined"!=typeof Promise&&(a=function(r,e,n,s){return new Promise(function(o,t){i(r,e,function(r,e){e?t(e):(n&&s&&!1!==i.options.progress&&i.options.progress(n,s),o(r))})})},i.promise=function(r,e){if("undefined"==typeof Promise)throw new Error("Please include a Promise/A+ library");if("string"==typeof r)return a(r,e);if(!isArray(r)||r.length<1||void 0!==e)throw new Error("Error in .promise parameters");var o=r;if(!(o.length<1)){for(var t,n,s=[],i=0;i<o.length;i++){if("string"==typeof(n=o[i])&&(n=[n]),!isArray(n)||n.length<1||2<n.length)throw new Error("Error in .promise parameter");t=n[0],n=n[1]||void 0,s.push(a(t,n,i,o.length))}return Promise.all(s)}}),i=i||!1)return i.worker=function(){throw new Error("Can find webworker in this enviroment")},"undefined"!=typeof Worker&&(i.worker=function(r,e,o){if(void 0===(r=!0===r?void 0:r))for(var t=document.getElementsByTagName("script"),n=0;n<t.length;n++){if("alasql-worker.js"===t[n].src.substr(-16).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-16)+"alasql.js";break}if("alasql-worker.min.js"===t[n].src.substr(-20).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-20)+"alasql.min.js";break}if("alasql.js"===t[n].src.substr(-9).toLowerCase()){r=t[n].src;break}if("alasql.min.js"===t[n].src.substr(-13).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-13)+"alasql.min.js";break}}if(void 0===r)throw new Error("Path to alasql.js is not specified");var s;!1!==r?(s=(s="importScripts('")+r+"');self.onmessage = function(event) {alasql(event.data.sql,event.data.params, function(data){postMessage({id:event.data.id, data:data});});}",s=new Blob([s],{type:"text/plain"}),i.webworker=new Worker(URL.createObjectURL(s)),i.webworker.onmessage=function(r){var e=r.data.id;i.buffer[e](r.data.data),delete i.buffer[e]},i.webworker.onerror=function(r){throw r},1<arguments.length&&i("REQUIRE "+e.map(function(r){return'"'+r+'"'}).join(","),[],o)):!1===r&&delete i.webworker}),i.lastid=0,i.buffer={},i.worker(),i;throw new Error("alasql was not found")});
package/dist/alasql.fs.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v2.1.3-develop-dc864f6c | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.1.4-develop-5f5b471d | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.1.3-develop-dc864f6c
4
+ @version 2.1.4-develop-5f5b471d
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.3-develop-dc864f6c';
145
+ alasql.version = '2.1.4-develop-5f5b471d';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -4551,6 +4551,10 @@ alasql.options.excel = {cellDates: true};
4551
4551
 
4552
4552
  alasql.options.joinstar = 'overwrite'; // Option for SELECT * FROM a,b
4553
4553
 
4554
+ alasql.options.loopbreak = 100000;
4555
+
4556
+ alasql.options;
4557
+
4554
4558
  //alasql.options.worker = false;
4555
4559
 
4556
4560
  // Variables
@@ -5697,7 +5701,7 @@ function doSearch(databaseid, params, cb) {
5697
5701
  // throw new Error('Selector "'+sel.srchid+'" not found');
5698
5702
  // };
5699
5703
 
5700
- var SECURITY_BREAK = 100000;
5704
+ var INFINITE_LOOP_BREAK = alasql.options.loopbreak || 100000;
5701
5705
 
5702
5706
  if (sel.selid) {
5703
5707
  // TODO Process Selector
@@ -5928,8 +5932,8 @@ function doSearch(databaseid, params, cb) {
5928
5932
  }
5929
5933
  // Security brake
5930
5934
  i++;
5931
- if (i > SECURITY_BREAK) {
5932
- throw new Error('Security brake. Number of iterations = ' + i);
5935
+ if (i > INFINITE_LOOP_BREAK) {
5936
+ throw new Error('Infinite loop brake. Number of iterations = ' + i);
5933
5937
  }
5934
5938
  }
5935
5939
  }
@@ -6109,8 +6113,8 @@ function doSearch(databaseid, params, cb) {
6109
6113
 
6110
6114
  // Security brake
6111
6115
  i++;
6112
- if (i > SECURITY_BREAK) {
6113
- throw new Error('Security brake. Number of iterations = ' + i);
6116
+ if (i > INFINITE_LOOP_BREAK) {
6117
+ throw new Error('Infinite loop brake. Number of iterations = ' + i);
6114
6118
  }
6115
6119
  }
6116
6120
  return retval;
@@ -6144,8 +6148,8 @@ function doSearch(databaseid, params, cb) {
6144
6148
 
6145
6149
  // Security brake
6146
6150
  i++;
6147
- if (i > SECURITY_BREAK) {
6148
- throw new Error('Loop brake. Number of iterations = ' + i);
6151
+ if (i > INFINITE_LOOP_BREAK) {
6152
+ throw new Error('Infinite loop brake. Number of iterations = ' + i);
6149
6153
  }
6150
6154
  }
6151
6155
 
@@ -11498,7 +11502,7 @@ yy.AggrValue.prototype.toType = function () {
11498
11502
  return this.expression.toType();
11499
11503
  }
11500
11504
 
11501
- // todo: implement default;
11505
+ return this.expression.toType();
11502
11506
  };
11503
11507
 
11504
11508
  yy.AggrValue.prototype.toJS = function (/*context, tableid, defcols*/) {
@@ -11949,42 +11953,39 @@ alasql.aggr.GROUP_CONCAT = function (v, s, stage) {
11949
11953
  return s;
11950
11954
  };
11951
11955
 
11952
- alasql.aggr.MEDIAN = function (v, s, stage) {
11956
+ alasql.aggr.median = alasql.aggr.MEDIAN = function (v, s, stage) {
11953
11957
  if (stage === 2) {
11954
11958
  if (v !== null) {
11955
11959
  s.push(v);
11956
11960
  }
11957
11961
  return s;
11958
- } else if (stage === 1) {
11962
+ }
11963
+
11964
+ if (stage === 1) {
11959
11965
  if (v === null) {
11960
11966
  return [];
11961
11967
  }
11962
11968
  return [v];
11963
- } else {
11964
- if (!s.length) {
11965
- return s;
11966
- }
11969
+ }
11967
11970
 
11968
- var r = s.sort(function (a, b) {
11969
- if (a === b) {
11970
- return 0;
11971
- }
11972
- if (a > b) {
11973
- return 1;
11974
- }
11975
- return -1;
11976
- });
11977
- var p = (r.length + 1) / 2;
11978
- if (Number.isInteger(p)) {
11979
- return r[p - 1];
11980
- }
11971
+ if (!s.length) {
11972
+ return null;
11973
+ }
11981
11974
 
11982
- var value = r[Math.floor(p - 1)];
11983
- if (typeof value !== 'number' && !(value instanceof Number)) {
11984
- return value;
11985
- }
11975
+ var r = s.sort((a, b) => {
11976
+ if (a > b) return 1;
11977
+ if (a < b) return -1;
11978
+ return 0;
11979
+ });
11980
+
11981
+ var middle = (r.length + 1) / 2;
11982
+ var middleFloor = middle | 0;
11983
+ var el = r[middleFloor - 1];
11986
11984
 
11987
- return (value + r[Math.ceil(p - 1)]) / 2;
11985
+ if (middle === middleFloor || (typeof el !== 'number' && !(el instanceof Number))) {
11986
+ return el;
11987
+ } else {
11988
+ return (el + r[middleFloor]) / 2;
11988
11989
  }
11989
11990
  };
11990
11991
 
package/dist/alasql.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v2.1.3-develop-dc864f6c | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.1.4-develop-5f5b471d | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.1.3-develop-dc864f6c
4
+ @version 2.1.4-develop-5f5b471d
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.3-develop-dc864f6c';
145
+ alasql.version = '2.1.4-develop-5f5b471d';
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 SECURITY_BREAK = 100000;
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 > SECURITY_BREAK) {
5926
- throw new Error('Security brake. Number of iterations = ' + i);
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 > SECURITY_BREAK) {
6107
- throw new Error('Security brake. Number of iterations = ' + i);
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 > SECURITY_BREAK) {
6142
- throw new Error('Loop brake. Number of iterations = ' + i);
6145
+ if (i > INFINITE_LOOP_BREAK) {
6146
+ throw new Error('Infinite loop brake. Number of iterations = ' + i);
6143
6147
  }
6144
6148
  }
6145
6149
 
@@ -11492,7 +11496,7 @@ yy.AggrValue.prototype.toType = function () {
11492
11496
  return this.expression.toType();
11493
11497
  }
11494
11498
 
11495
- // todo: implement default;
11499
+ return this.expression.toType();
11496
11500
  };
11497
11501
 
11498
11502
  yy.AggrValue.prototype.toJS = function (/*context, tableid, defcols*/) {
@@ -11943,42 +11947,39 @@ alasql.aggr.GROUP_CONCAT = function (v, s, stage) {
11943
11947
  return s;
11944
11948
  };
11945
11949
 
11946
- alasql.aggr.MEDIAN = function (v, s, stage) {
11950
+ alasql.aggr.median = alasql.aggr.MEDIAN = function (v, s, stage) {
11947
11951
  if (stage === 2) {
11948
11952
  if (v !== null) {
11949
11953
  s.push(v);
11950
11954
  }
11951
11955
  return s;
11952
- } else if (stage === 1) {
11956
+ }
11957
+
11958
+ if (stage === 1) {
11953
11959
  if (v === null) {
11954
11960
  return [];
11955
11961
  }
11956
11962
  return [v];
11957
- } else {
11958
- if (!s.length) {
11959
- return s;
11960
- }
11963
+ }
11961
11964
 
11962
- var r = s.sort(function (a, b) {
11963
- if (a === b) {
11964
- return 0;
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
- }
11965
+ if (!s.length) {
11966
+ return null;
11967
+ }
11975
11968
 
11976
- var value = r[Math.floor(p - 1)];
11977
- if (typeof value !== 'number' && !(value instanceof Number)) {
11978
- return value;
11979
- }
11969
+ var r = s.sort((a, b) => {
11970
+ if (a > b) return 1;
11971
+ if (a < b) return -1;
11972
+ return 0;
11973
+ });
11974
+
11975
+ var middle = (r.length + 1) / 2;
11976
+ var middleFloor = middle | 0;
11977
+ var el = r[middleFloor - 1];
11980
11978
 
11981
- return (value + r[Math.ceil(p - 1)]) / 2;
11979
+ if (middle === middleFloor || (typeof el !== 'number' && !(el instanceof Number))) {
11980
+ return el;
11981
+ } else {
11982
+ return (el + r[middleFloor]) / 2;
11982
11983
  }
11983
11984
  };
11984
11985