alasql 2.2.0 → 2.2.2

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.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v2.1.8-develop-7e87d661 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.2.1-develop-86ee0810 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.1.8-develop-7e87d661
4
+ @version 2.2.1-develop-86ee0810
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.8-develop-7e87d661';
145
+ alasql.version = '2.2.1-develop-86ee0810';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -6585,10 +6585,8 @@ function queryfn3(query) {
6585
6585
  if (query.selectGroup.length > 0) {
6586
6586
 
6587
6587
  query.selectGroup.forEach(function (sg) {
6588
- if (sg.aggregatorid == 'COUNT') {
6588
+ if (sg.aggregatorid == 'COUNT' || sg.aggregatorid == 'SUM') {
6589
6589
  g[sg.nick] = 0;
6590
- } else if (sg.aggregatorid == 'SUM') {
6591
- g[sg.nick] = 'NULL';
6592
6590
  } else {
6593
6591
  g[sg.nick] = undefined;
6594
6592
  }
@@ -8714,9 +8712,9 @@ yy.Select.prototype.compileGroup = function (query) {
8714
8712
  if ('funcid' in col.expression) {
8715
8713
  let colexpression = col.expression.args[0];
8716
8714
  let colexp1 = colexpression.toJS('p', tableid, defcols);
8717
- return "'" + colas + "':(" + colexp1 + ')||null,';
8715
+ return `'${colas}':(${colexp1})|| typeof ${colexp1} == 'number' ? ${colexp1} : null,`;
8718
8716
  }
8719
- return "'" + colas + "':(" + colexp + ')||null,';
8717
+ return `'${colas}':(${colexp})|| typeof ${colexp} == 'number' ? ${colexp} : null,`;
8720
8718
  } else if (
8721
8719
  col.aggregatorid === 'FIRST' ||
8722
8720
  col.aggregatorid === 'LAST'
@@ -8728,76 +8726,20 @@ yy.Select.prototype.compileGroup = function (query) {
8728
8726
  if ('funcid' in col.expression) {
8729
8727
  let colexpression = col.expression.args[0];
8730
8728
  let colexp1 = colexpression.toJS('p', tableid, defcols);
8731
- return (
8732
- "'" +
8733
- colas +
8734
- "': (typeof " +
8735
- colexp1 +
8736
- " == 'number' ? " +
8737
- colexp1 +
8738
- ': typeof ' +
8739
- colexp1 +
8740
- " == 'object' ? typeof Number(" +
8741
- colexp1 +
8742
- ") == 'number' && " +
8743
- colexp1 +
8744
- '!== null? ' +
8745
- colexp1 +
8746
- ' : null : null),'
8747
- );
8729
+ return `'${colas}': (typeof ${colexp1} == 'number' ? ${colexp1} : typeof ${colexp1} == 'object' ?
8730
+ typeof Number(${colexp1}) == 'number' && ${colexp1}!== null? ${colexp1} : null : null),`;
8748
8731
  }
8749
- return (
8750
- "'" +
8751
- colas +
8752
- "': (typeof " +
8753
- colexp +
8754
- " == 'number' ? " +
8755
- colexp +
8756
- ': typeof ' +
8757
- colexp +
8758
- " == 'object' ? typeof Number(" +
8759
- colexp +
8760
- ") == 'number' && " +
8761
- colexp +
8762
- '!== null? ' +
8763
- colexp +
8764
- ' : null : null),'
8765
- );
8732
+ return `'${colas}': (typeof ${colexp} == 'number' ? ${colexp} : typeof ${colexp} == 'object' ?
8733
+ typeof Number(${colexp}) == 'number' && ${colexp}!== null? ${colexp} : null : null),`;
8766
8734
  } else if (col.aggregatorid === 'MAX') {
8767
8735
  if ('funcid' in col.expression) {
8768
8736
  let colexpression = col.expression.args[0];
8769
8737
  let colexp1 = colexpression.toJS('p', tableid, defcols);
8770
- return (
8771
- "'" +
8772
- colas +
8773
- "': (typeof " +
8774
- colexp1 +
8775
- " == 'number' ? " +
8776
- colexp1 +
8777
- ': typeof ' +
8778
- colexp1 +
8779
- " == 'object' ? typeof Number(" +
8780
- colexp1 +
8781
- ") == 'number' ? " +
8782
- colexp1 +
8783
- ' : null : null),'
8784
- );
8738
+ return `'${colas}' : (typeof ${colexp1} == 'number' ? ${colexp1} : typeof ${colexp1} == 'object' ?
8739
+ typeof Number(${colexp1}) == 'number' ? ${colexp1} : null : null),`;
8785
8740
  }
8786
- return (
8787
- "'" +
8788
- colas +
8789
- "': (typeof " +
8790
- colexp +
8791
- " == 'number' ? " +
8792
- colexp +
8793
- ': typeof ' +
8794
- colexp +
8795
- " == 'object' ? typeof Number(" +
8796
- colexp +
8797
- ") == 'number' ? " +
8798
- colexp +
8799
- ' : null : null),'
8800
- );
8741
+ return `'${colas}' : (typeof ${colexp} == 'number' ? ${colexp} : typeof ${colexp} == 'object' ?
8742
+ typeof Number(${colexp}) == 'number' ? ${colexp} : null : null),`;
8801
8743
  } else if (col.aggregatorid === 'ARRAY') {
8802
8744
  return "'" + colas + "':[" + colexp + '],';
8803
8745
  } else if (col.aggregatorid === 'COUNT') {
@@ -8896,121 +8838,27 @@ yy.Select.prototype.compileGroup = function (query) {
8896
8838
  let colexp1 = colexpression.toJS('p', tableid, defcols);
8897
8839
  return (
8898
8840
  pre +
8899
- "if(g['" +
8900
- colas +
8901
- "'] == null && " +
8902
- colexp1 +
8903
- " == null){g['" +
8904
- colas +
8905
- "'] = null} else if(typeof g['" +
8906
- colas +
8907
- "']!== 'object' && typeof g['" +
8908
- colas +
8909
- "'] !== 'number' && typeof " +
8910
- colexp1 +
8911
- "!== 'object' && typeof " +
8912
- colexp1 +
8913
- "!== 'number'){g['" +
8914
- colas +
8915
- "'] = null} else if(typeof g['" +
8916
- colas +
8917
- "'] !== 'object' && typeof g['" +
8918
- colas +
8919
- "'] !== 'number' && typeof " +
8920
- colexp1 +
8921
- " == 'number'){g['" +
8922
- colas +
8923
- "'] = " +
8924
- colexp1 +
8925
- "} else if(typeof g['" +
8926
- colas +
8927
- "'] == 'number' && typeof " +
8928
- colexp1 +
8929
- " !== 'number' && typeof " +
8930
- colexp1 +
8931
- " !== 'object'){g['" +
8932
- colas +
8933
- "'] = g['" +
8934
- colas +
8935
- "']} else if((g['" +
8936
- colas +
8937
- "'] == null || (typeof g['" +
8938
- colas +
8939
- "'] !== 'number' && typeof g['" +
8940
- colas +
8941
- "'] !== 'object')) && (" +
8942
- colexp1 +
8943
- ' == null || (typeof ' +
8944
- colexp1 +
8945
- " !== 'number' && typeof " +
8946
- colexp1 +
8947
- " !== 'object'))){g['" +
8948
- colas +
8949
- "'] = null} else {g['" +
8950
- colas +
8951
- "']+=(" +
8952
- colexp1 +
8953
- '||0);}' +
8841
+ `if(g['${colas}'] == null && ${colexp1} == null){g['${colas}'] = null}
8842
+ else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp1}!== 'object' && typeof ${colexp1}!== 'number'){g['${colas}'] = null}
8843
+ else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp1} == 'number'){g['${colas}'] = ${colexp1}}
8844
+ else if(typeof g['${colas}']!== 'number' && typeof ${colexp1}!== 'number' && typeof ${colexp1}!== 'object'){g['${colas}'] = g['${colas}']}
8845
+ else if((g['${colas}'] == null || (typeof g['${colas}']!== 'number' && typeof g['${colas}']!== 'object')) && (${colexp1} == null || (typeof ${colexp1}!== 'number' && typeof ${colexp1}!== 'object'))){g['${colas}'] = null}
8846
+ else if(typeof g['${colas}'] == 'number' && typeof ${colexp1} ==null){g['${colas}'] = g['${colas}']}
8847
+ else if(typeof g['${colas}'] == null && typeof ${colexp1} =='number'){g['${colas}'] = ${colexp1}}
8848
+ else{g['${colas}'] += ${colexp1}||0}` +
8954
8849
  post
8955
8850
  );
8956
8851
  }
8957
8852
  return (
8958
8853
  pre +
8959
- "if(g['" +
8960
- colas +
8961
- "'] == null && " +
8962
- colexp +
8963
- " == null){g['" +
8964
- colas +
8965
- "'] = null} else if(typeof g['" +
8966
- colas +
8967
- "']!== 'object' && typeof g['" +
8968
- colas +
8969
- "'] !== 'number' && typeof " +
8970
- colexp +
8971
- "!== 'object' && typeof " +
8972
- colexp +
8973
- "!== 'number'){g['" +
8974
- colas +
8975
- "'] = null} else if(typeof g['" +
8976
- colas +
8977
- "'] !== 'object' && typeof g['" +
8978
- colas +
8979
- "'] !== 'number' && typeof " +
8980
- colexp +
8981
- " == 'number'){g['" +
8982
- colas +
8983
- "'] = " +
8984
- colexp +
8985
- "} else if(typeof g['" +
8986
- colas +
8987
- "'] == 'number' && typeof " +
8988
- colexp +
8989
- " !== 'number' && typeof " +
8990
- colexp +
8991
- " !== 'object'){g['" +
8992
- colas +
8993
- "'] = g['" +
8994
- colas +
8995
- "']} else if((g['" +
8996
- colas +
8997
- "'] == null || (typeof g['" +
8998
- colas +
8999
- "'] !== 'number' && typeof g['" +
9000
- colas +
9001
- "'] !== 'object')) && (" +
9002
- colexp +
9003
- ' == null || (typeof ' +
9004
- colexp +
9005
- " !== 'number' && typeof " +
9006
- colexp +
9007
- " !== 'object'))){g['" +
9008
- colas +
9009
- "'] = null} else {g['" +
9010
- colas +
9011
- "']+=(" +
9012
- colexp +
9013
- '||0);}' +
8854
+ `if(g['${colas}'] == null && ${colexp} == null){g['${colas}'] = null}
8855
+ else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number'&& typeof ${colexp}!== 'object' && typeof ${colexp}!== 'number'){g['${colas}'] = null}
8856
+ else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp} == 'number'){g['${colas}'] = ${colexp}}
8857
+ else if(typeof g['${colas}']!== 'number' && typeof ${colexp}!== 'number' && typeof ${colexp}!== 'object'){g['${colas}'] = g['${colas}']}
8858
+ else if((g['${colas}'] == null || (typeof g['${colas}']!== 'number' && typeof g['${colas}']!== 'object')) && (${colexp} == null || (typeof ${colexp}!== 'number' && typeof ${colexp}!== 'object'))){g['${colas}'] = null}
8859
+ else if(typeof g['${colas}'] == 'number' && typeof ${colexp} ==null){g['${colas}'] = g['${colas}']}
8860
+ else if(typeof g['${colas}'] == null && typeof ${colexp} =='number'){g['${colas}'] = ${colexp}}
8861
+ else{g['${colas}'] += ${colexp}||0}` +
9014
8862
  post
9015
8863
  );
9016
8864
  } else if (col.aggregatorid === 'COUNT') {
@@ -9038,89 +8886,23 @@ yy.Select.prototype.compileGroup = function (query) {
9038
8886
  let colexp1 = colexpression.toJS('p', tableid, defcols);
9039
8887
  return (
9040
8888
  pre +
9041
- "if((g['" +
9042
- colas +
9043
- "'] == null && " +
9044
- colexp1 +
9045
- '!== null) ? y = ' +
9046
- colexp1 +
9047
- " : (g['" +
9048
- colas +
9049
- "'] !== null && " +
9050
- colexp1 +
9051
- " == null) ? y = g['" +
9052
- colas +
9053
- "'] : ((y=" +
9054
- colexp1 +
9055
- ") < g['" +
9056
- colas +
9057
- "'])){ if((typeof y == 'number')) {g['" +
9058
- colas +
9059
- "'] = y;} else if(typeof y == 'object' && y instanceof Date){g['" +
9060
- colas +
9061
- "'] = y;}else if(typeof y == 'object' && typeof Number(y) == 'number'){g['" +
9062
- colas +
9063
- "'] = Number(y);}}else if(g['" +
9064
- colas +
9065
- "']!== null && typeof g['" +
9066
- colas +
9067
- "'] == 'object' && y instanceof Date){g['" +
9068
- colas +
9069
- "'] = g['" +
9070
- colas +
9071
- "']}else if(g['" +
9072
- colas +
9073
- "']!== null && typeof g['" +
9074
- colas +
9075
- "'] == 'object'){g['" +
9076
- colas +
9077
- "'] = Number(g['" +
9078
- colas +
9079
- "'])}" +
8889
+ `if((g['${colas}'] == null && ${colexp1}!== null) ? y = ${colexp1} : (g['${colas}']!== null &&
8890
+ ${colexp1} == null) ? y = g['${colas}']:((y=${colexp1}) < g['${colas}'])){ if(typeof y == 'number')
8891
+ {g['${colas}'] = y;}else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
8892
+ else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}
8893
+ else if(g['${colas}']!== null && typeof g['${colas}'] == 'object' && y instanceof Date){g['${colas}'] = g['${colas}']}
8894
+ else if(g['${colas}']!== null && typeof g['${colas}'] == 'object'){g['${colas}'] = Number(g['${colas}'])}` +
9080
8895
  post
9081
8896
  );
9082
8897
  }
9083
8898
  return (
9084
8899
  pre +
9085
- "if((g['" +
9086
- colas +
9087
- "'] == null && " +
9088
- colexp +
9089
- '!== null) ? y = ' +
9090
- colexp +
9091
- " : (g['" +
9092
- colas +
9093
- "'] !== null && " +
9094
- colexp +
9095
- " == null) ? y = g['" +
9096
- colas +
9097
- "'] : ((y=" +
9098
- colexp +
9099
- ") < g['" +
9100
- colas +
9101
- "'])){ if((typeof y == 'number')) {g['" +
9102
- colas +
9103
- "'] = y;} else if(typeof y == 'object' && y instanceof Date){g['" +
9104
- colas +
9105
- "'] = y;}else if(typeof y == 'object' && typeof Number(y) == 'number'){g['" +
9106
- colas +
9107
- "'] = Number(y);}}else if(g['" +
9108
- colas +
9109
- "']!== null && typeof g['" +
9110
- colas +
9111
- "'] == 'object' && y instanceof Date){g['" +
9112
- colas +
9113
- "'] = g['" +
9114
- colas +
9115
- "']}else if(g['" +
9116
- colas +
9117
- "']!== null && typeof g['" +
9118
- colas +
9119
- "'] == 'object'){g['" +
9120
- colas +
9121
- "'] = Number(g['" +
9122
- colas +
9123
- "'])}" +
8900
+ `if((g['${colas}'] == null && ${colexp}!== null) ? y = ${colexp} : (g['${colas}']!== null &&
8901
+ ${colexp} == null) ? y = g['${colas}']:((y=${colexp}) < g['${colas}'])){ if(typeof y == 'number')
8902
+ {g['${colas}'] = y;}else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
8903
+ else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}
8904
+ else if(g['${colas}']!== null && typeof g['${colas}'] == 'object' && y instanceof Date){g['${colas}'] = g['${colas}']}
8905
+ else if(g['${colas}']!== null && typeof g['${colas}'] == 'object'){g['${colas}'] = Number(g['${colas}'])}` +
9124
8906
  post
9125
8907
  );
9126
8908
  } else if (col.aggregatorid === 'MAX') {
@@ -9129,33 +8911,17 @@ yy.Select.prototype.compileGroup = function (query) {
9129
8911
  let colexp1 = colexpression.toJS('p', tableid, defcols);
9130
8912
  return (
9131
8913
  pre +
9132
- 'if ((y=' +
9133
- colexp1 +
9134
- ") > g['" +
9135
- colas +
9136
- "']){ if((typeof y == 'number')) {g['" +
9137
- colas +
9138
- "'] = y;} else if(typeof y == 'object' && y instanceof Date){g['" +
9139
- colas +
9140
- "'] = y;} else if(typeof y == 'object' && typeof Number(y) == 'number'){g['" +
9141
- colas +
9142
- "'] = Number(y);}}" +
8914
+ `if((y=${colexp1}) > g['${colas}']){if(typeof y == 'number'){g['${colas}'] = y;}
8915
+ else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
8916
+ else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}` +
9143
8917
  post
9144
8918
  );
9145
8919
  }
9146
8920
  return (
9147
8921
  pre +
9148
- 'if ((y=' +
9149
- colexp +
9150
- ") > g['" +
9151
- colas +
9152
- "']){ if((typeof y == 'number')) {g['" +
9153
- colas +
9154
- "'] = y;} else if(typeof y == 'object' && y instanceof Date){g['" +
9155
- colas +
9156
- "'] = y;} else if(typeof y == 'object' && typeof Number(y) == 'number'){g['" +
9157
- colas +
9158
- "'] = Number(y);}}" +
8922
+ `if((y=${colexp}) > g['${colas}']){if(typeof y == 'number'){g['${colas}'] = y;}
8923
+ else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
8924
+ else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}` +
9159
8925
  post
9160
8926
  );
9161
8927
  } else if (col.aggregatorid === 'FIRST') {
@@ -9227,6 +8993,7 @@ yy.Select.prototype.compileGroup = function (query) {
9227
8993
  // s += 'group.count++;';
9228
8994
  s += '}';
9229
8995
  });
8996
+
9230
8997
  return new Function('p,params,alasql', 'var y;' + s);
9231
8998
  };
9232
8999