alasql 2.5.1 → 2.5.3

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.fs.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v2.5.0 build: develop-dcdd4683 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.5.2 build: develop-0e8a5557 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.5.0
4
+ @version 2.5.2
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2023 Andrey Gershun & Mathias Wulff
@@ -142,8 +142,8 @@ var alasql = function(sql, params, cb, scope) {
142
142
  Current version of alasql
143
143
  @constant {string}
144
144
  */
145
- alasql.version = '2.5.0';
146
- alasql.build = 'develop-dcdd4683';
145
+ alasql.version = '2.5.2';
146
+ alasql.build = 'develop-0e8a5557';
147
147
 
148
148
  /**
149
149
  Debug flag
@@ -5153,15 +5153,19 @@ Table.prototype.indexColumns = function () {
5153
5153
  */
5154
5154
 
5155
5155
  // Table class
5156
- var View = (alasql.View = function (params) {
5157
- // Columns
5158
- this.columns = [];
5159
- this.xcolumns = {};
5160
- // Data array
5161
- this.query = [];
5156
+ class View {
5157
+ constructor(params) {
5158
+ // Columns
5159
+ this.columns = [];
5160
+ this.xcolumns = {};
5161
+ // Data array
5162
+ this.query = [];
5162
5163
 
5163
- Object.assign(this, params);
5164
- });
5164
+ Object.assign(this, params);
5165
+ }
5166
+ }
5167
+
5168
+ alasql.View = View;
5165
5169
 
5166
5170
  /*
5167
5171
  //
@@ -5176,25 +5180,32 @@ var View = (alasql.View = function (params) {
5176
5180
  /**
5177
5181
  @class Query Main query class
5178
5182
  */
5179
- var Query = (alasql.Query = function (params) {
5180
- this.alasql = alasql;
5183
+ class Query {
5184
+ constructor(params) {
5185
+ this.alasql = alasql;
5181
5186
 
5182
- // Columns
5183
- this.columns = [];
5184
- this.xcolumns = {};
5185
- this.selectGroup = [];
5186
- this.groupColumns = {};
5187
- // Data array
5188
- extend(this, params);
5189
- });
5187
+ // Columns
5188
+ this.columns = [];
5189
+ this.xcolumns = {};
5190
+ this.selectGroup = [];
5191
+ this.groupColumns = {};
5192
+ // Data array
5193
+ Object.assign(this, params);
5194
+ }
5195
+ }
5190
5196
 
5191
5197
  /**
5192
5198
  @class Recordset data object
5193
5199
  */
5194
- var Recordset = (alasql.Recordset = function (params) {
5195
- // Data array
5196
- extend(this, params);
5197
- });
5200
+ class Recordset {
5201
+ constructor(params) {
5202
+ // Data array
5203
+ Object.assign(this, params);
5204
+ }
5205
+ }
5206
+
5207
+ alasql.Recordset = Recordset;
5208
+ alasql.Query = Query;
5198
5209
 
5199
5210
  /*
5200
5211
  //
@@ -7240,388 +7251,420 @@ function swapSources(query, h) {
7240
7251
 
7241
7252
  /* global yy */
7242
7253
 
7243
- yy.Select = function (params) {
7244
- return Object.assign(this, params);
7245
- };
7246
- yy.Select.prototype.toString = function () {
7247
- var s;
7248
- s = '';
7249
- if (this.explain) {
7250
- s += 'EXPLAIN ';
7251
- }
7252
- s += 'SELECT ';
7253
- if (this.modifier) {
7254
- s += this.modifier + ' ';
7255
- }
7256
- if (this.distinct) {
7257
- s += 'DISTINCT ';
7254
+ yy.Select = class Select {
7255
+ constructor(params) {
7256
+ Object.assign(this, params);
7258
7257
  }
7259
- if (this.top) {
7260
- s += 'TOP ' + this.top.value + ' ';
7261
- if (this.percent) {
7262
- s += 'PERCENT ';
7258
+
7259
+ toString() {
7260
+ var s;
7261
+ s = '';
7262
+ if (this.explain) {
7263
+ s += 'EXPLAIN ';
7263
7264
  }
7264
- }
7265
- s += this.columns
7266
- .map(function (col) {
7267
- var s;
7268
- s = col.toString();
7269
- if (typeof col.as !== 'undefined') {
7270
- s += ' AS ' + col.as;
7265
+ s += 'SELECT ';
7266
+ if (this.modifier) {
7267
+ s += this.modifier + ' ';
7268
+ }
7269
+ if (this.distinct) {
7270
+ s += 'DISTINCT ';
7271
+ }
7272
+ if (this.top) {
7273
+ s += 'TOP ' + this.top.value + ' ';
7274
+ if (this.percent) {
7275
+ s += 'PERCENT ';
7271
7276
  }
7272
- return s;
7273
- })
7274
- .join(', ');
7275
- if (this.from) {
7276
- s +=
7277
- ' FROM ' +
7278
- this.from
7279
- .map(function (f) {
7277
+ }
7278
+ s += this.columns
7279
+ .map(function (col) {
7280
+ var s;
7281
+ s = col.toString();
7282
+ if (typeof col.as !== 'undefined') {
7283
+ s += ' AS ' + col.as;
7284
+ }
7285
+ return s;
7286
+ })
7287
+ .join(', ');
7288
+ if (this.from) {
7289
+ s +=
7290
+ ' FROM ' +
7291
+ this.from
7292
+ .map(function (f) {
7293
+ var ss;
7294
+ ss = f.toString();
7295
+ if (f.as) {
7296
+ ss += ' AS ' + f.as;
7297
+ }
7298
+ return ss;
7299
+ })
7300
+ .join(',');
7301
+ }
7302
+ if (this.joins) {
7303
+ s += this.joins
7304
+ .map(function (jn) {
7280
7305
  var ss;
7281
- ss = f.toString();
7282
- if (f.as) {
7283
- ss += ' AS ' + f.as;
7306
+ ss = ' ';
7307
+ if (jn.joinmode) {
7308
+ ss += jn.joinmode + ' ';
7309
+ }
7310
+ if (jn.table) {
7311
+ ss += 'JOIN ' + jn.table.toString();
7312
+ } else if (jn.select) {
7313
+ ss += 'JOIN (' + jn.select.toString() + ')';
7314
+ } else if (jn instanceof alasql.yy.Apply) {
7315
+ ss += jn.toString();
7316
+ } else {
7317
+ throw new Error('Wrong type in JOIN mode');
7318
+ }
7319
+ if (jn.as) {
7320
+ ss += ' AS ' + jn.as;
7321
+ }
7322
+ if (jn.using) {
7323
+ ss += ' USING ' + jn.using.toString();
7324
+ }
7325
+ if (jn.on) {
7326
+ ss += ' ON ' + jn.on.toString();
7284
7327
  }
7285
7328
  return ss;
7286
7329
  })
7287
- .join(',');
7288
- }
7289
- if (this.joins) {
7290
- s += this.joins
7291
- .map(function (jn) {
7292
- var ss;
7293
- ss = ' ';
7294
- if (jn.joinmode) {
7295
- ss += jn.joinmode + ' ';
7296
- }
7297
- if (jn.table) {
7298
- ss += 'JOIN ' + jn.table.toString();
7299
- } else if (jn.select) {
7300
- ss += 'JOIN (' + jn.select.toString() + ')';
7301
- } else if (jn instanceof alasql.yy.Apply) {
7302
- ss += jn.toString();
7303
- } else {
7304
- throw new Error('Wrong type in JOIN mode');
7305
- }
7306
- if (jn.as) {
7307
- ss += ' AS ' + jn.as;
7308
- }
7309
- if (jn.using) {
7310
- ss += ' USING ' + jn.using.toString();
7311
- }
7312
- if (jn.on) {
7313
- ss += ' ON ' + jn.on.toString();
7314
- }
7315
- return ss;
7316
- })
7317
- .join('');
7318
- }
7319
- if (this.where) {
7320
- s += ' WHERE ' + this.where.toString();
7321
- }
7322
- if (this.group && this.group.length > 0) {
7323
- s +=
7324
- ' GROUP BY ' +
7325
- this.group
7326
- .map(function (grp) {
7327
- return grp.toString();
7328
- })
7329
- .join(', ');
7330
- }
7331
- if (this.having) {
7332
- s += ' HAVING ' + this.having.toString();
7333
- }
7334
- if (this.order && this.order.length > 0) {
7335
- s +=
7336
- ' ORDER BY ' +
7337
- this.order
7338
- .map(function (ord) {
7339
- return ord.toString();
7340
- })
7341
- .join(', ');
7342
- }
7343
- if (this.limit) {
7344
- s += ' LIMIT ' + this.limit.value;
7345
- }
7346
- if (this.offset) {
7347
- s += ' OFFSET ' + this.offset.value;
7348
- }
7349
- if (this.union) {
7350
- s += ' UNION ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.union.toString();
7351
- }
7352
- if (this.unionall) {
7353
- s += ' UNION ALL ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.unionall.toString();
7354
- }
7355
- if (this.except) {
7356
- s += ' EXCEPT ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.except.toString();
7357
- }
7358
- if (this.intersect) {
7359
- s += ' INTERSECT ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.intersect.toString();
7330
+ .join('');
7331
+ }
7332
+ if (this.where) {
7333
+ s += ' WHERE ' + this.where.toString();
7334
+ }
7335
+ if (this.group && this.group.length > 0) {
7336
+ s +=
7337
+ ' GROUP BY ' +
7338
+ this.group
7339
+ .map(function (grp) {
7340
+ return grp.toString();
7341
+ })
7342
+ .join(', ');
7343
+ }
7344
+ if (this.having) {
7345
+ s += ' HAVING ' + this.having.toString();
7346
+ }
7347
+ if (this.order && this.order.length > 0) {
7348
+ s +=
7349
+ ' ORDER BY ' +
7350
+ this.order
7351
+ .map(function (ord) {
7352
+ return ord.toString();
7353
+ })
7354
+ .join(', ');
7355
+ }
7356
+ if (this.limit) {
7357
+ s += ' LIMIT ' + this.limit.value;
7358
+ }
7359
+ if (this.offset) {
7360
+ s += ' OFFSET ' + this.offset.value;
7361
+ }
7362
+ if (this.union) {
7363
+ s += ' UNION ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.union.toString();
7364
+ }
7365
+ if (this.unionall) {
7366
+ s += ' UNION ALL ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.unionall.toString();
7367
+ }
7368
+ if (this.except) {
7369
+ s += ' EXCEPT ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.except.toString();
7370
+ }
7371
+ if (this.intersect) {
7372
+ s += ' INTERSECT ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.intersect.toString();
7373
+ }
7374
+ return s;
7360
7375
  }
7361
- return s;
7362
- };
7363
-
7364
- /**
7365
- Select statement in expression
7366
- */
7367
- yy.Select.prototype.toJS = function (context) {
7368
-
7369
- // if(this.expression.reduced) return 'true';
7370
- // return this.expression.toJS(context, tableid, defcols);
7371
7376
 
7372
- // var s = 'this.queriesdata['+(this.queriesidx-1)+'][0]';
7377
+ /**
7378
+ Select statement in expression
7379
+ */
7380
+ toJS(context) {
7373
7381
 
7374
- var s =
7375
- 'alasql.utils.flatArray(this.queriesfn[' +
7376
- (this.queriesidx - 1) +
7377
- '](this.params,null,' +
7378
- context +
7379
- '))[0]';
7382
+ // if(this.expression.reduced) return 'true';
7383
+ // return this.expression.toJS(context, tableid, defcols);
7380
7384
 
7381
- return s;
7382
- };
7385
+ // var s = 'this.queriesdata['+(this.queriesidx-1)+'][0]';
7386
+ var s =
7387
+ 'alasql.utils.flatArray(this.queriesfn[' +
7388
+ (this.queriesidx - 1) +
7389
+ '](this.params,null,' +
7390
+ context +
7391
+ '))[0]';
7383
7392
 
7384
- // Compile SELECT statement
7385
- yy.Select.prototype.compile = function (databaseid, params) {
7386
- var db = alasql.databases[databaseid];
7387
- // Create variable for query
7388
- var query = new Query();
7393
+ return s;
7394
+ }
7389
7395
 
7390
- // Array with columns to be removed
7391
- query.removeKeys = [];
7392
- query.aggrKeys = [];
7396
+ // Compile SELECT statement
7397
+ compile(databaseid, params) {
7398
+ var db = alasql.databases[databaseid];
7399
+ // Create variable for query
7400
+ var query = new Query();
7393
7401
 
7394
- query.explain = this.explain; // Explain
7395
- query.explaination = [];
7396
- query.explid = 1;
7402
+ // Array with columns to be removed
7403
+ query.removeKeys = [];
7404
+ query.aggrKeys = [];
7397
7405
 
7398
- query.modifier = this.modifier;
7406
+ query.explain = this.explain; // Explain
7407
+ query.explaination = [];
7408
+ query.explid = 1;
7399
7409
 
7400
- query.database = db;
7401
- // 0. Precompile whereexists
7402
- this.compileWhereExists(query);
7410
+ query.modifier = this.modifier;
7403
7411
 
7404
- // 0. Precompile queries for IN, NOT IN, ANY and ALL operators
7405
- this.compileQueries(query);
7412
+ query.database = db;
7413
+ // 0. Precompile whereexists
7414
+ this.compileWhereExists(query);
7406
7415
 
7407
- query.defcols = this.compileDefCols(query, databaseid);
7416
+ // 0. Precompile queries for IN, NOT IN, ANY and ALL operators
7417
+ this.compileQueries(query);
7408
7418
 
7409
- // 1. Compile FROM clause
7410
- query.fromfn = this.compileFrom(query);
7419
+ query.defcols = this.compileDefCols(query, databaseid);
7411
7420
 
7412
- // 2. Compile JOIN clauses
7413
- if (this.joins) {
7414
- this.compileJoins(query);
7415
- }
7421
+ // 1. Compile FROM clause
7422
+ query.fromfn = this.compileFrom(query);
7416
7423
 
7417
- // todo?: 3. Compile SELECT clause
7424
+ // 2. Compile JOIN clauses
7425
+ if (this.joins) {
7426
+ this.compileJoins(query);
7427
+ }
7418
7428
 
7419
- // For ROWNUM()
7420
- query.rownums = [];
7429
+ // todo?: 3. Compile SELECT clause
7430
+ // For ROWNUM()
7431
+ query.rownums = [];
7421
7432
 
7422
- this.compileSelectGroup0(query);
7433
+ this.compileSelectGroup0(query);
7423
7434
 
7424
- if (this.group || query.selectGroup.length > 0) {
7425
- query.selectgfns = this.compileSelectGroup1(query);
7426
- } else {
7427
- query.selectfns = this.compileSelect1(query, params);
7428
- }
7435
+ if (this.group || query.selectGroup.length > 0) {
7436
+ query.selectgfns = this.compileSelectGroup1(query);
7437
+ } else {
7438
+ query.selectfns = this.compileSelect1(query, params);
7439
+ }
7429
7440
 
7430
- // Remove columns clause
7431
- this.compileRemoveColumns(query);
7441
+ // Remove columns clause
7442
+ this.compileRemoveColumns(query);
7432
7443
 
7433
- // 5. Optimize WHERE and JOINS
7434
- if (this.where) {
7435
- this.compileWhereJoins(query);
7436
- }
7444
+ // 5. Optimize WHERE and JOINS
7445
+ if (this.where) {
7446
+ this.compileWhereJoins(query);
7447
+ }
7437
7448
 
7438
- // 4. Compile WHERE clause
7439
- query.wherefn = this.compileWhere(query);
7449
+ // 4. Compile WHERE clause
7450
+ query.wherefn = this.compileWhere(query);
7440
7451
 
7441
- // 6. Compile GROUP BY
7442
- if (this.group || query.selectGroup.length > 0) {
7443
- query.groupfn = this.compileGroup(query);
7444
- }
7452
+ // 6. Compile GROUP BY
7453
+ if (this.group || query.selectGroup.length > 0) {
7454
+ query.groupfn = this.compileGroup(query);
7455
+ }
7445
7456
 
7446
- // 6. Compile HAVING
7447
- if (this.having) {
7448
- query.havingfn = this.compileHaving(query);
7449
- }
7457
+ // 6. Compile HAVING
7458
+ if (this.having) {
7459
+ query.havingfn = this.compileHaving(query);
7460
+ }
7450
7461
 
7451
- // 8. Compile ORDER BY clause
7452
- if (this.order) {
7453
- query.orderfn = this.compileOrder(query, params);
7454
- }
7462
+ // 8. Compile ORDER BY clause
7463
+ if (this.order) {
7464
+ query.orderfn = this.compileOrder(query, params);
7465
+ }
7455
7466
 
7456
- if (this.group || query.selectGroup.length > 0) {
7457
- query.selectgfn = this.compileSelectGroup2(query);
7458
- } else {
7459
- query.selectfn = this.compileSelect2(query, params);
7460
- }
7467
+ if (this.group || query.selectGroup.length > 0) {
7468
+ query.selectgfn = this.compileSelectGroup2(query);
7469
+ } else {
7470
+ query.selectfn = this.compileSelect2(query, params);
7471
+ }
7461
7472
 
7462
- // 7. Compile DISTINCT, LIMIT and OFFSET
7463
- query.distinct = this.distinct;
7473
+ // 7. Compile DISTINCT, LIMIT and OFFSET
7474
+ query.distinct = this.distinct;
7464
7475
 
7465
- // 9. Compile PIVOT clause
7466
- if (this.pivot) query.pivotfn = this.compilePivot(query);
7467
- if (this.unpivot) query.pivotfn = this.compileUnpivot(query);
7476
+ // 9. Compile PIVOT clause
7477
+ if (this.pivot) query.pivotfn = this.compilePivot(query);
7478
+ if (this.unpivot) query.pivotfn = this.compileUnpivot(query);
7468
7479
 
7469
- // 10. Compile TOP/LIMIT/OFFSET/FETCH clause
7470
- if (this.top) {
7471
- query.limit = this.top.value;
7472
- } else if (this.limit) {
7473
- query.limit = this.limit.value;
7474
- if (this.offset) {
7475
- query.offset = this.offset.value;
7480
+ // 10. Compile TOP/LIMIT/OFFSET/FETCH clause
7481
+ if (this.top) {
7482
+ query.limit = this.top.value;
7483
+ } else if (this.limit) {
7484
+ query.limit = this.limit.value;
7485
+ if (this.offset) {
7486
+ query.offset = this.offset.value;
7487
+ }
7476
7488
  }
7477
- }
7478
7489
 
7479
- query.percent = this.percent;
7490
+ query.percent = this.percent;
7480
7491
 
7481
- // 9. Compile ordering function for UNION and UNIONALL
7482
- query.corresponding = this.corresponding; // If CORRESPONDING flag exists
7483
- if (this.union) {
7484
- query.unionfn = this.union.compile(databaseid);
7485
- if (this.union.order) {
7486
- query.orderfn = this.union.compileOrder(query, params);
7487
- } else {
7488
- query.orderfn = null;
7489
- }
7490
- } else if (this.unionall) {
7491
- query.unionallfn = this.unionall.compile(databaseid);
7492
- if (this.unionall.order) {
7493
- query.orderfn = this.unionall.compileOrder(query, params);
7494
- } else {
7495
- query.orderfn = null;
7496
- }
7497
- } else if (this.except) {
7498
- query.exceptfn = this.except.compile(databaseid);
7499
- if (this.except.order) {
7500
- query.orderfn = this.except.compileOrder(query, params);
7501
- } else {
7502
- query.orderfn = null;
7503
- }
7504
- } else if (this.intersect) {
7505
- query.intersectfn = this.intersect.compile(databaseid);
7506
- if (this.intersect.order) {
7507
- query.intersectfn = this.intersect.compileOrder(query, params);
7508
- } else {
7509
- query.orderfn = null;
7492
+ // 9. Compile ordering function for UNION and UNIONALL
7493
+ query.corresponding = this.corresponding; // If CORRESPONDING flag exists
7494
+ if (this.union) {
7495
+ query.unionfn = this.union.compile(databaseid);
7496
+ if (this.union.order) {
7497
+ query.orderfn = this.union.compileOrder(query, params);
7498
+ } else {
7499
+ query.orderfn = null;
7500
+ }
7501
+ } else if (this.unionall) {
7502
+ query.unionallfn = this.unionall.compile(databaseid);
7503
+ if (this.unionall.order) {
7504
+ query.orderfn = this.unionall.compileOrder(query, params);
7505
+ } else {
7506
+ query.orderfn = null;
7507
+ }
7508
+ } else if (this.except) {
7509
+ query.exceptfn = this.except.compile(databaseid);
7510
+ if (this.except.order) {
7511
+ query.orderfn = this.except.compileOrder(query, params);
7512
+ } else {
7513
+ query.orderfn = null;
7514
+ }
7515
+ } else if (this.intersect) {
7516
+ query.intersectfn = this.intersect.compile(databaseid);
7517
+ if (this.intersect.order) {
7518
+ query.intersectfn = this.intersect.compileOrder(query, params);
7519
+ } else {
7520
+ query.orderfn = null;
7521
+ }
7510
7522
  }
7511
- }
7512
7523
 
7513
- // SELECT INTO
7514
- if (this.into) {
7515
- if (this.into instanceof yy.Table) {
7516
- //
7517
- // Save into the table in database
7518
- //
7519
- if (
7520
- alasql.options.autocommit &&
7521
- alasql.databases[this.into.databaseid || databaseid].engineid
7522
- ) {
7523
- // For external database when AUTOCOMMIT is ONs
7524
+ // SELECT INTO
7525
+ if (this.into) {
7526
+ if (this.into instanceof yy.Table) {
7527
+ //
7528
+ // Save into the table in database
7529
+ //
7530
+ if (
7531
+ alasql.options.autocommit &&
7532
+ alasql.databases[this.into.databaseid || databaseid].engineid
7533
+ ) {
7534
+ // For external database when AUTOCOMMIT is ONs
7535
+ query.intoallfns =
7536
+ 'return alasql.engines["' +
7537
+ alasql.databases[this.into.databaseid || databaseid].engineid +
7538
+ '"]' +
7539
+ '.intoTable("' +
7540
+ (this.into.databaseid || databaseid) +
7541
+ '","' +
7542
+ this.into.tableid +
7543
+ '",this.data, columns, cb);';
7544
+ } else {
7545
+ // Into AlaSQL tables
7546
+ query.intofns =
7547
+ "alasql.databases['" +
7548
+ (this.into.databaseid || databaseid) +
7549
+ "'].tables" +
7550
+ "['" +
7551
+ this.into.tableid +
7552
+ "'].data.push(r);";
7553
+ }
7554
+ } else if (this.into instanceof yy.VarValue) {
7555
+ //
7556
+ // Save into local variable
7557
+ // SELECT * INTO @VAR1 FROM ?
7558
+ //
7524
7559
  query.intoallfns =
7525
- 'return alasql.engines["' +
7526
- alasql.databases[this.into.databaseid || databaseid].engineid +
7527
- '"]' +
7528
- '.intoTable("' +
7529
- (this.into.databaseid || databaseid) +
7530
- '","' +
7531
- this.into.tableid +
7532
- '",this.data, columns, cb);';
7533
- } else {
7534
- // Into AlaSQL tables
7535
- query.intofns =
7536
- "alasql.databases['" +
7537
- (this.into.databaseid || databaseid) +
7538
- "'].tables" +
7539
- "['" +
7540
- this.into.tableid +
7541
- "'].data.push(r);";
7542
- }
7543
- } else if (this.into instanceof yy.VarValue) {
7544
- //
7545
- // Save into local variable
7546
- // SELECT * INTO @VAR1 FROM ?
7547
- //
7548
- query.intoallfns =
7549
- 'alasql.vars["' +
7550
- this.into.variable +
7551
- '"]=this.data;res=this.data.length;if(cb)res=cb(res);return res;';
7552
- } else if (this.into instanceof yy.FuncValue) {
7553
- //
7554
- // If this is INTO() function, then call it
7555
- // with one or two parameters
7556
- //
7557
- var qs = 'return alasql.into[' + JSON.stringify(this.into.funcid.toUpperCase()) + '](';
7558
- if (this.into.args && this.into.args.length > 0) {
7559
- qs += this.into.args[0].toJS() + ',';
7560
- if (this.into.args.length > 1) {
7561
- qs += this.into.args[1].toJS() + ',';
7560
+ 'alasql.vars["' +
7561
+ this.into.variable +
7562
+ '"]=this.data;res=this.data.length;if(cb)res=cb(res);return res;';
7563
+ } else if (this.into instanceof yy.FuncValue) {
7564
+ //
7565
+ // If this is INTO() function, then call it
7566
+ // with one or two parameters
7567
+ //
7568
+ var qs = 'return alasql.into[' + JSON.stringify(this.into.funcid.toUpperCase()) + '](';
7569
+ if (this.into.args && this.into.args.length > 0) {
7570
+ qs += this.into.args[0].toJS() + ',';
7571
+ if (this.into.args.length > 1) {
7572
+ qs += this.into.args[1].toJS() + ',';
7573
+ } else {
7574
+ qs += 'undefined,';
7575
+ }
7562
7576
  } else {
7563
- qs += 'undefined,';
7577
+ qs += 'undefined, undefined,';
7564
7578
  }
7565
- } else {
7566
- qs += 'undefined, undefined,';
7567
- }
7568
- query.intoallfns = qs + 'this.data,columns,cb)';
7579
+ query.intoallfns = qs + 'this.data,columns,cb)';
7569
7580
 
7570
- } else if (this.into instanceof yy.ParamValue) {
7571
- //
7572
- // Save data into parameters array
7573
- // like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
7574
- //
7575
- query.intofns = "params['" + this.into.param + "'].push(r)";
7576
- }
7581
+ } else if (this.into instanceof yy.ParamValue) {
7582
+ //
7583
+ // Save data into parameters array
7584
+ // like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
7585
+ //
7586
+ query.intofns = "params['" + this.into.param + "'].push(r)";
7587
+ }
7577
7588
 
7578
- if (query.intofns) {
7579
- // Create intofn function
7589
+ if (query.intofns) {
7590
+ // Create intofn function
7580
7591
 
7581
- query.intofn = new Function('r,i,params,alasql', 'var y;' + query.intofns);
7582
- } else if (query.intoallfns) {
7583
- // Create intoallfn function
7592
+ query.intofn = new Function('r,i,params,alasql', 'var y;' + query.intofns);
7593
+ } else if (query.intoallfns) {
7594
+ // Create intoallfn function
7584
7595
 
7585
- query.intoallfn = new Function('columns,cb,params,alasql', 'var y;' + query.intoallfns);
7596
+ query.intoallfn = new Function('columns,cb,params,alasql', 'var y;' + query.intoallfns);
7597
+ }
7586
7598
  }
7587
- }
7588
7599
 
7589
- // Now, compile all togeather into one function with query object in scope
7590
- var statement = function (params, cb, oldscope) {
7591
- query.params = params;
7592
- // Note the callback function has the data and error reversed due to existing code in promiseExec which has the
7593
- // err and data swapped. This trickles down into alasql.exec and further. Rather than risk breaking the whole thing,
7594
- // the (data, err) standard is maintained here.
7595
- var res1 = queryfn(query, oldscope, function (res, err) {
7596
- if (err) {
7597
- return cb(err, null);
7598
- }
7599
- if (query.rownums.length > 0) {
7600
- for (var i = 0, ilen = res.length; i < ilen; i++) {
7601
- for (var j = 0, jlen = query.rownums.length; j < jlen; j++) {
7602
- res[i][query.rownums[j]] = i + 1;
7600
+ // Now, compile all togeather into one function with query object in scope
7601
+ var statement = function (params, cb, oldscope) {
7602
+ query.params = params;
7603
+ // Note the callback function has the data and error reversed due to existing code in promiseExec which has the
7604
+ // err and data swapped. This trickles down into alasql.exec and further. Rather than risk breaking the whole thing,
7605
+ // the (data, err) standard is maintained here.
7606
+ var res1 = queryfn(query, oldscope, function (res, err) {
7607
+ if (err) {
7608
+ return cb(err, null);
7609
+ }
7610
+ if (query.rownums.length > 0) {
7611
+ for (var i = 0, ilen = res.length; i < ilen; i++) {
7612
+ for (var j = 0, jlen = query.rownums.length; j < jlen; j++) {
7613
+ res[i][query.rownums[j]] = i + 1;
7614
+ }
7603
7615
  }
7604
7616
  }
7605
- }
7606
7617
 
7607
- var res2 = modify(query, res);
7618
+ var res2 = modify(query, res);
7608
7619
 
7609
- if (cb) {
7610
- cb(res2);
7611
- }
7620
+ if (cb) {
7621
+ cb(res2);
7622
+ }
7612
7623
 
7613
- return res2;
7614
- });
7624
+ return res2;
7625
+ });
7615
7626
 
7616
- // if(typeof res1 != 'undefined') res1 = modify(query,res1);
7627
+ // if(typeof res1 != 'undefined') res1 = modify(query,res1);
7628
+ return res1;
7629
+ };
7617
7630
 
7618
- return res1;
7619
- };
7631
+ // statement.dbversion = ;
7620
7632
 
7621
- // statement.dbversion = ;
7633
+ statement.query = query;
7634
+ return statement;
7635
+ }
7622
7636
 
7623
- statement.query = query;
7624
- return statement;
7637
+ execute(databaseid, params, cb) {
7638
+ return this.compile(databaseid)(params, cb);
7639
+ // throw new Error('Insert statement is should be compiled')
7640
+ }
7641
+
7642
+ compileWhereExists(query) {
7643
+ if (!this.exists) return;
7644
+ query.existsfn = this.exists.map(function (ex) {
7645
+ var nq = ex.compile(query.database.databaseid);
7646
+
7647
+ // if(!nq.query.modifier) nq.query.modifier = 'RECORDSET';
7648
+ nq.query.modifier = 'RECORDSET';
7649
+ return nq;
7650
+ });
7651
+ }
7652
+
7653
+ compileQueries(query) {
7654
+ if (!this.queries) return;
7655
+ query.queriesfn = this.queries.map(function (q) {
7656
+ var nq = q.compile(query.database.databaseid);
7657
+
7658
+ // if(!nq.query) nq.query = {};
7659
+ nq.query.modifier = 'RECORDSET';
7660
+ // if(!nq.query.modifier) nq.query.modifier = 'RECORDSET';
7661
+ return nq;
7662
+ });
7663
+ }
7664
+
7665
+ // exec(databaseid) {
7666
+ // throw new Error('Select statement should be precompiled');
7667
+ // }
7625
7668
  };
7626
7669
 
7627
7670
  /**
@@ -7751,11 +7794,6 @@ function modify(query, res) {
7751
7794
  return res;
7752
7795
  }
7753
7796
 
7754
- yy.Select.prototype.execute = function (databaseid, params, cb) {
7755
- return this.compile(databaseid)(params, cb);
7756
- // throw new Error('Insert statement is should be compiled')
7757
- };
7758
-
7759
7797
  /*
7760
7798
  //
7761
7799
  // EXISTS and other subqueries functions functions for Alasql.js
@@ -7764,43 +7802,23 @@ yy.Select.prototype.execute = function (databaseid, params, cb) {
7764
7802
  //
7765
7803
  */
7766
7804
 
7767
- yy.ExistsValue = function (params) {
7768
- return Object.assign(this, params);
7769
- };
7770
- yy.ExistsValue.prototype.toString = function () {
7771
- return 'EXISTS(' + this.value.toString() + ')';
7772
- };
7773
-
7774
- yy.ExistsValue.prototype.toType = function () {
7775
- return 'boolean';
7776
- };
7777
-
7778
- yy.ExistsValue.prototype.toJS = function (context, tableid, defcols) {
7779
-
7780
- return 'this.existsfn[' + this.existsidx + '](params,null,' + context + ').data.length';
7781
- };
7805
+ yy.ExistsValue = class ExistsValue {
7806
+ constructor(params) {
7807
+ Object.assign(this, params);
7808
+ }
7782
7809
 
7783
- yy.Select.prototype.compileWhereExists = function (query) {
7784
- if (!this.exists) return;
7785
- query.existsfn = this.exists.map(function (ex) {
7786
- var nq = ex.compile(query.database.databaseid);
7810
+ toString() {
7811
+ return 'EXISTS(' + this.value.toString() + ')';
7812
+ }
7787
7813
 
7788
- // if(!nq.query.modifier) nq.query.modifier = 'RECORDSET';
7789
- nq.query.modifier = 'RECORDSET';
7790
- return nq;
7791
- });
7792
- };
7814
+ toType() {
7815
+ return 'boolean';
7816
+ }
7793
7817
 
7794
- yy.Select.prototype.compileQueries = function (query) {
7795
- if (!this.queries) return;
7796
- query.queriesfn = this.queries.map(function (q) {
7797
- var nq = q.compile(query.database.databaseid);
7818
+ toJS(context, tableid, defcols) {
7798
7819
 
7799
- // if(!nq.query) nq.query = {};
7800
- nq.query.modifier = 'RECORDSET';
7801
- // if(!nq.query.modifier) nq.query.modifier = 'RECORDSET';
7802
- return nq;
7803
- });
7820
+ return 'this.existsfn[' + this.existsidx + '](params,null,' + context + ').data.length';
7821
+ }
7804
7822
  };
7805
7823
 
7806
7824
  //
@@ -8843,25 +8861,27 @@ yy.Select.prototype.compileGroup = function (query) {
8843
8861
  if ('funcid' in col.expression) {
8844
8862
  let colexp1 = colExpIfFunIdExists(col.expression);
8845
8863
  return (
8846
- pre +
8864
+ pre +
8847
8865
  `if(typeof g['${colas}'] == 'string' && !isNaN(g['${colas}']) && typeof Number(g['${colas}']) == 'number' &&
8848
8866
  typeof ${colexp1} == 'string' && !isNaN(${colexp1}) && typeof Number(${colexp1}) == 'number'){g['${colas}'] = Number(g['${colas}']) + Number(${colexp1})}
8849
8867
  else if(typeof g['${colas}'] == 'string' && typeof ${colexp1} == 'string'){g['${colas}'] = 0}
8850
8868
  else if(typeof g['${colas}'] == 'string' && typeof ${colexp1} == 'number'){g['${colas}'] = ${colexp1}}
8851
8869
  else if(typeof ${colexp1} == 'string' && typeof g['${colas}'] == 'number'){g['${colas}'] = g['${colas}']}
8852
- else{g['${colas}'] += ${colexp1}||0}`
8853
- + post
8870
+ else{g['${colas}'] += ${colexp1}||0}` +
8871
+ post
8854
8872
  );
8855
8873
  }
8856
- return pre +
8857
- `if(typeof g['${colas}'] == 'string' && !isNaN(g['${colas}']) && typeof Number(g['${colas}']) == 'number' &&
8874
+ return (
8875
+ pre +
8876
+ `if(typeof g['${colas}'] == 'string' && !isNaN(g['${colas}']) && typeof Number(g['${colas}']) == 'number' &&
8858
8877
  typeof ${colexp} == 'string' && !isNaN(${colexp}) && typeof Number(${colexp}) == 'number'){g['${colas}'] = Number(g['${colas}']) + Number(${colexp})}
8859
8878
  else if(typeof g['${colas}'] == 'string' && typeof ${colexp} == 'string'){g['${colas}'] = 0}
8860
8879
  else if(typeof g['${colas}'] == 'string' && typeof ${colexp} == 'number'){g['${colas}'] = ${colexp}}
8861
8880
  else if(typeof ${colexp} == 'string' && typeof g['${colas}'] == 'number'){g['${colas}'] = g['${colas}']}
8862
- else{g['${colas}'] += ${colexp}||0}`
8863
- + post
8864
- }else if (col.aggregatorid === 'COUNT') {
8881
+ else{g['${colas}'] += ${colexp}||0}` +
8882
+ post
8883
+ );
8884
+ } else if (col.aggregatorid === 'COUNT') {
8865
8885
 
8866
8886
  if (col.expression.columnid === '*') {
8867
8887
  return pre + "g['" + colas + "']++;" + post;
@@ -10122,15 +10142,18 @@ yy.Select.prototype.compileDefCols = function (query, databaseid) {
10122
10142
 
10123
10143
  // SELECT UNION statement
10124
10144
 
10125
- yy.Union = function (params) {
10126
- return Object.assign(this, params);
10127
- };
10128
- yy.Union.prototype.toString = function () {
10129
- return 'UNION';
10130
- };
10145
+ yy.Union = class Union {
10146
+ constructor(params) {
10147
+ Object.assign(this, params);
10148
+ }
10131
10149
 
10132
- yy.Union.prototype.compile = function (tableid) {
10133
- return null;
10150
+ toString() {
10151
+ return 'UNION';
10152
+ }
10153
+
10154
+ compile(tableid) {
10155
+ return null;
10156
+ }
10134
10157
  };
10135
10158
 
10136
10159
  /*
@@ -10141,16 +10164,18 @@ yy.Union.prototype.compile = function (tableid) {
10141
10164
  //
10142
10165
  */
10143
10166
 
10144
- yy.Apply = function (params) {
10145
- return Object.assign(this, params);
10146
- };
10167
+ yy.Apply = class Apply {
10168
+ constructor(params) {
10169
+ Object.assign(this, params);
10170
+ }
10147
10171
 
10148
- yy.Apply.prototype.toString = function () {
10149
- var s = this.applymode + ' APPLY (' + this.select.toString() + ')';
10172
+ toString() {
10173
+ var s = this.applymode + ' APPLY (' + this.select.toString() + ')';
10150
10174
 
10151
- if (this.as) s += ' AS ' + this.as;
10175
+ if (this.as) s += ' AS ' + this.as;
10152
10176
 
10153
- return s;
10177
+ return s;
10178
+ }
10154
10179
  };
10155
10180
 
10156
10181
  /*
@@ -10161,20 +10186,23 @@ yy.Apply.prototype.toString = function () {
10161
10186
  //
10162
10187
  */
10163
10188
 
10164
- yy.Over = function (params) {
10165
- return Object.assign(this, params);
10166
- };
10167
- yy.Over.prototype.toString = function () {
10168
- var s = 'OVER (';
10169
- if (this.partition) {
10170
- s += 'PARTITION BY ' + this.partition.toString();
10171
- if (this.order) s += ' ';
10189
+ yy.Over = class Over {
10190
+ constructor(params) {
10191
+ Object.assign(this, params);
10172
10192
  }
10173
- if (this.order) {
10174
- s += 'ORDER BY ' + this.order.toString();
10193
+
10194
+ toString() {
10195
+ var s = 'OVER (';
10196
+ if (this.partition) {
10197
+ s += 'PARTITION BY ' + this.partition.toString();
10198
+ if (this.order) s += ' ';
10199
+ }
10200
+ if (this.order) {
10201
+ s += 'ORDER BY ' + this.order.toString();
10202
+ }
10203
+ s += ')';
10204
+ return s;
10175
10205
  }
10176
- s += ')';
10177
- return s;
10178
10206
  };
10179
10207
 
10180
10208
  /*
@@ -10574,21 +10602,9 @@ yy.Over.prototype.toString = function () {
10574
10602
  this.right instanceof yy.NullValue ||
10575
10603
  (this.right.op === 'NOT' && this.right.right instanceof yy.NullValue)
10576
10604
  ) {
10577
- s = `(
10578
- (${leftOperand}==null) // Cant be ===
10579
- ===
10580
- (${rightOperand}==null) // Cant be ===
10581
- )`;
10605
+ s = `((${leftOperand} == null) === (${rightOperand} == null))`; // == null cant be ===
10582
10606
  } else {
10583
- s = `(
10584
- (${leftOperand} == ${rightOperand})
10585
- ||
10586
- (
10587
- ${leftOperand} < 0
10588
- &&
10589
- true == ${rightOperand}
10590
- )
10591
- )`;
10607
+ s = `((${leftOperand} == ${rightOperand}) || (${leftOperand} < 0 && true == ${rightOperand}))`;
10592
10608
  }
10593
10609
  }
10594
10610
 
@@ -11165,8 +11181,9 @@ yy.Over.prototype.toString = function () {
11165
11181
 
11166
11182
  toType() {
11167
11183
  if (
11168
- ['SUM', 'COUNT', 'AVG', 'MIN', 'MAX', 'AGGR', 'VAR', 'STDDEV', 'TOTAL'].indexOf(this.aggregatorid) >
11169
- -1
11184
+ ['SUM', 'COUNT', 'AVG', 'MIN', 'MAX', 'AGGR', 'VAR', 'STDDEV', 'TOTAL'].indexOf(
11185
+ this.aggregatorid
11186
+ ) > -1
11170
11187
  ) {
11171
11188
  return 'number';
11172
11189
  }
@@ -14418,6 +14435,9 @@ yy.Insert.prototype.compile = function (databaseid) {
14418
14435
  // INSERT INTO table SELECT
14419
14436
  } else if (this.select) {
14420
14437
  this.select.modifier = 'RECORDSET';
14438
+ if (this.queries) {
14439
+ this.select.queries = this.queries;
14440
+ }
14421
14441
  var selectfn = this.select.compile(databaseid);
14422
14442
  if (db.engineid && alasql.engines[db.engineid].intoTable) {
14423
14443
  var statement = function (params, cb) {