alasql 2.1.8 → 2.2.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/dist/alasql.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v2.1.7-develop-295886e2 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.1.8-develop-7e87d661 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.1.7-develop-295886e2
4
+ @version 2.1.8-develop-7e87d661
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.7-develop-295886e2';
145
+ alasql.version = '2.1.8-develop-7e87d661';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -6585,8 +6585,10 @@ function queryfn3(query) {
6585
6585
  if (query.selectGroup.length > 0) {
6586
6586
 
6587
6587
  query.selectGroup.forEach(function (sg) {
6588
- if (sg.aggregatorid == 'COUNT' || sg.aggregatorid == 'SUM') {
6588
+ if (sg.aggregatorid == 'COUNT') {
6589
6589
  g[sg.nick] = 0;
6590
+ } else if (sg.aggregatorid == 'SUM') {
6591
+ g[sg.nick] = 'NULL';
6590
6592
  } else {
6591
6593
  g[sg.nick] = undefined;
6592
6594
  }
@@ -8709,16 +8711,93 @@ yy.Select.prototype.compileGroup = function (query) {
8709
8711
  ",g['$$_VALUES_" + colas + "']={},g['$$_VALUES_" + colas + "'][" + colexp + ']=true';
8710
8712
  }
8711
8713
  if (col.aggregatorid === 'SUM') {
8712
- return "'" + colas + "':(" + colexp + ')||0,';
8714
+ if ('funcid' in col.expression) {
8715
+ let colexpression = col.expression.args[0];
8716
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8717
+ return "'" + colas + "':(" + colexp1 + ')||null,';
8718
+ }
8719
+ return "'" + colas + "':(" + colexp + ')||null,';
8713
8720
  } else if (
8714
- col.aggregatorid === 'MIN' ||
8715
- col.aggregatorid === 'MAX' ||
8716
8721
  col.aggregatorid === 'FIRST' ||
8717
8722
  col.aggregatorid === 'LAST'
8718
8723
  // || col.aggregatorid == 'AVG'
8719
8724
  // ) { return "'"+col.as+'\':r[\''+col.as+'\'],'; }//f.field.arguments[0].toJS();
8720
8725
  ) {
8721
8726
  return "'" + colas + "':" + colexp + ','; //f.field.arguments[0].toJS();
8727
+ } else if (col.aggregatorid === 'MIN') {
8728
+ if ('funcid' in col.expression) {
8729
+ let colexpression = col.expression.args[0];
8730
+ 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
+ );
8748
+ }
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
+ );
8766
+ } else if (col.aggregatorid === 'MAX') {
8767
+ if ('funcid' in col.expression) {
8768
+ let colexpression = col.expression.args[0];
8769
+ 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
+ );
8785
+ }
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
+ );
8722
8801
  } else if (col.aggregatorid === 'ARRAY') {
8723
8802
  return "'" + colas + "':[" + colexp + '],';
8724
8803
  } else if (col.aggregatorid === 'COUNT') {
@@ -8812,7 +8891,128 @@ yy.Select.prototype.compileGroup = function (query) {
8812
8891
  var post = "g['$$_VALUES_" + colas + "'][" + colexp + ']=true;}';
8813
8892
  }
8814
8893
  if (col.aggregatorid === 'SUM') {
8815
- return pre + "g['" + colas + "']+=(" + colexp + '||0);' + post; //f.field.arguments[0].toJS();
8894
+ if ('funcid' in col.expression) {
8895
+ let colexpression = col.expression.args[0];
8896
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8897
+ return (
8898
+ 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);}' +
8954
+ post
8955
+ );
8956
+ }
8957
+ return (
8958
+ 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);}' +
9014
+ post
9015
+ );
8816
9016
  } else if (col.aggregatorid === 'COUNT') {
8817
9017
 
8818
9018
  if (col.expression.columnid === '*') {
@@ -8833,12 +9033,130 @@ yy.Select.prototype.compileGroup = function (query) {
8833
9033
  } else if (col.aggregatorid === 'ARRAY') {
8834
9034
  return pre + "g['" + colas + "'].push(" + colexp + ');' + post;
8835
9035
  } else if (col.aggregatorid === 'MIN') {
9036
+ if ('funcid' in col.expression) {
9037
+ let colexpression = col.expression.args[0];
9038
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
9039
+ return (
9040
+ 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
+ "'])}" +
9080
+ post
9081
+ );
9082
+ }
8836
9083
  return (
8837
- pre + 'if ((y=' + colexp + ") < g['" + colas + "']) g['" + colas + "'] = y;" + post
9084
+ 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
+ "'])}" +
9124
+ post
8838
9125
  );
8839
9126
  } else if (col.aggregatorid === 'MAX') {
9127
+ if ('funcid' in col.expression) {
9128
+ let colexpression = col.expression.args[0];
9129
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
9130
+ return (
9131
+ 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);}}" +
9143
+ post
9144
+ );
9145
+ }
8840
9146
  return (
8841
- pre + 'if ((y=' + colexp + ") > g['" + colas + "']) g['" + colas + "'] = y;" + post
9147
+ 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);}}" +
9159
+ post
8842
9160
  );
8843
9161
  } else if (col.aggregatorid === 'FIRST') {
8844
9162
  return '';
@@ -8909,7 +9227,6 @@ yy.Select.prototype.compileGroup = function (query) {
8909
9227
  // s += 'group.count++;';
8910
9228
  s += '}';
8911
9229
  });
8912
-
8913
9230
  return new Function('p,params,alasql', 'var y;' + s);
8914
9231
  };
8915
9232