alasql 2.2.4 → 2.2.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/dist/alasql.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v2.2.3-develop-21117291 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.2.6 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.2.3-develop-21117291
4
+ @version 2.2.6
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2016 Andrey Gershun & Mathias Rangel Wulff
@@ -63,7 +63,7 @@ SOFTWARE.
63
63
  /**
64
64
  AlaSQL - Main Alasql class
65
65
  @function
66
- @param {string|function|object} sql - SQL-statement or data object for fuent interface
66
+ @param {string|function|object} sql - SQL-statement or data object for fluent interface
67
67
  @param {object} params - SQL parameters
68
68
  @param {function} cb - callback function
69
69
  @param {object} scope - Scope for nested queries
@@ -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.2.3-develop-21117291';
145
+ alasql.version = '2.2.6';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -151,7 +151,7 @@ alasql.version = '2.2.3-develop-21117291';
151
151
  alasql.debug = undefined; // Initial debug variable
152
152
 
153
153
  //*only-for-browser/*
154
- var require = function(){return null}; // as alasqlparser.js is generated, we can not "remove" referenses to
154
+ var require = function(){return null}; // as alasqlparser.js is generated, we can not "remove" references to
155
155
  var __dirname = '';
156
156
  //*/
157
157
 
@@ -4054,11 +4054,11 @@ var cloneDeep = (utils.cloneDeep = function cloneDeep(obj) {
4054
4054
  return +obj;
4055
4055
  }
4056
4056
 
4057
- var temp = obj.constructor(); // changed
4057
+ var temp = new (Object.prototype.hasOwnProperty.call(obj, 'constructor') ? Object : obj.constructor)(); // changed
4058
4058
 
4059
4059
  for (var key in obj) {
4060
4060
  if (obj.hasOwnProperty(key)) {
4061
- temp[key] = cloneDeep(obj[key]);
4061
+ /* A "__proto__" key from parsed data is copied as data, never as the prototype */ if (key === '__proto__') { Object.defineProperty(temp, key, {value: cloneDeep(obj[key]), writable: true, enumerable: true, configurable: true}); } else { temp[key] = cloneDeep(obj[key]); }
4062
4062
  }
4063
4063
  }
4064
4064
  return temp;
@@ -4130,7 +4130,7 @@ var extend = (utils.extend = function extend(a, b) {
4130
4130
  a = a || {};
4131
4131
  for (var key in b) {
4132
4132
  if (b.hasOwnProperty(key)) {
4133
- a[key] = b[key];
4133
+ /* A "__proto__" key from parsed data is copied as data, never as the prototype */ if (key === '__proto__') { Object.defineProperty(a, key, {value: b[key], writable: true, enumerable: true, configurable: true}); } else { a[key] = b[key]; }
4134
4134
  }
4135
4135
  }
4136
4136
  return a;
@@ -6551,7 +6551,7 @@ function queryfn3(query) {
6551
6551
 
6552
6552
  doJoin(query, scope, h);
6553
6553
 
6554
- // If groupping, then filter groups with HAVING function
6554
+ // If grouping, then filter groups with HAVING function
6555
6555
 
6556
6556
  if (query.groupfn) {
6557
6557
  query.data = [];
@@ -7036,7 +7036,7 @@ function doJoin(query, scope, h) {
7036
7036
 
7037
7037
  // var res = query.selectfn(scope, query.params, alasql);
7038
7038
 
7039
- // If there is a GROUP BY then pipe to groupping function
7039
+ // If there is a GROUP BY then pipe to grouping function
7040
7040
  if (query.groupfn) {
7041
7041
  query.groupfn(scope, query.params, alasql);
7042
7042
  } else {
@@ -8619,7 +8619,7 @@ yy.Select.prototype.compileGroup = function (query) {
8619
8619
  var coljs = col2.split('\t')[1];
8620
8620
  // Check, if aggregator exists but GROUP BY is not exists
8621
8621
  if (columnid === '') {
8622
- return '1'; // Create fictive groupping column for fictive GROUP BY
8622
+ return '1'; // Create fictive grouping column for fictive GROUP BY
8623
8623
  }
8624
8624
  // else return "r['"+columnid+"']";
8625
8625
  query.ingroup.push(columnid);
@@ -8662,7 +8662,7 @@ yy.Select.prototype.compileGroup = function (query) {
8662
8662
  aft2 = '';
8663
8663
 
8664
8664
  if (typeof query.groupStar !== 'undefined') {
8665
- aft2 += "for(var f in p['" + query.groupStar + "']) {g[f]=p['" + query.groupStar + "'][f];};";
8665
+ aft2 += "for(var f in p['" + query.groupStar + "']) {if(/^__proto__$/.test(f))Object.defineProperty(g,f,{writable:true,enumerable:true,configurable:true});g[f]=p['" + query.groupStar + "'][f];};";
8666
8666
  }
8667
8667
 
8668
8668
  /*
@@ -9068,7 +9068,7 @@ function compileSelectStar(query, aliases, joinstar) {
9068
9068
  } else {
9069
9069
 
9070
9070
  // if column not exist, then copy all
9071
- sp += 'var w=p["' + alias + '"];for(var k in w){r[k]=w[k]};';
9071
+ sp += 'var w=p["' + alias + '"];for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
9072
9072
 
9073
9073
  query.dirtyColumns = true;
9074
9074
  }
@@ -9397,10 +9397,10 @@ yy.Select.prototype.compileSelectGroup1 = function (query) {
9397
9397
  self.columns.forEach(function (col) {
9398
9398
 
9399
9399
  if (col instanceof yy.Column && col.columnid === '*') {
9400
- // s += 'for(var k in g){r[k]=g[k]};';
9400
+ // s += 'for(var k in g){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=g[k]};';
9401
9401
  // s += 'for(var k in this.query.groupColumns){r[k]=g[this.query.groupColumns[k]]};';
9402
9402
 
9403
- s += 'for(var k in g) {r[k]=g[k]};';
9403
+ s += 'for(var k in g) {if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=g[k]};';
9404
9404
  return '';
9405
9405
 
9406
9406
  } else {
@@ -9538,6 +9538,11 @@ yy.Select.prototype.compileOrder = function (query, params) {
9538
9538
  this.order.forEach(function (ord, idx) {
9539
9539
 
9540
9540
  if (ord.expression instanceof yy.NumValue) {
9541
+ if (ord.expression.value > self.columns.length) {
9542
+ throw new Error(
9543
+ `You are trying to order by column number ${ord.expression.value} but you have only selected ${self.columns.length} columns.`
9544
+ );
9545
+ }
9541
9546
  var v = self.columns[ord.expression.value - 1];
9542
9547
  } else {
9543
9548
  var v = ord.expression;
@@ -10157,416 +10162,402 @@ yy.Over.prototype.toString = function () {
10157
10162
  //
10158
10163
  */
10159
10164
 
10160
- var assign = Object.assign;
10165
+ {
10166
+ const assign = Object.assign;
10161
10167
 
10162
- /**
10163
- Expression statement ( = 2*2; )
10164
- @class
10165
- @param {object} params Initial parameters
10166
- */
10167
- yy.ExpressionStatement = function (params) {
10168
- return assign(this, params);
10169
- };
10168
+ class ExpressionStatement {
10169
+ /** @param {object} params Initial parameters */
10170
+ constructor(params) {
10171
+ assign(this, params);
10172
+ }
10170
10173
 
10171
- /**
10172
- Convert AST to string
10173
- @this ExpressionStatement
10174
- @return {string}
10175
- */
10176
- yy.ExpressionStatement.prototype.toString = function () {
10177
- return this.expression.toString();
10178
- };
10179
- /**
10180
- Execute statement
10181
- @param {string} databaseid Database identificatro
10182
- @param {object} params Statement parameters
10183
- @param {statement-callback} cb Callback
10184
- @return {object} Result value
10185
- */
10186
- yy.ExpressionStatement.prototype.execute = function (databaseid, params, cb) {
10187
- if (this.expression) {
10174
+ /**
10175
+ Convert AST to string
10176
+ @return {string}
10177
+ */
10178
+ toString() {
10179
+ return this.expression.toString();
10180
+ }
10188
10181
 
10189
- alasql.precompile(this, databaseid, params); // Precompile queries
10190
- var exprfn = new Function(
10191
- 'params,alasql,p',
10192
- 'var y;return ' + this.expression.toJS('({})', '', null)
10193
- ).bind(this);
10194
- var res = exprfn(params, alasql);
10195
- if (cb) {
10196
- res = cb(res);
10182
+ /**
10183
+ Execute statement
10184
+ @param {string} databaseid Database identificatro
10185
+ @param {object} params Statement parameters
10186
+ @param {statement-callback} cb Callback
10187
+ @return {object} Result value
10188
+ */
10189
+ execute(databaseid, params, cb) {
10190
+ if (this.expression) {
10191
+
10192
+ alasql.precompile(this, databaseid, params); // Precompile queries
10193
+ var exprfn = new Function(
10194
+ 'params,alasql,p',
10195
+ 'var y;return ' + this.expression.toJS('({})', '', null)
10196
+ ).bind(this);
10197
+ var res = exprfn(params, alasql);
10198
+ if (cb) {
10199
+ res = cb(res);
10200
+ }
10201
+ return res;
10202
+ }
10197
10203
  }
10198
- return res;
10199
10204
  }
10200
- };
10201
10205
 
10202
- /**
10203
- Expression class
10204
- @class
10205
- @param {object} params Initial parameters
10206
- */
10206
+ class Expression {
10207
+ constructor(params) {
10208
+ assign(this, params);
10209
+ }
10207
10210
 
10208
- yy.Expression = function (params) {
10209
- return assign(this, params);
10210
- };
10211
+ /**
10212
+ Convert AST to string
10213
+ @return {string}
10214
+ */
10215
+ toString() {
10216
+ var s = this.expression.toString();
10217
+ if (this.order) {
10218
+ s += ' ' + this.order.toString();
10219
+ }
10220
+ if (this.nocase) {
10221
+ s += ' COLLATE NOCASE';
10222
+ }
10223
+ if (this.direction) {
10224
+ s += ' ' + this.direction;
10225
+ }
10226
+ return s;
10227
+ }
10211
10228
 
10212
- /**
10213
- Convert AST to string
10214
- @this ExpressionStatement
10215
- @return {string}
10216
- */
10217
- yy.Expression.prototype.toString = function () {
10218
- var s = this.expression.toString();
10219
- if (this.order) {
10220
- s += ' ' + this.order.toString();
10221
- }
10222
- if (this.nocase) {
10223
- s += ' COLLATE NOCASE';
10224
- }
10225
- if (this.direction) {
10226
- s += ' ' + this.direction;
10227
- }
10228
- return s;
10229
- };
10229
+ /**
10230
+ Find aggregator in AST subtree
10231
+ @param {object} query Query object
10232
+ */
10233
+ findAggregator(query) {
10234
+ if (this.expression.findAggregator) {
10235
+ this.expression.findAggregator(query);
10236
+ }
10237
+ }
10230
10238
 
10231
- /**
10232
- Find aggregator in AST subtree
10233
- @this ExpressionStatement
10234
- @param {object} query Query object
10235
- */
10236
- yy.Expression.prototype.findAggregator = function (query) {
10237
- if (this.expression.findAggregator) {
10238
- this.expression.findAggregator(query);
10239
- }
10240
- };
10239
+ /**
10240
+ Convert AST to JavaScript expression
10241
+ @param {string} context Context string, e.g. 'p','g', or 'x'
10242
+ @param {string} tableid Default table name
10243
+ @param {object} defcols Default columns dictionary
10244
+ @return {string} JavaScript expression
10245
+ */
10246
+ toJS(context, tableid, defcols) {
10241
10247
 
10242
- /**
10243
- Convert AST to JavaScript expression
10244
- @this ExpressionStatement
10245
- @param {string} context Context string, e.g. 'p','g', or 'x'
10246
- @param {string} tableid Default table name
10247
- @param {object} defcols Default columns dictionary
10248
- @return {string} JavaScript expression
10249
- */
10248
+ if (this.expression.reduced) {
10249
+ return 'true';
10250
+ }
10251
+ return this.expression.toJS(context, tableid, defcols);
10252
+ }
10250
10253
 
10251
- yy.Expression.prototype.toJS = function (context, tableid, defcols) {
10254
+ /**
10255
+ Compile AST to JavaScript expression
10256
+ @param {string} context Context string, e.g. 'p','g', or 'x'
10257
+ @param {string} tableid Default table name
10258
+ @param {object} defcols Default columns dictionary
10259
+ @return {string} JavaScript expression
10260
+ */
10261
+ compile(context, tableid, defcols) {
10252
10262
 
10253
- if (this.expression.reduced) {
10254
- return 'true';
10263
+ if (this.reduced) {
10264
+ return returnTrue();
10265
+ }
10266
+ return new Function('p', 'var y;return ' + this.toJS(context, tableid, defcols));
10267
+ }
10255
10268
  }
10256
- return this.expression.toJS(context, tableid, defcols);
10257
- };
10258
-
10259
- /**
10260
- Compile AST to JavaScript expression
10261
- @this ExpressionStatement
10262
- @param {string} context Context string, e.g. 'p','g', or 'x'
10263
- @param {string} tableid Default table name
10264
- @param {object} defcols Default columns dictionary
10265
- @return {string} JavaScript expression
10266
- */
10267
10269
 
10268
- yy.Expression.prototype.compile = function (context, tableid, defcols) {
10270
+ class JavaScript {
10271
+ constructor(params) {
10272
+ assign(this, params);
10273
+ }
10269
10274
 
10270
- if (this.reduced) {
10271
- return returnTrue();
10272
- }
10273
- return new Function('p', 'var y;return ' + this.toJS(context, tableid, defcols));
10274
- };
10275
+ toString() {
10276
+ var s = '``' + this.value + '``';
10277
+ return s;
10278
+ }
10275
10279
 
10276
- /**
10277
- JavaScript class
10278
- @class
10279
- */
10280
- yy.JavaScript = function (params) {
10281
- return assign(this, params);
10282
- };
10283
- yy.JavaScript.prototype.toString = function () {
10284
- var s = '``' + this.value + '``';
10285
- return s;
10286
- };
10280
+ toJS() {
10281
+ return '(' + this.value + ')';
10282
+ }
10287
10283
 
10288
- yy.JavaScript.prototype.toJS = function () {
10289
- return '(' + this.value + ')';
10290
- };
10291
- yy.JavaScript.prototype.execute = function (databaseid, params, cb) {
10292
- var res = 1;
10293
- var expr = new Function('params,alasql,p', this.value);
10294
- expr(params, alasql);
10295
- if (cb) {
10296
- res = cb(res);
10284
+ execute(databaseid, params, cb) {
10285
+ var res = 1;
10286
+ var expr = new Function('params,alasql,p', this.value);
10287
+ expr(params, alasql);
10288
+ if (cb) {
10289
+ res = cb(res);
10290
+ }
10291
+ return res;
10292
+ }
10297
10293
  }
10298
- return res;
10299
- };
10300
10294
 
10301
- /**
10302
- Literal class
10303
- @class
10304
- @example
10305
- MyVar, [My vairable], `MySQL variable`
10306
- */
10295
+ class Literal {
10296
+ constructor(params) {
10297
+ assign(this, params);
10298
+ }
10307
10299
 
10308
- yy.Literal = function (params) {
10309
- return assign(this, params);
10310
- };
10311
- yy.Literal.prototype.toString = function () {
10312
- var s = this.value;
10313
- if (this.value1) {
10314
- s = this.value1 + '.' + s;
10300
+ toString() {
10301
+ var s = this.value;
10302
+ if (this.value1) {
10303
+ s = this.value1 + '.' + s;
10304
+ }
10305
+ // else s = tableid+'.'+s;
10306
+ return s;
10307
+ }
10315
10308
  }
10316
- // else s = tableid+'.'+s;
10317
- return s;
10318
- };
10319
10309
 
10320
- /**
10321
- Join class
10322
- @class
10323
- */
10310
+ class Join {
10311
+ constructor(params) {
10312
+ assign(this, params);
10313
+ }
10324
10314
 
10325
- yy.Join = function (params) {
10326
- return assign(this, params);
10327
- };
10328
- yy.Join.prototype.toString = function () {
10329
- var s = ' ';
10330
- if (this.joinmode) {
10331
- s += this.joinmode + ' ';
10315
+ toString() {
10316
+ var s = ' ';
10317
+ if (this.joinmode) {
10318
+ s += this.joinmode + ' ';
10319
+ }
10320
+ s += 'JOIN ' + this.table.toString();
10321
+ return s;
10322
+ }
10332
10323
  }
10333
- s += 'JOIN ' + this.table.toString();
10334
- return s;
10335
- };
10336
10324
 
10337
- /**
10338
- Table class
10339
- @class
10340
- */
10325
+ class Table {
10326
+ constructor(params) {
10327
+ assign(this, params);
10328
+ }
10341
10329
 
10342
- yy.Table = function (params) {
10343
- return assign(this, params);
10344
- };
10345
- yy.Table.prototype.toString = function () {
10346
- var s = this.tableid;
10347
- // if(this.joinmode)
10348
- if (this.databaseid) {
10349
- s = this.databaseid + '.' + s;
10330
+ toString() {
10331
+ var s = this.tableid;
10332
+ // if(this.joinmode)
10333
+ if (this.databaseid) {
10334
+ s = this.databaseid + '.' + s;
10335
+ }
10336
+ return s;
10337
+ }
10350
10338
  }
10351
- return s;
10352
- };
10353
-
10354
- /**
10355
- View class
10356
- @class
10357
- */
10358
10339
 
10359
- yy.View = function (params) {
10360
- return assign(this, params);
10361
- };
10362
- yy.View.prototype.toString = function () {
10363
- var s = this.viewid;
10364
- // if(this.joinmode)
10365
- if (this.databaseid) {
10366
- s = this.databaseid + '.' + s;
10367
- }
10368
- return s;
10369
- };
10340
+ class View {
10341
+ constructor(params) {
10342
+ assign(this, params);
10343
+ }
10370
10344
 
10371
- /**
10372
- Binary operation class
10373
- @class
10374
- */
10375
- yy.Op = function (params) {
10376
- return assign(this, params);
10377
- };
10378
- yy.Op.prototype.toString = function () {
10379
- if (this.op === 'IN' || this.op === 'NOT IN') {
10380
- return this.left.toString() + ' ' + this.op + ' (' + this.right.toString() + ')';
10381
- }
10382
- if (this.allsome) {
10383
- return (
10384
- this.left.toString() + ' ' + this.op + ' ' + this.allsome + ' (' + this.right.toString() + ')'
10385
- );
10345
+ toString() {
10346
+ var s = this.viewid;
10347
+ // if(this.joinmode)
10348
+ if (this.databaseid) {
10349
+ s = this.databaseid + '.' + s;
10350
+ }
10351
+ return s;
10352
+ }
10386
10353
  }
10387
- if (this.op === '->' || this.op === '!') {
10388
- var s = this.left.toString() + this.op;
10389
10354
 
10390
- if (typeof this.right !== 'string' && typeof this.right !== 'number') {
10391
- s += '(';
10355
+ class Op {
10356
+ constructor(params) {
10357
+ assign(this, params);
10392
10358
  }
10393
10359
 
10394
- s += this.right.toString();
10360
+ toString() {
10361
+ if (this.op === 'IN' || this.op === 'NOT IN') {
10362
+ return this.left.toString() + ' ' + this.op + ' (' + this.right.toString() + ')';
10363
+ }
10364
+ if (this.allsome) {
10365
+ return (
10366
+ this.left.toString() +
10367
+ ' ' +
10368
+ this.op +
10369
+ ' ' +
10370
+ this.allsome +
10371
+ ' (' +
10372
+ this.right.toString() +
10373
+ ')'
10374
+ );
10375
+ }
10376
+ if (this.op === '->' || this.op === '!') {
10377
+ var s = this.left.toString() + this.op;
10395
10378
 
10396
- if (typeof this.right !== 'string' && typeof this.right !== 'number') {
10397
- s += ')';
10398
- }
10379
+ if (typeof this.right !== 'string' && typeof this.right !== 'number') {
10380
+ s += '(';
10381
+ }
10399
10382
 
10400
- return s;
10401
- }
10402
- if (this.op === 'BETWEEN' || this.op === 'NOT BETWEEN') {
10403
- var s =
10404
- this.left.toString() +
10405
- ' ' +
10406
- this.op +
10407
- ' ' +
10408
- this.right1.toString() +
10409
- ' AND ' +
10410
- this.right2.toString();
10383
+ s += this.right.toString();
10411
10384
 
10412
- return s;
10413
- }
10385
+ if (typeof this.right !== 'string' && typeof this.right !== 'number') {
10386
+ s += ')';
10387
+ }
10414
10388
 
10415
- return (
10416
- this.left.toString() +
10417
- ' ' +
10418
- this.op +
10419
- ' ' +
10420
- (this.allsome ? this.allsome + ' ' : '') +
10421
- this.right.toString()
10422
- );
10423
- };
10389
+ return s;
10390
+ }
10391
+ if (this.op === 'BETWEEN' || this.op === 'NOT BETWEEN') {
10392
+ var s =
10393
+ this.left.toString() +
10394
+ ' ' +
10395
+ this.op +
10396
+ ' ' +
10397
+ this.right1.toString() +
10398
+ ' AND ' +
10399
+ this.right2.toString();
10424
10400
 
10425
- yy.Op.prototype.findAggregator = function (query) {
10426
- if (this.left && this.left.findAggregator) {
10427
- this.left.findAggregator(query);
10428
- }
10429
- // Do not go in > ALL
10430
- if (this.right && this.right.findAggregator && !this.allsome) {
10431
- this.right.findAggregator(query);
10432
- }
10433
- };
10401
+ return s;
10402
+ }
10434
10403
 
10435
- yy.Op.prototype.toType = function (tableid) {
10436
- if (['-', '*', '/', '%', '^'].indexOf(this.op) > -1) {
10437
- return 'number';
10438
- }
10439
- if (['||'].indexOf(this.op) > -1) {
10440
- return 'string';
10441
- }
10442
- if (this.op === '+') {
10443
- if (this.left.toType(tableid) === 'string' || this.right.toType(tableid) === 'string') {
10444
- return 'string';
10404
+ return (
10405
+ this.left.toString() +
10406
+ ' ' +
10407
+ this.op +
10408
+ ' ' +
10409
+ (this.allsome ? this.allsome + ' ' : '') +
10410
+ this.right.toString()
10411
+ );
10445
10412
  }
10446
- if (this.left.toType(tableid) === 'number' || this.right.toType(tableid) === 'number') {
10447
- return 'number';
10413
+
10414
+ findAggregator(query) {
10415
+ if (this.left && this.left.findAggregator) {
10416
+ this.left.findAggregator(query);
10417
+ }
10418
+ // Do not go in > ALL
10419
+ if (this.right && this.right.findAggregator && !this.allsome) {
10420
+ this.right.findAggregator(query);
10421
+ }
10448
10422
  }
10449
- }
10450
10423
 
10451
- if (
10452
- [
10453
- 'AND',
10454
- 'OR',
10455
- 'NOT',
10456
- '=',
10457
- '==',
10458
- '===',
10459
- '!=',
10460
- '!==',
10461
- '!===',
10462
- '>',
10463
- '>=',
10464
- '<',
10465
- '<=',
10466
- 'IN',
10467
- 'NOT IN',
10468
- 'LIKE',
10469
- 'NOT LIKE',
10470
- 'REGEXP',
10471
- 'GLOB',
10472
- ].indexOf(this.op) > -1
10473
- ) {
10474
- return 'boolean';
10475
- }
10424
+ toType(tableid) {
10425
+ if (['-', '*', '/', '%', '^'].indexOf(this.op) > -1) {
10426
+ return 'number';
10427
+ }
10476
10428
 
10477
- if (
10478
- this.op === 'BETWEEN' ||
10479
- this.op === 'NOT BETWEEN' ||
10480
- this.op === 'IS NULL' ||
10481
- this.op === 'IS NOT NULL'
10482
- ) {
10483
- return 'boolean';
10484
- }
10429
+ if (['||'].indexOf(this.op) > -1) {
10430
+ return 'string';
10431
+ }
10485
10432
 
10486
- if (this.allsome) {
10487
- return 'boolean';
10488
- }
10433
+ if (this.op === '+') {
10434
+ if (this.left.toType(tableid) === 'string' || this.right.toType(tableid) === 'string') {
10435
+ return 'string';
10436
+ }
10437
+ if (this.left.toType(tableid) === 'number' || this.right.toType(tableid) === 'number') {
10438
+ return 'number';
10439
+ }
10440
+ }
10489
10441
 
10490
- if (!this.op) {
10491
- return this.left.toType();
10492
- }
10442
+ if (
10443
+ [
10444
+ 'AND',
10445
+ 'OR',
10446
+ 'NOT',
10447
+ '=',
10448
+ '==',
10449
+ '===',
10450
+ '!=',
10451
+ '!==',
10452
+ '!===',
10453
+ '>',
10454
+ '>=',
10455
+ '<',
10456
+ '<=',
10457
+ 'IN',
10458
+ 'NOT IN',
10459
+ 'LIKE',
10460
+ 'NOT LIKE',
10461
+ 'REGEXP',
10462
+ 'GLOB',
10463
+ ].indexOf(this.op) > -1
10464
+ ) {
10465
+ return 'boolean';
10466
+ }
10493
10467
 
10494
- return 'unknown';
10495
- };
10468
+ if (
10469
+ this.op === 'BETWEEN' ||
10470
+ this.op === 'NOT BETWEEN' ||
10471
+ this.op === 'IS NULL' ||
10472
+ this.op === 'IS NOT NULL'
10473
+ ) {
10474
+ return 'boolean';
10475
+ }
10496
10476
 
10497
- yy.Op.prototype.toJS = function (context, tableid, defcols) {
10477
+ if (this.allsome) {
10478
+ return 'boolean';
10479
+ }
10498
10480
 
10499
- var s;
10500
- var refs = [];
10501
- var op = this.op;
10502
- var _this = this;
10503
- //var leftJS = function(){return _this.left.toJS(context,tableid, defcols)};
10504
- //var rightJS = function(){return _this.right.toJS(context,tableid, defcols)};
10505
- var accessedLeft = false,
10506
- accessedRight = false;
10507
- var ref = function (expr) {
10508
- if (expr.toJS) {
10509
- expr = expr.toJS(context, tableid, defcols);
10510
- }
10511
- var i = refs.push(expr) - 1;
10512
- return 'y[' + i + ']';
10513
- };
10514
- var leftJS = function () {
10515
- return ref(_this.left);
10516
- };
10517
- var rightJS = function () {
10518
- return ref(_this.right);
10519
- };
10481
+ if (!this.op) {
10482
+ return this.left.toType();
10483
+ }
10520
10484
 
10521
- if (this.op === '=') {
10522
- op = '===';
10523
- } else if (this.op === '<>') {
10524
- op = '!=';
10525
- } else if (this.op === 'OR') {
10526
- op = '||';
10527
- }
10485
+ return 'unknown';
10486
+ }
10528
10487
 
10529
- // Arrow operator
10530
- if (this.op === '->') {
10531
- // Expression to prevent error if object is empty (#344)
10532
- var ljs = '(' + leftJS() + '||{})';
10488
+ toJS(context, tableid, defcols) {
10533
10489
 
10534
- if (typeof this.right === 'string') {
10535
- s = ljs + '["' + this.right + '"]';
10536
- } else if (typeof this.right === 'number') {
10537
- s = ljs + '[' + this.right + ']';
10538
- } else if (this.right instanceof yy.FuncValue) {
10539
- var ss = [];
10540
- if (!(!this.right.args || 0 === this.right.args.length)) {
10541
- var ss = this.right.args.map(ref);
10490
+ var s;
10491
+ var refs = [];
10492
+ var op = this.op;
10493
+ var _this = this;
10494
+ //var leftJS = function(){return _this.left.toJS(context,tableid, defcols)};
10495
+ //var rightJS = function(){return _this.right.toJS(context,tableid, defcols)};
10496
+ var accessedLeft = false,
10497
+ accessedRight = false;
10498
+ var ref = function (expr) {
10499
+ if (expr.toJS) {
10500
+ expr = expr.toJS(context, tableid, defcols);
10501
+ }
10502
+ var i = refs.push(expr) - 1;
10503
+ return 'y[' + i + ']';
10504
+ };
10505
+ var leftJS = function () {
10506
+ return ref(_this.left);
10507
+ };
10508
+ var rightJS = function () {
10509
+ return ref(_this.right);
10510
+ };
10511
+
10512
+ if (this.op === '=') {
10513
+ op = '===';
10514
+ } else if (this.op === '<>') {
10515
+ op = '!=';
10516
+ } else if (this.op === 'OR') {
10517
+ op = '||';
10542
10518
  }
10543
- s = '' + ljs + '[' + JSON.stringify(this.right.funcid) + '](' + ss.join(',') + ')';
10544
- } else {
10545
- s = '' + ljs + '[' + rightJS() + ']';
10546
- }
10547
- }
10548
10519
 
10549
- if (this.op === '!') {
10550
- if (typeof this.right === 'string') {
10551
- s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + this.right + '"]';
10552
- }
10553
- // TODO - add other cases
10554
- }
10520
+ // Arrow operator
10521
+ if (this.op === '->') {
10522
+ // Expression to prevent error if object is empty (#344)
10523
+ var ljs = '(' + leftJS() + '||{})';
10524
+
10525
+ if (typeof this.right === 'string') {
10526
+ s = ljs + '["' + this.right + '"]';
10527
+ } else if (typeof this.right === 'number') {
10528
+ s = ljs + '[' + this.right + ']';
10529
+ } else if (this.right instanceof yy.FuncValue) {
10530
+ var ss = [];
10531
+ if (!(!this.right.args || 0 === this.right.args.length)) {
10532
+ var ss = this.right.args.map(ref);
10533
+ }
10534
+ s = '' + ljs + '[' + JSON.stringify(this.right.funcid) + '](' + ss.join(',') + ')';
10535
+ } else {
10536
+ s = '' + ljs + '[' + rightJS() + ']';
10537
+ }
10538
+ }
10555
10539
 
10556
- if (this.op === 'IS') {
10557
- const leftOperand = leftJS();
10558
- const rightOperand = rightJS();
10559
- if (
10560
- this.right instanceof yy.NullValue ||
10561
- (this.right.op === 'NOT' && this.right.right instanceof yy.NullValue)
10562
- ) {
10563
- s = `(
10540
+ if (this.op === '!') {
10541
+ if (typeof this.right === 'string') {
10542
+ s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + this.right + '"]';
10543
+ }
10544
+ // TODO - add other cases
10545
+ }
10546
+
10547
+ if (this.op === 'IS') {
10548
+ const leftOperand = leftJS();
10549
+ const rightOperand = rightJS();
10550
+ if (
10551
+ this.right instanceof yy.NullValue ||
10552
+ (this.right.op === 'NOT' && this.right.right instanceof yy.NullValue)
10553
+ ) {
10554
+ s = `(
10564
10555
  (${leftOperand}==null) // Cant be ===
10565
10556
  ===
10566
10557
  (${rightOperand}==null) // Cant be ===
10567
10558
  )`;
10568
- } else {
10569
- s = `(
10559
+ } else {
10560
+ s = `(
10570
10561
  (${leftOperand} == ${rightOperand})
10571
10562
  ||
10572
10563
  (
@@ -10575,572 +10566,650 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
10575
10566
  true == ${rightOperand}
10576
10567
  )
10577
10568
  )`;
10578
- }
10579
- }
10580
-
10581
- if (this.op === '==') {
10582
- s = '' + 'alasql.utils.deepEqual(' + leftJS() + ',' + rightJS() + ')';
10583
- }
10569
+ }
10570
+ }
10584
10571
 
10585
- if (this.op === '===' || this.op === '!===') {
10586
- s =
10587
- '' +
10588
- '(' +
10589
- (this.op === '!===' ? '!' : '') +
10590
- '(' +
10591
- '(' +
10592
- leftJS() +
10593
- ').valueOf()' +
10594
- '===' +
10595
- '(' +
10596
- rightJS() +
10597
- ').valueOf()' +
10598
- ')' +
10599
- ')';
10600
- }
10572
+ if (this.op === '==') {
10573
+ s = '' + 'alasql.utils.deepEqual(' + leftJS() + ',' + rightJS() + ')';
10574
+ }
10601
10575
 
10602
- if (this.op === '!==') {
10603
- s = '' + '(!alasql.utils.deepEqual(' + leftJS() + ',' + rightJS() + '))';
10604
- }
10605
- if (this.op === '||') {
10606
- s = '' + "(''+(" + leftJS() + "||'')+(" + rightJS() + '||""))';
10607
- }
10608
- if (this.op === 'LIKE' || this.op === 'NOT LIKE') {
10609
- var s =
10610
- '(' + (this.op === 'NOT LIKE' ? '!' : '') + 'alasql.utils.like(' + rightJS() + ',' + leftJS();
10611
- if (this.escape) {
10612
- s += ',' + ref(this.escape);
10613
- }
10614
- s += '))';
10615
- }
10616
- if (this.op === 'REGEXP') {
10617
- s = 'alasql.stdfn.REGEXP_LIKE(' + leftJS() + ',' + rightJS() + ')';
10618
- }
10619
- if (this.op === 'GLOB') {
10620
- s = 'alasql.utils.glob(' + leftJS() + ',' + rightJS() + ')';
10621
- }
10576
+ if (this.op === '===' || this.op === '!===') {
10577
+ s =
10578
+ '' +
10579
+ '(' +
10580
+ (this.op === '!===' ? '!' : '') +
10581
+ '(' +
10582
+ '(' +
10583
+ leftJS() +
10584
+ ').valueOf()' +
10585
+ '===' +
10586
+ '(' +
10587
+ rightJS() +
10588
+ ').valueOf()' +
10589
+ ')' +
10590
+ ')';
10591
+ }
10622
10592
 
10623
- if (this.op === 'BETWEEN' || this.op === 'NOT BETWEEN') {
10624
- var left = leftJS();
10625
- s =
10626
- '' +
10627
- '(' +
10628
- (this.op === 'NOT BETWEEN' ? '!' : '') +
10629
- '(' +
10630
- '(' +
10631
- ref(this.right1) +
10632
- '<=' +
10633
- left +
10634
- ') && (' +
10635
- left +
10636
- '<=' +
10637
- ref(this.right2) +
10638
- ')' +
10639
- ')' +
10640
- ')';
10641
- }
10593
+ if (this.op === '!==') {
10594
+ s = '' + '(!alasql.utils.deepEqual(' + leftJS() + ',' + rightJS() + '))';
10595
+ }
10596
+ if (this.op === '||') {
10597
+ s = '' + "(''+(" + leftJS() + "||'')+(" + rightJS() + '||""))';
10598
+ }
10599
+ if (this.op === 'LIKE' || this.op === 'NOT LIKE') {
10600
+ var s =
10601
+ '(' +
10602
+ (this.op === 'NOT LIKE' ? '!' : '') +
10603
+ 'alasql.utils.like(' +
10604
+ rightJS() +
10605
+ ',' +
10606
+ leftJS();
10607
+ if (this.escape) {
10608
+ s += ',' + ref(this.escape);
10609
+ }
10610
+ s += '))';
10611
+ }
10612
+ if (this.op === 'REGEXP') {
10613
+ s = 'alasql.stdfn.REGEXP_LIKE(' + leftJS() + ',' + rightJS() + ')';
10614
+ }
10615
+ if (this.op === 'GLOB') {
10616
+ s = 'alasql.utils.glob(' + leftJS() + ',' + rightJS() + ')';
10617
+ }
10642
10618
 
10643
- if (this.op === 'IN') {
10644
- if (this.right instanceof yy.Select) {
10645
- s = '(';
10646
- // s += 'this.query.queriesdata['+this.queriesidx+']';
10647
- // s += 'alasql.utils.flatArray(this.query.queriesfn['+(this.queriesidx)+'](params,null,context))';
10648
- s +=
10649
- 'alasql.utils.flatArray(this.queriesfn[' +
10650
- this.queriesidx +
10651
- '](params,null,' +
10652
- context +
10653
- '))';
10654
- s += '.indexOf(';
10655
- s += 'alasql.utils.getValueOf(' + leftJS() + '))>-1)';
10656
- } else if (Array.isArray(this.right)) {
10657
- // if(this.right.length == 0) return 'false';
10658
- s =
10659
- '([' +
10660
- this.right.map(ref).join(',') +
10661
- '].indexOf(alasql.utils.getValueOf(' +
10662
- leftJS() +
10663
- '))>-1)';
10619
+ if (this.op === 'BETWEEN' || this.op === 'NOT BETWEEN') {
10620
+ var left = leftJS();
10621
+ s =
10622
+ '' +
10623
+ '(' +
10624
+ (this.op === 'NOT BETWEEN' ? '!' : '') +
10625
+ '(' +
10626
+ '(' +
10627
+ ref(this.right1) +
10628
+ '<=' +
10629
+ left +
10630
+ ') && (' +
10631
+ left +
10632
+ '<=' +
10633
+ ref(this.right2) +
10634
+ ')' +
10635
+ ')' +
10636
+ ')';
10637
+ }
10664
10638
 
10665
- } else {
10666
- s = '(' + rightJS() + '.indexOf(' + leftJS() + ')>-1)';
10639
+ if (this.op === 'IN') {
10640
+ if (this.right instanceof yy.Select) {
10641
+ s = '(';
10642
+ // s += 'this.query.queriesdata['+this.queriesidx+']';
10643
+ // s += 'alasql.utils.flatArray(this.query.queriesfn['+(this.queriesidx)+'](params,null,context))';
10644
+ s +=
10645
+ 'alasql.utils.flatArray(this.queriesfn[' +
10646
+ this.queriesidx +
10647
+ '](params,null,' +
10648
+ context +
10649
+ '))';
10650
+ s += '.indexOf(';
10651
+ s += 'alasql.utils.getValueOf(' + leftJS() + '))>-1)';
10652
+ } else if (Array.isArray(this.right)) {
10653
+ // if(this.right.length == 0) return 'false';
10654
+ s =
10655
+ '([' +
10656
+ this.right.map(ref).join(',') +
10657
+ '].indexOf(alasql.utils.getValueOf(' +
10658
+ leftJS() +
10659
+ '))>-1)';
10667
10660
 
10668
- // } else {
10669
- // throw new Error('Wrong IN operator without SELECT part');
10670
- }
10671
- }
10661
+ } else {
10662
+ s = '(' + rightJS() + '.indexOf(' + leftJS() + ')>-1)';
10672
10663
 
10673
- if (this.op === 'NOT IN') {
10674
- if (this.right instanceof yy.Select) {
10675
- s = '(';
10676
- s += 'alasql.utils.flatArray(this.queriesfn[' + this.queriesidx + '](params,null,p))';
10677
- s += '.indexOf(';
10678
- s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
10679
- } else if (Array.isArray(this.right)) {
10680
- s = '([' + this.right.map(ref).join(',') + '].indexOf(';
10681
- s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
10682
- } else {
10683
- s = '(' + rightJS() + '.indexOf(';
10684
- s += leftJS() + ')==-1)';
10664
+ // } else {
10665
+ // throw new Error('Wrong IN operator without SELECT part');
10666
+ }
10667
+ }
10685
10668
 
10686
- // throw new Error('Wrong NOT IN operator without SELECT part');
10687
- }
10688
- }
10669
+ if (this.op === 'NOT IN') {
10670
+ if (this.right instanceof yy.Select) {
10671
+ s = '(';
10672
+ s += 'alasql.utils.flatArray(this.queriesfn[' + this.queriesidx + '](params,null,p))';
10673
+ s += '.indexOf(';
10674
+ s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
10675
+ } else if (Array.isArray(this.right)) {
10676
+ s = '([' + this.right.map(ref).join(',') + '].indexOf(';
10677
+ s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
10678
+ } else {
10679
+ s = '(' + rightJS() + '.indexOf(';
10680
+ s += leftJS() + ')==-1)';
10689
10681
 
10690
- if (this.allsome === 'ALL') {
10691
- var s;
10692
- if (this.right instanceof yy.Select) {
10693
- s = 'alasql.utils.flatArray(this.query.queriesfn[' + this.queriesidx + '](params,null,p))';
10682
+ // throw new Error('Wrong NOT IN operator without SELECT part');
10683
+ }
10684
+ }
10694
10685
 
10695
- s += '.every(function(b){return (';
10696
- s += leftJS() + ')' + op + 'b})';
10697
- } else if (Array.isArray(this.right)) {
10698
- s =
10699
- '' +
10700
- (this.right.length == 1 ? ref(this.right[0]) : '[' + this.right.map(ref).join(',') + ']');
10701
- s += '.every(function(b){return (';
10702
- s += leftJS() + ')' + op + 'b})';
10703
- } else {
10704
- throw new Error('NOT IN operator without SELECT');
10705
- }
10706
- }
10707
-
10708
- if (this.allsome === 'SOME' || this.allsome === 'ANY') {
10709
- var s;
10710
- if (this.right instanceof yy.Select) {
10711
- s = 'alasql.utils.flatArray(this.query.queriesfn[' + this.queriesidx + '](params,null,p))';
10712
- s += '.some(function(b){return (';
10713
- s += leftJS() + ')' + op + 'b})';
10714
- } else if (Array.isArray(this.right)) {
10715
- s =
10716
- '' +
10717
- (this.right.length == 1 ? ref(this.right[0]) : '[' + this.right.map(ref).join(',') + ']');
10718
- s += '.some(function(b){return (';
10719
- s += leftJS() + ')' + op + 'b})';
10720
- } else {
10721
- throw new Error('SOME/ANY operator without SELECT');
10722
- }
10723
- }
10686
+ if (this.allsome === 'ALL') {
10687
+ var s;
10688
+ if (this.right instanceof yy.Select) {
10689
+ s =
10690
+ 'alasql.utils.flatArray(this.query.queriesfn[' + this.queriesidx + '](params,null,p))';
10691
+
10692
+ s += '.every(function(b){return (';
10693
+ s += leftJS() + ')' + op + 'b})';
10694
+ } else if (Array.isArray(this.right)) {
10695
+ s =
10696
+ '' +
10697
+ (this.right.length == 1
10698
+ ? ref(this.right[0])
10699
+ : '[' + this.right.map(ref).join(',') + ']');
10700
+ s += '.every(function(b){return (';
10701
+ s += leftJS() + ')' + op + 'b})';
10702
+ } else {
10703
+ throw new Error('NOT IN operator without SELECT');
10704
+ }
10705
+ }
10724
10706
 
10725
- // Special case for AND optimization (if reduced)
10726
- if (this.op === 'AND') {
10727
- if (this.left.reduced) {
10728
- if (this.right.reduced) {
10729
- return 'true';
10730
- } else {
10731
- s = rightJS();
10707
+ if (this.allsome === 'SOME' || this.allsome === 'ANY') {
10708
+ var s;
10709
+ if (this.right instanceof yy.Select) {
10710
+ s =
10711
+ 'alasql.utils.flatArray(this.query.queriesfn[' + this.queriesidx + '](params,null,p))';
10712
+ s += '.some(function(b){return (';
10713
+ s += leftJS() + ')' + op + 'b})';
10714
+ } else if (Array.isArray(this.right)) {
10715
+ s =
10716
+ '' +
10717
+ (this.right.length == 1
10718
+ ? ref(this.right[0])
10719
+ : '[' + this.right.map(ref).join(',') + ']');
10720
+ s += '.some(function(b){return (';
10721
+ s += leftJS() + ')' + op + 'b})';
10722
+ } else {
10723
+ throw new Error('SOME/ANY operator without SELECT');
10724
+ }
10732
10725
  }
10733
- } else if (this.right.reduced) {
10734
- s = leftJS();
10735
- }
10736
10726
 
10737
- // Otherwise process as regular operation (see below)
10738
- op = '&&';
10739
- }
10727
+ // Special case for AND optimization (if reduced)
10728
+ if (this.op === 'AND') {
10729
+ if (this.left.reduced) {
10730
+ if (this.right.reduced) {
10731
+ return 'true';
10732
+ } else {
10733
+ s = rightJS();
10734
+ }
10735
+ } else if (this.right.reduced) {
10736
+ s = leftJS();
10737
+ }
10740
10738
 
10741
- // if(this.op === '^') {
10742
- // // return 'Math.pow('
10743
- // // + leftJS()
10744
- // // + ','
10745
- // // + rightJS()
10746
- // // + ')';
10747
- // }
10739
+ // Otherwise process as regular operation (see below)
10740
+ op = '&&';
10741
+ }
10748
10742
 
10749
- var expr = s || '(' + leftJS() + op + rightJS() + ')';
10743
+ // if(this.op === '^') {
10744
+ // // return 'Math.pow('
10745
+ // // + leftJS()
10746
+ // // + ','
10747
+ // // + rightJS()
10748
+ // // + ')';
10749
+ // }
10750
+ var expr = s || '(' + leftJS() + op + rightJS() + ')';
10750
10751
 
10751
- var declareRefs = 'y=[(' + refs.join('), (') + ')]';
10752
- if (op === '&&' || op === '||' || op === 'IS' || op === 'IS NULL' || op === 'IS NOT NULL') {
10753
- return '(' + declareRefs + ', ' + expr + ')';
10754
- }
10752
+ var declareRefs = 'y=[(' + refs.join('), (') + ')]';
10753
+ if (op === '&&' || op === '||' || op === 'IS' || op === 'IS NULL' || op === 'IS NOT NULL') {
10754
+ return '(' + declareRefs + ', ' + expr + ')';
10755
+ }
10755
10756
 
10756
- return (
10757
- '(' + declareRefs + ', ' + 'y.some(function(e){return e == null}) ? void 0 : ' + expr + ')'
10758
- );
10759
- };
10757
+ return (
10758
+ '(' + declareRefs + ', ' + 'y.some(function(e){return e == null}) ? void 0 : ' + expr + ')'
10759
+ );
10760
+ }
10761
+ }
10760
10762
 
10761
- yy.VarValue = function (params) {
10762
- return assign(this, params);
10763
- };
10764
- yy.VarValue.prototype.toString = function () {
10765
- return '@' + this.variable;
10766
- };
10763
+ class VarValue {
10764
+ constructor(params) {
10765
+ assign(this, params);
10766
+ }
10767
10767
 
10768
- yy.VarValue.prototype.toType = function () {
10769
- return 'unknown';
10770
- };
10768
+ toString() {
10769
+ return '@' + this.variable;
10770
+ }
10771
10771
 
10772
- yy.VarValue.prototype.toJS = function () {
10773
- return "alasql.vars['" + this.variable + "']";
10774
- };
10772
+ toType() {
10773
+ return 'unknown';
10774
+ }
10775
10775
 
10776
- yy.NumValue = function (params) {
10777
- return assign(this, params);
10778
- };
10779
- yy.NumValue.prototype.toString = function () {
10780
- return this.value.toString();
10781
- };
10776
+ toJS() {
10777
+ return "alasql.vars['" + this.variable + "']";
10778
+ }
10779
+ }
10782
10780
 
10783
- yy.NumValue.prototype.toType = function () {
10784
- return 'number';
10785
- };
10781
+ class NumValue {
10782
+ constructor(params) {
10783
+ assign(this, params);
10784
+ }
10786
10785
 
10787
- yy.NumValue.prototype.toJS = function () {
10788
- return '' + this.value;
10789
- };
10786
+ toString() {
10787
+ return this.value.toString();
10788
+ }
10790
10789
 
10791
- yy.StringValue = function (params) {
10792
- return assign(this, params);
10793
- };
10794
- yy.StringValue.prototype.toString = function () {
10795
- return "'" + this.value.toString() + "'";
10796
- };
10790
+ toType() {
10791
+ return 'number';
10792
+ }
10797
10793
 
10798
- yy.StringValue.prototype.toType = function () {
10799
- return 'string';
10800
- };
10794
+ toJS() {
10795
+ return '' + this.value;
10796
+ }
10797
+ }
10801
10798
 
10802
- yy.StringValue.prototype.toJS = function () {
10803
- return "'" + escapeq(this.value) + "'";
10804
- };
10799
+ class StringValue {
10800
+ constructor(params) {
10801
+ assign(this, params);
10802
+ }
10805
10803
 
10806
- yy.DomainValueValue = function (params) {
10807
- return assign(this, params);
10808
- };
10809
- yy.DomainValueValue.prototype.toString = function () {
10810
- return 'VALUE';
10811
- };
10804
+ toString() {
10805
+ return "'" + this.value.toString() + "'";
10806
+ }
10812
10807
 
10813
- yy.DomainValueValue.prototype.toType = function () {
10814
- return 'object';
10815
- };
10808
+ toType() {
10809
+ return 'string';
10810
+ }
10816
10811
 
10817
- yy.DomainValueValue.prototype.toJS = function (context, tableid, defcols) {
10812
+ toJS() {
10813
+ return "'" + escapeq(this.value) + "'";
10814
+ }
10815
+ }
10818
10816
 
10819
- // return "'"+doubleqq(this.value)+"'";
10820
- return context;
10821
- };
10817
+ class DomainValueValue {
10818
+ constructor(params) {
10819
+ assign(this, params);
10820
+ }
10822
10821
 
10823
- yy.ArrayValue = function (params) {
10824
- return assign(this, params);
10825
- };
10826
- yy.ArrayValue.prototype.toString = function () {
10827
- return 'ARRAY[]';
10828
- };
10822
+ toString() {
10823
+ return 'VALUE';
10824
+ }
10829
10825
 
10830
- yy.ArrayValue.prototype.toType = function () {
10831
- return 'object';
10832
- };
10826
+ toType() {
10827
+ return 'object';
10828
+ }
10833
10829
 
10834
- yy.ArrayValue.prototype.toJS = function (context, tableid, defcols) {
10835
- return (
10836
- '[(' +
10837
- this.value
10838
- .map(function (el) {
10839
- return el.toJS(context, tableid, defcols);
10840
- })
10841
- .join('), (') +
10842
- ')]'
10843
- );
10844
- };
10830
+ toJS(context, tableid, defcols) {
10845
10831
 
10846
- yy.LogicValue = function (params) {
10847
- return assign(this, params);
10848
- };
10849
- yy.LogicValue.prototype.toString = function () {
10850
- return this.value ? 'TRUE' : 'FALSE';
10851
- };
10832
+ // return "'"+doubleqq(this.value)+"'";
10833
+ return context;
10834
+ }
10835
+ }
10852
10836
 
10853
- yy.LogicValue.prototype.toType = function () {
10854
- return 'boolean';
10855
- };
10837
+ class ArrayValue {
10838
+ constructor(params) {
10839
+ assign(this, params);
10840
+ }
10856
10841
 
10857
- yy.LogicValue.prototype.toJS = function () {
10858
- return this.value ? 'true' : 'false';
10859
- };
10842
+ toString() {
10843
+ return 'ARRAY[]';
10844
+ }
10860
10845
 
10861
- yy.NullValue = function (params) {
10862
- return assign(this, params);
10863
- };
10864
- yy.NullValue.prototype.toString = function () {
10865
- return 'NULL';
10866
- };
10867
- yy.NullValue.prototype.toJS = function () {
10868
- return 'undefined';
10869
- // return 'undefined';
10870
- };
10846
+ toType() {
10847
+ return 'object';
10848
+ }
10871
10849
 
10872
- yy.ParamValue = function (params) {
10873
- return assign(this, params);
10874
- };
10875
- yy.ParamValue.prototype.toString = function () {
10876
- return '$' + this.param;
10877
- };
10878
- yy.ParamValue.prototype.toJS = function () {
10879
- if (typeof this.param === 'string') {
10880
- return "params['" + this.param + "']";
10850
+ toJS(context, tableid, defcols) {
10851
+ return (
10852
+ '[(' +
10853
+ this.value
10854
+ .map(function (el) {
10855
+ return el.toJS(context, tableid, defcols);
10856
+ })
10857
+ .join('), (') +
10858
+ ')]'
10859
+ );
10860
+ }
10881
10861
  }
10882
10862
 
10883
- return 'params[' + this.param + ']';
10884
- };
10863
+ class LogicValue {
10864
+ constructor(params) {
10865
+ assign(this, params);
10866
+ }
10885
10867
 
10886
- yy.UniOp = function (params) {
10887
- return assign(this, params);
10888
- };
10889
- yy.UniOp.prototype.toString = function () {
10890
- var s;
10891
- s = void 0;
10892
- if (this.op === '~') {
10893
- s = this.op + this.right.toString();
10894
- }
10895
- if (this.op === '-') {
10896
- s = this.op + this.right.toString();
10897
- }
10898
- if (this.op === '+') {
10899
- s = this.op + this.right.toString();
10900
- }
10901
- if (this.op === '#') {
10902
- s = this.op + this.right.toString();
10903
- }
10904
- if (this.op === 'NOT') {
10905
- s = this.op + '(' + this.right.toString() + ')';
10906
- }
10907
- if (this.op === null) {
10908
- s = '(' + this.right.toString() + ')';
10909
- }
10910
- if (!s) {
10911
- s = '(' + this.right.toString() + ')';
10912
- }
10913
- return s;
10914
- };
10868
+ toString() {
10869
+ return this.value ? 'TRUE' : 'FALSE';
10870
+ }
10915
10871
 
10916
- yy.UniOp.prototype.findAggregator = function (query) {
10917
- if (this.right.findAggregator) {
10918
- this.right.findAggregator(query);
10919
- }
10920
- };
10872
+ toType() {
10873
+ return 'boolean';
10874
+ }
10921
10875
 
10922
- yy.UniOp.prototype.toType = function () {
10923
- if (this.op === '-') {
10924
- return 'number';
10876
+ toJS() {
10877
+ return this.value ? 'true' : 'false';
10878
+ }
10925
10879
  }
10926
10880
 
10927
- if (this.op === '+') {
10928
- return 'number';
10929
- }
10881
+ class NullValue {
10882
+ constructor(params) {
10883
+ assign(this, params);
10884
+ }
10885
+
10886
+ toString() {
10887
+ return 'NULL';
10888
+ }
10930
10889
 
10931
- if (this.op === 'NOT') {
10932
- return 'boolean';
10890
+ toJS() {
10891
+ return 'undefined';
10892
+ }
10933
10893
  }
10934
10894
 
10935
- // Todo: implement default case
10936
- };
10895
+ class ParamValue {
10896
+ constructor(params) {
10897
+ assign(this, params);
10898
+ }
10937
10899
 
10938
- yy.UniOp.prototype.toJS = function (context, tableid, defcols) {
10939
- if (this.op === '~') {
10940
- return '(~(' + this.right.toJS(context, tableid, defcols) + '))';
10941
- }
10900
+ toString() {
10901
+ return '$' + this.param;
10902
+ }
10942
10903
 
10943
- if (this.op === '-') {
10944
- return '(-(' + this.right.toJS(context, tableid, defcols) + '))';
10945
- }
10904
+ toJS() {
10905
+ if (typeof this.param === 'string') {
10906
+ return "params['" + this.param + "']";
10907
+ }
10946
10908
 
10947
- if (this.op === '+') {
10948
- return '(' + this.right.toJS(context, tableid, defcols) + ')';
10909
+ return 'params[' + this.param + ']';
10910
+ }
10949
10911
  }
10950
10912
 
10951
- if (this.op === 'NOT') {
10952
- return '!(' + this.right.toJS(context, tableid, defcols) + ')';
10953
- }
10913
+ class UniOp {
10914
+ constructor(params) {
10915
+ assign(this, params);
10916
+ }
10954
10917
 
10955
- if (this.op === '#') {
10956
- if (this.right instanceof yy.Column) {
10957
- return "(alasql.databases[alasql.useid].objects['" + this.right.columnid + "'])";
10958
- } else {
10959
- return (
10960
- '(alasql.databases[alasql.useid].objects[' +
10961
- this.right.toJS(context, tableid, defcols) +
10962
- '])'
10963
- );
10918
+ toString() {
10919
+ var s;
10920
+ const {op, right} = this;
10921
+ const res = right.toString();
10922
+
10923
+ if (op === '~') {
10924
+ s = op + res;
10925
+ }
10926
+ if (op === '-') {
10927
+ s = op + res;
10928
+ }
10929
+ if (op === '+') {
10930
+ s = op + res;
10931
+ }
10932
+ if (op === '#') {
10933
+ s = op + res;
10934
+ }
10935
+ if (op === 'NOT') {
10936
+ s = op + '(' + res + ')';
10937
+ }
10938
+ if (op === null) {
10939
+ s = '(' + res + ')';
10940
+ }
10941
+ if (!s) {
10942
+ s = '(' + res + ')';
10943
+ }
10944
+ return s;
10964
10945
  }
10965
- }
10966
10946
 
10967
- // Please avoid === here
10968
- if (this.op == null) {
10969
- // jshint ignore:line
10970
- return '(' + this.right.toJS(context, tableid, defcols) + ')';
10971
- }
10947
+ findAggregator(query) {
10948
+ if (this.right.findAggregator) {
10949
+ this.right.findAggregator(query);
10950
+ }
10951
+ }
10972
10952
 
10973
- // Todo: implement default case.
10974
- };
10953
+ toType() {
10954
+ if (this.op === '-') {
10955
+ return 'number';
10956
+ }
10975
10957
 
10976
- yy.Column = function (params) {
10977
- return assign(this, params);
10978
- };
10979
- yy.Column.prototype.toString = function () {
10980
- var s;
10981
- if (this.columnid == +this.columnid) {
10982
- s = '[' + this.columnid + ']';
10983
- } else {
10984
- s = this.columnid;
10985
- }
10986
- if (this.tableid) {
10987
- if (+this.columnid === this.columnid) {
10988
- s = this.tableid + s;
10989
- } else {
10990
- s = this.tableid + '.' + s;
10958
+ if (this.op === '+') {
10959
+ return 'number';
10960
+ }
10961
+
10962
+ if (this.op === 'NOT') {
10963
+ return 'boolean';
10964
+ }
10965
+
10966
+ // Todo: implement default case
10991
10967
  }
10992
- if (this.databaseid) {
10993
- s = this.databaseid + '.' + s;
10968
+
10969
+ toJS(context, tableid, defcols) {
10970
+ if (this.op === '~') {
10971
+ return '(~(' + this.right.toJS(context, tableid, defcols) + '))';
10972
+ }
10973
+
10974
+ if (this.op === '-') {
10975
+ return '(-(' + this.right.toJS(context, tableid, defcols) + '))';
10976
+ }
10977
+
10978
+ if (this.op === '+') {
10979
+ return '(' + this.right.toJS(context, tableid, defcols) + ')';
10980
+ }
10981
+
10982
+ if (this.op === 'NOT') {
10983
+ return '!(' + this.right.toJS(context, tableid, defcols) + ')';
10984
+ }
10985
+
10986
+ if (this.op === '#') {
10987
+ if (this.right instanceof Column) {
10988
+ return "(alasql.databases[alasql.useid].objects['" + this.right.columnid + "'])";
10989
+ } else {
10990
+ return (
10991
+ '(alasql.databases[alasql.useid].objects[' +
10992
+ this.right.toJS(context, tableid, defcols) +
10993
+ '])'
10994
+ );
10995
+ }
10996
+ }
10997
+
10998
+ // Please avoid === here
10999
+ if (this.op == null) {
11000
+ // jshint ignore:line
11001
+ return '(' + this.right.toJS(context, tableid, defcols) + ')';
11002
+ }
11003
+
11004
+ // Todo: implement default case.
10994
11005
  }
10995
11006
  }
10996
- return s;
10997
- };
10998
11007
 
10999
- yy.Column.prototype.toJS = function (context, tableid, defcols) {
11000
- var s = '';
11001
- if (!this.tableid && tableid === '' && !defcols) {
11002
- if (this.columnid !== '_') {
11003
- s = context + "['" + this.columnid + "']";
11004
- } else {
11005
- if (context === 'g') {
11006
- s = "g['_']";
11007
- } else {
11008
- s = context;
11009
- }
11008
+ class Column {
11009
+ constructor(params) {
11010
+ assign(this, params);
11010
11011
  }
11011
- } else {
11012
- if (context === 'g') {
11013
- s = "g['" + this.nick + "']";
11014
- } else if (this.tableid) {
11015
- if (this.columnid !== '_') {
11016
- s = context + "['" + this.tableid + "']['" + this.columnid + "']";
11012
+
11013
+ toString() {
11014
+ var s;
11015
+ if (this.columnid == +this.columnid) {
11016
+ s = '[' + this.columnid + ']';
11017
11017
  } else {
11018
- if (context === 'g') {
11019
- s = "g['_']";
11018
+ s = this.columnid;
11019
+ }
11020
+ if (this.tableid) {
11021
+ if (+this.columnid === this.columnid) {
11022
+ s = this.tableid + s;
11020
11023
  } else {
11021
- s = context + "['" + this.tableid + "']";
11024
+ s = this.tableid + '.' + s;
11025
+ }
11026
+ if (this.databaseid) {
11027
+ s = this.databaseid + '.' + s;
11022
11028
  }
11023
11029
  }
11024
- } else if (defcols) {
11025
- var tbid = defcols[this.columnid];
11026
- if (tbid === '-') {
11027
- throw new Error(
11028
- 'Cannot resolve column "' + this.columnid + '" because it exists in two source tables'
11029
- );
11030
- } else if (tbid) {
11030
+ return s;
11031
+ }
11032
+
11033
+ toJS(context, tableid, defcols) {
11034
+ var s = '';
11035
+ if (!this.tableid && tableid === '' && !defcols) {
11031
11036
  if (this.columnid !== '_') {
11032
- s = context + "['" + tbid + "']['" + this.columnid + "']";
11037
+ s = context + "['" + this.columnid + "']";
11033
11038
  } else {
11034
- s = context + "['" + tbid + "']";
11039
+ if (context === 'g') {
11040
+ s = "g['_']";
11041
+ } else {
11042
+ s = context;
11043
+ }
11035
11044
  }
11036
-
11037
11045
  } else {
11038
- if (this.columnid !== '_') {
11039
- s = context + "['" + (this.tableid || tableid) + "']['" + this.columnid + "']";
11046
+ if (context === 'g') {
11047
+ s = "g['" + this.nick + "']";
11048
+ } else if (this.tableid) {
11049
+ if (this.columnid !== '_') {
11050
+ s = context + "['" + this.tableid + "']['" + this.columnid + "']";
11051
+ } else {
11052
+ if (context === 'g') {
11053
+ s = "g['_']";
11054
+ } else {
11055
+ s = context + "['" + this.tableid + "']";
11056
+ }
11057
+ }
11058
+ } else if (defcols) {
11059
+ var tbid = defcols[this.columnid];
11060
+ if (tbid === '-') {
11061
+ throw new Error(
11062
+ 'Cannot resolve column "' + this.columnid + '" because it exists in two source tables'
11063
+ );
11064
+ } else if (tbid) {
11065
+ if (this.columnid !== '_') {
11066
+ s = context + "['" + tbid + "']['" + this.columnid + "']";
11067
+ } else {
11068
+ s = context + "['" + tbid + "']";
11069
+ }
11070
+
11071
+ } else {
11072
+ if (this.columnid !== '_') {
11073
+ s = context + "['" + (this.tableid || tableid) + "']['" + this.columnid + "']";
11074
+ } else {
11075
+ s = context + "['" + (this.tableid || tableid) + "']";
11076
+ }
11077
+ }
11078
+ } else if (tableid === -1) {
11079
+ s = context + "['" + this.columnid + "']";
11040
11080
  } else {
11041
- s = context + "['" + (this.tableid || tableid) + "']";
11081
+ if (this.columnid !== '_') {
11082
+ s = context + "['" + (this.tableid || tableid) + "']['" + this.columnid + "']";
11083
+ } else {
11084
+ s = context + "['" + (this.tableid || tableid) + "']";
11085
+ }
11042
11086
  }
11043
11087
  }
11044
- } else if (tableid === -1) {
11045
- s = context + "['" + this.columnid + "']";
11046
- } else {
11047
- if (this.columnid !== '_') {
11048
- s = context + "['" + (this.tableid || tableid) + "']['" + this.columnid + "']";
11049
- } else {
11050
- s = context + "['" + (this.tableid || tableid) + "']";
11051
- }
11088
+ return s;
11052
11089
  }
11053
11090
  }
11054
- return s;
11055
- };
11056
11091
 
11057
- yy.AggrValue = function (params) {
11058
- return assign(this, params);
11059
- };
11060
- yy.AggrValue.prototype.toString = function () {
11061
- var s = '';
11062
- if (this.aggregatorid === 'REDUCE') {
11063
- s += this.funcid.replace(re_invalidFnNameChars, '') + '(';
11064
- } else {
11065
- s += this.aggregatorid + '(';
11066
- }
11092
+ class AggrValue {
11093
+ constructor(params) {
11094
+ assign(this, params);
11095
+ }
11067
11096
 
11068
- if (this.distinct) {
11069
- s += 'DISTINCT ';
11070
- }
11097
+ toString() {
11098
+ var s = '';
11099
+ if (this.aggregatorid === 'REDUCE') {
11100
+ s += this.funcid.replace(re_invalidFnNameChars, '') + '(';
11101
+ } else {
11102
+ s += this.aggregatorid + '(';
11103
+ }
11071
11104
 
11072
- if (this.expression) {
11073
- s += this.expression.toString();
11074
- }
11105
+ if (this.distinct) {
11106
+ s += 'DISTINCT ';
11107
+ }
11075
11108
 
11076
- s += ')';
11109
+ if (this.expression) {
11110
+ s += this.expression.toString();
11111
+ }
11077
11112
 
11078
- if (this.over) {
11079
- s += ' ' + this.over.toString();
11080
- }
11081
- return s;
11082
- };
11113
+ s += ')';
11083
11114
 
11084
- yy.AggrValue.prototype.findAggregator = function (query) {
11085
- var colas = escapeq(this.toString()) + ':' + query.selectGroup.length;
11086
- var found = false;
11087
- if (!found) {
11088
- if (!this.nick) {
11089
- this.nick = colas;
11115
+ if (this.over) {
11116
+ s += ' ' + this.over.toString();
11117
+ }
11118
+ return s;
11119
+ }
11120
+
11121
+ findAggregator(query) {
11122
+ var colas = escapeq(this.toString()) + ':' + query.selectGroup.length;
11090
11123
  var found = false;
11091
- for (var i = 0; i < query.removeKeys.length; i++) {
11092
- if (query.removeKeys[i] === colas) {
11093
- found = true;
11094
- break;
11124
+ if (!found) {
11125
+ if (!this.nick) {
11126
+ this.nick = colas;
11127
+ var found = false;
11128
+ for (var i = 0; i < query.removeKeys.length; i++) {
11129
+ if (query.removeKeys[i] === colas) {
11130
+ found = true;
11131
+ break;
11132
+ }
11133
+ }
11134
+ if (!found) {
11135
+ query.removeKeys.push(colas);
11136
+ }
11095
11137
  }
11138
+ query.selectGroup.push(this);
11096
11139
  }
11097
- if (!found) {
11098
- query.removeKeys.push(colas);
11140
+ return;
11141
+ }
11142
+
11143
+ toType() {
11144
+ if (
11145
+ ['SUM', 'COUNT', 'AVG', 'MIN', 'MAX', 'AGGR', 'VAR', 'STDDEV'].indexOf(this.aggregatorid) >
11146
+ -1
11147
+ ) {
11148
+ return 'number';
11149
+ }
11150
+
11151
+ if (['ARRAY'].indexOf(this.aggregatorid) > -1) {
11152
+ return 'array';
11153
+ }
11154
+
11155
+ if (['FIRST', 'LAST'].indexOf(this.aggregatorid) > -1) {
11156
+ return this.expression.toType();
11099
11157
  }
11158
+
11159
+ return this.expression.toType();
11100
11160
  }
11101
- query.selectGroup.push(this);
11102
- }
11103
- return;
11104
- };
11105
11161
 
11106
- yy.AggrValue.prototype.toType = function () {
11107
- if (
11108
- ['SUM', 'COUNT', 'AVG', 'MIN', 'MAX', 'AGGR', 'VAR', 'STDDEV'].indexOf(this.aggregatorid) > -1
11109
- ) {
11110
- return 'number';
11162
+ toJS() {
11163
+ var colas = this.nick;
11164
+ if (colas === undefined) {
11165
+ colas = this.toString();
11166
+ }
11167
+ return "g['" + colas + "']";
11168
+ }
11111
11169
  }
11112
11170
 
11113
- if (['ARRAY'].indexOf(this.aggregatorid) > -1) {
11114
- return 'array';
11171
+ class OrderExpression {
11172
+ constructor(params) {
11173
+ assign(this, params);
11174
+ }
11115
11175
  }
11116
11176
 
11117
- if (['FIRST', 'LAST'].indexOf(this.aggregatorid) > -1) {
11118
- return this.expression.toType();
11119
- }
11177
+ OrderExpression.prototype.toString = Expression.prototype.toString;
11120
11178
 
11121
- return this.expression.toType();
11122
- };
11179
+ class GroupExpression {
11180
+ constructor(params) {
11181
+ assign(this, params);
11182
+ }
11123
11183
 
11124
- yy.AggrValue.prototype.toJS = function () {
11125
- var colas = this.nick;
11126
- if (colas === undefined) {
11127
- colas = this.toString();
11184
+ toString() {
11185
+ return this.type + '(' + this.group.toString() + ')';
11186
+ }
11128
11187
  }
11129
- return "g['" + colas + "']";
11130
- };
11131
-
11132
- yy.OrderExpression = function (params) {
11133
- return assign(this, params);
11134
- };
11135
-
11136
- yy.OrderExpression.prototype.toString = yy.Expression.prototype.toString;
11137
11188
 
11138
- yy.GroupExpression = function (params) {
11139
- return assign(this, params);
11140
- };
11141
- yy.GroupExpression.prototype.toString = function () {
11142
- return this.type + '(' + this.group.toString() + ')';
11143
- };
11189
+ assign(yy, {
11190
+ AggrValue,
11191
+ ArrayValue,
11192
+ Column,
11193
+ DomainValueValue,
11194
+ Expression,
11195
+ ExpressionStatement,
11196
+ GroupExpression,
11197
+ JavaScript,
11198
+ Join,
11199
+ Literal,
11200
+ LogicValue,
11201
+ NullValue,
11202
+ NumValue,
11203
+ Op,
11204
+ OrderExpression,
11205
+ ParamValue,
11206
+ StringValue,
11207
+ Table,
11208
+ UniOp,
11209
+ VarValue,
11210
+ View,
11211
+ });
11212
+ }
11144
11213
 
11145
11214
  // Alasql Linq library
11146
11215
 
@@ -12689,7 +12758,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12689
12758
 
12690
12759
  table.update(
12691
12760
  function (t) {
12692
- for (var f in r) t[f] = r[f];
12761
+ for (var f in r) {if(/^__proto__$/.test(f))Object.defineProperty(t,f,{writable:true,enumerable:true,configurable:true});t[f] = r[f];}
12693
12762
  },
12694
12763
  table.data.indexOf(toreplace),
12695
12764
  params
@@ -14263,7 +14332,7 @@ yy.Insert.prototype.compile = function (databaseid) {
14263
14332
  });
14264
14333
  } else {
14265
14334
 
14266
- // sw = 'var w='+JSONtoJS(values)+';for(var k in w){r[k]=w[k]};';
14335
+ // sw = 'var w='+JSONtoJS(values)+';for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
14267
14336
  sw = JSONtoJS(values);
14268
14337
  }
14269
14338
  }