alasql 2.2.1 → 2.2.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.2.0-develop-6cec528a | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.2.2-develop-18f2d048 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.2.0-develop-6cec528a
4
+ @version 2.2.2-develop-18f2d048
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2016 Andrey Gershun & Mathias Rangel Wulff
@@ -142,7 +142,7 @@ var alasql = function(sql, params, cb, scope) {
142
142
  Current version of alasql
143
143
  @constant {string}
144
144
  */
145
- alasql.version = '2.2.0-develop-6cec528a';
145
+ alasql.version = '2.2.2-develop-18f2d048';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -3573,7 +3573,6 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
3573
3573
  }
3574
3574
  };
3575
3575
  xhr.open('GET', path, asy); // Async
3576
- xhr.responseType = 'text';
3577
3576
  xhr.send();
3578
3577
  }
3579
3578
  } else if (path instanceof Event) {
@@ -4935,7 +4934,7 @@ alasql.promise = function (sql, params) {
4935
4934
  // Main Database class
4936
4935
 
4937
4936
  /**
4938
- @class Database
4937
+ @class Database
4939
4938
  */
4940
4939
 
4941
4940
  var Database = (alasql.Database = function (databaseid) {
@@ -5012,85 +5011,95 @@ Database.prototype.autoval = function (tablename, colname, getNext) {
5012
5011
  return alasql.autoval(tablename, colname, getNext, this.databaseid);
5013
5012
  };
5014
5013
 
5014
+ Database.prototype.transaction = function (cb) {
5015
+ var tx = new alasql.Transaction(this.databaseid);
5016
+ var res = cb(tx);
5017
+ return res;
5018
+ };
5019
+
5015
5020
  // Aliases like MS SQL
5016
5021
 
5017
5022
  /*
5018
5023
  //
5019
- // Transactio class for Alasql.js
5024
+ // Transaction class for Alasql.js
5020
5025
  // Date: 03.11.2014
5021
5026
  // (c) 2014, Andrey Gershun
5022
5027
  //
5023
5028
  */
5024
5029
 
5025
- Database.prototype.transaction = function (cb) {
5026
- var tx = new alasql.Transaction(this.databaseid);
5027
- var res = cb(tx);
5028
- return res;
5029
- };
5030
-
5031
- // Transaction class (for WebSQL compatibility)
5030
+ class Transaction {
5031
+ transactionid = Date.now();
5032
5032
 
5033
- /**
5034
- Transaction class
5035
- @class Transaction
5036
- */
5033
+ committed = false;
5037
5034
 
5038
- var Transaction = (alasql.Transaction = function (databaseid) {
5039
- this.transactionid = Date.now();
5040
- this.databaseid = databaseid;
5041
- this.commited = false;
5042
- this.dbversion = alasql.databases[databaseid].dbversion;
5043
- // this.bank = cloneDeep(alasql.databases[databaseid]);
5044
- this.bank = JSON.stringify(alasql.databases[databaseid]);
5045
- // TODO CLone Tables with insertfns
5035
+ /** @type {string | undefined} */
5036
+ bank;
5046
5037
 
5047
- return this;
5048
- });
5038
+ constructor(databaseid) {
5039
+ this.databaseid = databaseid;
5040
+ this.dbversion = alasql.databases[databaseid].dbversion;
5041
+ // this.bank = structuredClone(alasql.databases[databaseid]);
5042
+ this.bank = JSON.stringify(alasql.databases[databaseid]);
5043
+ // TODO CLone Tables with insertfns
5044
+ }
5049
5045
 
5050
- // Main class
5046
+ /** Commit transaction */
5047
+ commit() {
5048
+ this.committed = true;
5049
+ alasql.databases[this.databaseid].dbversion = Date.now();
5050
+ delete this.bank;
5051
+ }
5051
5052
 
5052
- // Commit
5053
+ /** Rollback transaction */
5054
+ rollback() {
5055
+ if (!this.committed) {
5056
+ alasql.databases[this.databaseid] = JSON.parse(this.bank);
5057
+ // alasql.databases[this.databaseid].tables = this.bank;
5058
+ // alasql.databases[this.databaseid].dbversion = this.dbversion;
5059
+ delete this.bank;
5060
+ } else {
5061
+ throw new Error('Transaction already commited');
5062
+ }
5063
+ }
5053
5064
 
5054
- /**
5055
- Commit transaction
5056
- */
5057
- Transaction.prototype.commit = function () {
5058
- this.commited = true;
5059
- alasql.databases[this.databaseid].dbversion = Date.now();
5060
- delete this.bank;
5061
- };
5065
+ /**
5066
+ * Execute SQL statement
5067
+ * @param {string} sql SQL statement
5068
+ * @param {object} params Parameters
5069
+ * @param {function} cb Callback function
5070
+ * @return result
5071
+ */
5072
+ exec(sql, params, cb) {
5073
+ return alasql.dexec(this.databaseid, sql, params, cb);
5074
+ }
5062
5075
 
5063
- // Rollback
5064
- /**
5065
- Rollback transaction
5066
- */
5067
- Transaction.prototype.rollback = function () {
5068
- if (!this.commited) {
5069
- alasql.databases[this.databaseid] = JSON.parse(this.bank);
5070
- // alasql.databases[this.databaseid].tables = this.bank;
5071
- // alasql.databases[this.databaseid].dbversion = this.dbversion;
5072
- delete this.bank;
5073
- } else {
5074
- throw new Error('Transaction already commited');
5076
+ /*
5077
+ queryArray (sql, params, cb) {
5078
+ return flatArray(this.exec(sql, params, cb));
5075
5079
  }
5076
- };
5077
5080
 
5078
- // Transactions stub
5081
+ queryArrayOfArrays (sql, params, cb) {
5082
+ return arrayOfArrays(this.exec(sql, params, cb));
5083
+ }
5079
5084
 
5080
- /**
5081
- Execute SQL statement
5082
- @param {string} sql SQL statement
5083
- @param {object} params Parameters
5084
- @param {function} cb Callback function
5085
- @return result
5086
- */
5087
- Transaction.prototype.exec = function (sql, params, cb) {
5085
+ querySingle (sql, params, cb) {
5086
+ return this.exec(sql, params, cb)[0];
5087
+ }
5088
5088
 
5089
- return alasql.dexec(this.databaseid, sql, params, cb);
5090
- };
5089
+ queryValue (sql, params, cb) {
5090
+ var res = this.querySingle(sql, params, cb);
5091
+ return res[Object.keys(res)[0]];
5092
+ }
5093
+ */
5094
+ }
5091
5095
 
5092
5096
  Transaction.prototype.executeSQL = Transaction.prototype.exec;
5093
5097
 
5098
+ // Transaction.prototype.query = Database.prototype.exec;
5099
+ // Transaction.prototype.run = Database.prototype.exec;
5100
+
5101
+ alasql.Transaction = Transaction;
5102
+
5094
5103
  /*
5095
5104
  //
5096
5105
  // Table class for Alasql.js
@@ -5138,7 +5147,7 @@ var Table = (alasql.Table = function (params) {
5138
5147
  this.insteadofupdate = {};
5139
5148
 
5140
5149
  // Done
5141
- extend(this, params);
5150
+ Object.assign(this, params);
5142
5151
  });
5143
5152
 
5144
5153
  Table.prototype.indexColumns = function () {
@@ -5165,7 +5174,7 @@ var View = (alasql.View = function (params) {
5165
5174
  // Data array
5166
5175
  this.query = [];
5167
5176
 
5168
- extend(this, params);
5177
+ Object.assign(this, params);
5169
5178
  });
5170
5179
 
5171
5180
  /*
@@ -5209,27 +5218,29 @@ var Recordset = (alasql.Recordset = function (params) {
5209
5218
  //
5210
5219
  */
5211
5220
 
5212
- var yy = (alasqlparser.yy = alasql.yy = {});
5213
-
5214
- // Utility
5215
- yy.extend = extend;
5216
- // Option for case sensitive
5217
- yy.casesensitive = alasql.options.casesensitive;
5218
-
5219
5221
  // Base class for all yy classes
5220
- var Base = (yy.Base = function (params) {
5221
- return yy.extend(this, params);
5222
- });
5222
+ class Base {
5223
+ constructor(params) {
5224
+ Object.assign(this, params);
5225
+ }
5226
+ toString() {}
5227
+ toType() {}
5228
+ toJS() {}
5229
+ exec() {}
5230
+ compile() {}
5231
+ }
5223
5232
 
5224
- Base.prototype.toString = function () {};
5225
- Base.prototype.toType = function () {};
5226
- Base.prototype.toJS = function () {};
5233
+ var yy = {
5234
+ // Utility
5235
+ /** @deprecated use `Object.assign` instead */
5236
+ extend: Object.assign,
5227
5237
 
5228
- Base.prototype.compile = returnUndefined;
5229
- Base.prototype.exec = function () {};
5238
+ // Option for case sensitive
5239
+ casesensitive: alasql.options.casesensitive,
5240
+ Base,
5241
+ };
5230
5242
 
5231
- Base.prototype.compile = returnUndefined;
5232
- Base.prototype.exec = function () {};
5243
+ alasqlparser.yy = alasql.yy = yy;
5233
5244
 
5234
5245
  /*
5235
5246
  //
@@ -5239,36 +5250,25 @@ Base.prototype.exec = function () {};
5239
5250
  //
5240
5251
  */
5241
5252
 
5242
- // Statements container
5243
- yy.Statements = function (params) {
5244
- return yy.extend(this, params);
5245
- };
5253
+ yy.Statements = class Statements {
5254
+ constructor(params) {
5255
+ Object.assign(this, params);
5256
+ }
5246
5257
 
5247
- yy.Statements.prototype.toString = function () {
5248
- return this.statements
5249
- .map(function (st) {
5250
- return st.toString();
5251
- })
5252
- .join('; ');
5253
- };
5258
+ toString() {
5259
+ return this.statements.map((st) => st.toString()).join('; ');
5260
+ }
5254
5261
 
5255
- // Compile array of statements into single statement
5256
- yy.Statements.prototype.compile = function (db) {
5257
- var statements = this.statements.map(function (st) {
5258
- return st.compile(db);
5259
- });
5260
- if (statements.length === 1) {
5261
- return statements[0];
5262
- } else {
5263
- return function (params, cb) {
5264
- var res = statements.map(function (st) {
5265
- return st(params);
5266
- });
5267
- if (cb) {
5268
- cb(res);
5269
- }
5270
- return res;
5271
- };
5262
+ // Compile array of statements into single statement
5263
+ compile(db) {
5264
+ const statements = this.statements.map((st) => st.compile(db));
5265
+ return statements.length === 1
5266
+ ? statements[0]
5267
+ : (params, cb) => {
5268
+ const res = statements.map((st) => st(params));
5269
+ if (cb) cb(res);
5270
+ return res;
5271
+ };
5272
5272
  }
5273
5273
  };
5274
5274
 
@@ -5282,1078 +5282,1051 @@ yy.Statements.prototype.compile = function (db) {
5282
5282
  //
5283
5283
  */
5284
5284
 
5285
- function doSearch(databaseid, params, cb) {
5286
- var res;
5287
- var stope = {};
5288
- var fromdata;
5289
- var selectors = cloneDeep(this.selectors);
5285
+ /**
5286
+ Search class
5287
+ @example
5288
+ SEARCH SUM(/a) FROM ? -- search over parameter object
5289
+ */
5290
5290
 
5291
- function processSelector(selectors, sidx, value) {
5292
- // var val;
5291
+ yy.Search = class Search {
5292
+ constructor(params) {
5293
+ Object.assign(this, params);
5294
+ }
5293
5295
 
5294
- var val, // temp values use many places
5295
- nest, // temp value used many places
5296
- r, // temp value used many places
5297
- sel = selectors[sidx];
5296
+ toString() {
5297
+ let s = 'SEARCH ';
5298
+ if (this.selectors) s += this.selectors.toString();
5299
+ if (this.from) s += 'FROM ' + this.from.toString();
5300
+ return s;
5301
+ }
5298
5302
 
5299
- // if(!alasql.srch[sel.srchid]) {
5300
- // throw new Error('Selector "'+sel.srchid+'" not found');
5301
- // };
5303
+ toJS(context) {
5304
+ const s = `this.queriesfn[${this.queriesidx - 1}](this.params,null,${context})`;
5305
+ return s;
5306
+ }
5302
5307
 
5303
- var INFINITE_LOOP_BREAK = alasql.options.loopbreak || 100000;
5304
-
5305
- if (sel.selid) {
5306
- // TODO Process Selector
5307
- if (sel.selid === 'PATH') {
5308
- var queue = [{node: value, stack: []}];
5309
- var visited = {};
5310
- //var path = [];
5311
- var objects = alasql.databases[alasql.useid].objects;
5312
- while (queue.length > 0) {
5313
- var q = queue.shift();
5314
- var node = q.node;
5315
- var stack = q.stack;
5316
- var r = processSelector(sel.args, 0, node);
5317
- if (r.length > 0) {
5318
- if (sidx + 1 + 1 > selectors.length) {
5319
- return stack;
5320
- } else {
5321
- var rv = [];
5322
- if (stack && stack.length > 0) {
5323
- stack.forEach(function (stv) {
5324
- rv = rv.concat(processSelector(selectors, sidx + 1, stv));
5325
- });
5308
+ compile(databaseid) {
5309
+ var dbid = databaseid;
5310
+
5311
+ var statement = (params, cb) => {
5312
+ var res;
5313
+ this.#doSearch(dbid, params, function (data) {
5314
+ res = modify(statement.query, data);
5315
+ if (cb) res = cb(res);
5316
+ });
5317
+ // if(cb) res = cb(res);
5318
+ return res;
5319
+ };
5320
+ statement.query = {};
5321
+ return statement;
5322
+ }
5323
+
5324
+ #doSearch(databaseid, params, cb) {
5325
+ var res;
5326
+ var stope = {};
5327
+ var fromdata;
5328
+ var selectors = cloneDeep(this.selectors);
5329
+
5330
+ function processSelector(selectors, sidx, value) {
5331
+ // var val;
5332
+
5333
+ var val, // temp values use many places
5334
+ nest, // temp value used many places
5335
+ r, // temp value used many places
5336
+ sel = selectors[sidx];
5337
+
5338
+ // if(!alasql.srch[sel.srchid]) {
5339
+ // throw new Error('Selector "'+sel.srchid+'" not found');
5340
+ // };
5341
+
5342
+ var INFINITE_LOOP_BREAK = alasql.options.loopbreak || 100000;
5343
+
5344
+ if (sel.selid) {
5345
+ // TODO Process Selector
5346
+ if (sel.selid === 'PATH') {
5347
+ var queue = [{node: value, stack: []}];
5348
+ var visited = {};
5349
+ //var path = [];
5350
+ var objects = alasql.databases[alasql.useid].objects;
5351
+ while (queue.length > 0) {
5352
+ var q = queue.shift();
5353
+ var node = q.node;
5354
+ var stack = q.stack;
5355
+ var r = processSelector(sel.args, 0, node);
5356
+ if (r.length > 0) {
5357
+ if (sidx + 1 + 1 > selectors.length) {
5358
+ return stack;
5359
+ } else {
5360
+ var rv = [];
5361
+ if (stack && stack.length > 0) {
5362
+ stack.forEach(function (stv) {
5363
+ rv = rv.concat(processSelector(selectors, sidx + 1, stv));
5364
+ });
5365
+ }
5366
+ return rv;
5367
+ // return processSelector(selectors,sidx+1,stack);
5326
5368
  }
5327
- return rv;
5328
- // return processSelector(selectors,sidx+1,stack);
5329
- }
5330
- } else {
5331
- if (typeof visited[node.$id] !== 'undefined') {
5332
- continue;
5333
5369
  } else {
5370
+ if (typeof visited[node.$id] !== 'undefined') {
5371
+ continue;
5372
+ } else {
5334
5373
 
5335
- visited[node.$id] = true;
5336
- if (node.$out && node.$out.length > 0) {
5337
- node.$out.forEach(function (edgeid) {
5338
- var edge = objects[edgeid];
5339
- var stack2 = stack.concat(edge);
5340
- stack2.push(objects[edge.$out[0]]);
5341
- queue.push({
5342
- node: objects[edge.$out[0]],
5343
- stack: stack2,
5374
+ visited[node.$id] = true;
5375
+ if (node.$out && node.$out.length > 0) {
5376
+ node.$out.forEach(function (edgeid) {
5377
+ var edge = objects[edgeid];
5378
+ var stack2 = stack.concat(edge);
5379
+ stack2.push(objects[edge.$out[0]]);
5380
+ queue.push({
5381
+ node: objects[edge.$out[0]],
5382
+ stack: stack2,
5383
+ });
5344
5384
  });
5345
- });
5385
+ }
5346
5386
  }
5347
5387
  }
5348
5388
  }
5389
+ // Else return fail
5390
+ return [];
5349
5391
  }
5350
- // Else return fail
5351
- return [];
5352
- }
5353
- if (sel.selid === 'NOT') {
5354
- var nest = processSelector(sel.args, 0, value);
5392
+ if (sel.selid === 'NOT') {
5393
+ var nest = processSelector(sel.args, 0, value);
5355
5394
 
5356
- if (nest.length > 0) {
5357
- return [];
5358
- } else {
5359
- if (sidx + 1 + 1 > selectors.length) {
5360
- return [value];
5395
+ if (nest.length > 0) {
5396
+ return [];
5361
5397
  } else {
5362
- return processSelector(selectors, sidx + 1, value);
5398
+ if (sidx + 1 + 1 > selectors.length) {
5399
+ return [value];
5400
+ } else {
5401
+ return processSelector(selectors, sidx + 1, value);
5402
+ }
5363
5403
  }
5364
- }
5365
- } else if (sel.selid === 'DISTINCT') {
5366
- var nest;
5367
- if (typeof sel.args === 'undefined' || sel.args.length === 0) {
5368
- nest = distinctArray(value);
5369
- } else {
5370
- nest = processSelector(sel.args, 0, value);
5371
- }
5372
- if (nest.length === 0) {
5373
- return [];
5374
- } else {
5375
- var res = distinctArray(nest);
5376
- if (sidx + 1 + 1 > selectors.length) {
5377
- return res;
5404
+ } else if (sel.selid === 'DISTINCT') {
5405
+ var nest;
5406
+ if (typeof sel.args === 'undefined' || sel.args.length === 0) {
5407
+ nest = distinctArray(value);
5378
5408
  } else {
5379
- return processSelector(selectors, sidx + 1, res);
5409
+ nest = processSelector(sel.args, 0, value);
5380
5410
  }
5381
- }
5382
- } else if (sel.selid === 'AND') {
5383
- var res = true;
5384
- sel.args.forEach(function (se) {
5385
- res = res && processSelector(se, 0, value).length > 0;
5386
- });
5387
- if (!res) {
5388
- return [];
5389
- } else {
5390
- if (sidx + 1 + 1 > selectors.length) {
5391
- return [value];
5411
+ if (nest.length === 0) {
5412
+ return [];
5392
5413
  } else {
5393
- return processSelector(selectors, sidx + 1, value);
5414
+ var res = distinctArray(nest);
5415
+ if (sidx + 1 + 1 > selectors.length) {
5416
+ return res;
5417
+ } else {
5418
+ return processSelector(selectors, sidx + 1, res);
5419
+ }
5394
5420
  }
5395
- }
5396
- } else if (sel.selid === 'OR') {
5397
- var res = false;
5398
- sel.args.forEach(function (se) {
5399
- res = res || processSelector(se, 0, value).length > 0;
5400
- });
5401
- if (!res) {
5402
- return [];
5403
- } else {
5404
- if (sidx + 1 + 1 > selectors.length) {
5405
- return [value];
5421
+ } else if (sel.selid === 'AND') {
5422
+ var res = true;
5423
+ sel.args.forEach(function (se) {
5424
+ res = res && processSelector(se, 0, value).length > 0;
5425
+ });
5426
+ if (!res) {
5427
+ return [];
5406
5428
  } else {
5407
- return processSelector(selectors, sidx + 1, value);
5429
+ if (sidx + 1 + 1 > selectors.length) {
5430
+ return [value];
5431
+ } else {
5432
+ return processSelector(selectors, sidx + 1, value);
5433
+ }
5408
5434
  }
5409
- }
5410
- } else if (sel.selid === 'ALL') {
5411
- var nest = processSelector(sel.args[0], 0, value);
5412
- if (nest.length === 0) {
5413
- return [];
5414
- } else {
5415
- if (sidx + 1 + 1 > selectors.length) {
5416
- return nest;
5435
+ } else if (sel.selid === 'OR') {
5436
+ var res = false;
5437
+ sel.args.forEach(function (se) {
5438
+ res = res || processSelector(se, 0, value).length > 0;
5439
+ });
5440
+ if (!res) {
5441
+ return [];
5417
5442
  } else {
5418
- return processSelector(selectors, sidx + 1, nest);
5443
+ if (sidx + 1 + 1 > selectors.length) {
5444
+ return [value];
5445
+ } else {
5446
+ return processSelector(selectors, sidx + 1, value);
5447
+ }
5419
5448
  }
5420
- }
5421
- } else if (sel.selid === 'ANY') {
5422
- var nest = processSelector(sel.args[0], 0, value);
5423
-
5424
- if (nest.length === 0) {
5425
- return [];
5426
- } else {
5427
- if (sidx + 1 + 1 > selectors.length) {
5428
- return [nest[0]];
5449
+ } else if (sel.selid === 'ALL') {
5450
+ var nest = processSelector(sel.args[0], 0, value);
5451
+ if (nest.length === 0) {
5452
+ return [];
5429
5453
  } else {
5430
- return processSelector(selectors, sidx + 1, [nest[0]]);
5454
+ if (sidx + 1 + 1 > selectors.length) {
5455
+ return nest;
5456
+ } else {
5457
+ return processSelector(selectors, sidx + 1, nest);
5458
+ }
5431
5459
  }
5432
- }
5433
- } else if (sel.selid === 'UNIONALL') {
5434
- var nest = [];
5435
- sel.args.forEach(function (se) {
5436
- nest = nest.concat(processSelector(se, 0, value));
5437
- });
5438
- if (nest.length === 0) {
5439
- return [];
5440
- } else {
5441
- if (sidx + 1 + 1 > selectors.length) {
5442
- return nest;
5460
+ } else if (sel.selid === 'ANY') {
5461
+ var nest = processSelector(sel.args[0], 0, value);
5462
+ if (nest.length === 0) {
5463
+ return [];
5443
5464
  } else {
5444
- return processSelector(selectors, sidx + 1, nest);
5465
+ if (sidx + 1 + 1 > selectors.length) {
5466
+ return [nest[0]];
5467
+ } else {
5468
+ return processSelector(selectors, sidx + 1, [nest[0]]);
5469
+ }
5445
5470
  }
5446
- }
5447
- } else if (sel.selid === 'UNION') {
5448
- var nest = [];
5449
- sel.args.forEach(function (se) {
5450
- nest = nest.concat(processSelector(se, 0, value));
5451
- });
5452
- var nest = distinctArray(nest);
5453
- if (nest.length === 0) {
5454
- return [];
5455
- } else {
5456
- if (sidx + 1 + 1 > selectors.length) {
5457
- return nest;
5471
+ } else if (sel.selid === 'UNIONALL') {
5472
+ var nest = [];
5473
+ sel.args.forEach(function (se) {
5474
+ nest = nest.concat(processSelector(se, 0, value));
5475
+ });
5476
+ if (nest.length === 0) {
5477
+ return [];
5458
5478
  } else {
5459
- return processSelector(selectors, sidx + 1, nest);
5479
+ if (sidx + 1 + 1 > selectors.length) {
5480
+ return nest;
5481
+ } else {
5482
+ return processSelector(selectors, sidx + 1, nest);
5483
+ }
5460
5484
  }
5461
- }
5462
- } else if (sel.selid === 'IF') {
5463
- var nest = processSelector(sel.args, 0, value);
5464
-
5465
- if (nest.length === 0) {
5466
- return [];
5467
- } else {
5468
- if (sidx + 1 + 1 > selectors.length) {
5469
- return [value];
5485
+ } else if (sel.selid === 'UNION') {
5486
+ var nest = [];
5487
+ sel.args.forEach(function (se) {
5488
+ nest = nest.concat(processSelector(se, 0, value));
5489
+ });
5490
+ var nest = distinctArray(nest);
5491
+ if (nest.length === 0) {
5492
+ return [];
5470
5493
  } else {
5471
- return processSelector(selectors, sidx + 1, value);
5494
+ if (sidx + 1 + 1 > selectors.length) {
5495
+ return nest;
5496
+ } else {
5497
+ return processSelector(selectors, sidx + 1, nest);
5498
+ }
5472
5499
  }
5473
- }
5474
- } else if (sel.selid === 'REPEAT') {
5475
-
5476
- var lvar,
5477
- lmax,
5478
- lmin = sel.args[0].value;
5479
- if (!sel.args[1]) {
5480
- lmax = lmin; // Add security break
5481
- } else {
5482
- lmax = sel.args[1].value;
5483
- }
5484
- if (sel.args[2]) {
5485
- lvar = sel.args[2].variable;
5486
- }
5487
- //var lsel = sel.sels;
5500
+ } else if (sel.selid === 'IF') {
5501
+ var nest = processSelector(sel.args, 0, value);
5488
5502
 
5489
- var retval = [];
5490
-
5491
- if (lmin === 0) {
5492
- if (sidx + 1 + 1 > selectors.length) {
5493
- retval = [value];
5503
+ if (nest.length === 0) {
5504
+ return [];
5494
5505
  } else {
5495
- if (lvar) {
5496
- alasql.vars[lvar] = 0;
5506
+ if (sidx + 1 + 1 > selectors.length) {
5507
+ return [value];
5508
+ } else {
5509
+ return processSelector(selectors, sidx + 1, value);
5497
5510
  }
5498
- retval = retval.concat(processSelector(selectors, sidx + 1, value));
5499
5511
  }
5500
- }
5512
+ } else if (sel.selid === 'REPEAT') {
5501
5513
 
5502
- // var nests = processSelector(sel.sels,0,value).slice();
5503
- if (lmax > 0) {
5504
- var nests = [{value: value, lvl: 1}];
5514
+ var lvar,
5515
+ lmax,
5516
+ lmin = sel.args[0].value;
5517
+ if (!sel.args[1]) {
5518
+ lmax = lmin; // Add security break
5519
+ } else {
5520
+ lmax = sel.args[1].value;
5521
+ }
5522
+ if (sel.args[2]) {
5523
+ lvar = sel.args[2].variable;
5524
+ }
5525
+ //var lsel = sel.sels;
5505
5526
 
5506
- var i = 0;
5507
- while (nests.length > 0) {
5508
- var nest = nests[0];
5527
+ var retval = [];
5509
5528
 
5510
- nests.shift();
5511
- if (nest.lvl <= lmax) {
5529
+ if (lmin === 0) {
5530
+ if (sidx + 1 + 1 > selectors.length) {
5531
+ retval = [value];
5532
+ } else {
5512
5533
  if (lvar) {
5513
- alasql.vars[lvar] = nest.lvl;
5534
+ alasql.vars[lvar] = 0;
5514
5535
  }
5536
+ retval = retval.concat(processSelector(selectors, sidx + 1, value));
5537
+ }
5538
+ }
5515
5539
 
5516
- var nest1 = processSelector(sel.sels, 0, nest.value);
5540
+ // var nests = processSelector(sel.sels,0,value).slice();
5541
+ if (lmax > 0) {
5542
+ var nests = [{value: value, lvl: 1}];
5517
5543
 
5518
- nest1.forEach(function (n) {
5519
- nests.push({value: n, lvl: nest.lvl + 1});
5520
- });
5521
- if (nest.lvl >= lmin) {
5522
- if (sidx + 1 + 1 > selectors.length) {
5523
- retval = retval.concat(nest1);
5524
- //return nests;
5525
- } else {
5526
- nest1.forEach(function (n) {
5527
- retval = retval.concat(processSelector(selectors, sidx + 1, n));
5528
- });
5544
+ var i = 0;
5545
+ while (nests.length > 0) {
5546
+ var nest = nests[0];
5547
+
5548
+ nests.shift();
5549
+ if (nest.lvl <= lmax) {
5550
+ if (lvar) {
5551
+ alasql.vars[lvar] = nest.lvl;
5552
+ }
5553
+
5554
+ var nest1 = processSelector(sel.sels, 0, nest.value);
5555
+
5556
+ nest1.forEach(function (n) {
5557
+ nests.push({value: n, lvl: nest.lvl + 1});
5558
+ });
5559
+ if (nest.lvl >= lmin) {
5560
+ if (sidx + 1 + 1 > selectors.length) {
5561
+ retval = retval.concat(nest1);
5562
+ //return nests;
5563
+ } else {
5564
+ nest1.forEach(function (n) {
5565
+ retval = retval.concat(processSelector(selectors, sidx + 1, n));
5566
+ });
5567
+ }
5529
5568
  }
5530
5569
  }
5531
- }
5532
- // Security brake
5533
- i++;
5534
- if (i > INFINITE_LOOP_BREAK) {
5535
- throw new Error('Infinite loop brake. Number of iterations = ' + i);
5570
+ // Security brake
5571
+ i++;
5572
+ if (i > INFINITE_LOOP_BREAK) {
5573
+ throw new Error('Infinite loop brake. Number of iterations = ' + i);
5574
+ }
5536
5575
  }
5537
5576
  }
5538
- }
5539
- return retval;
5540
- } else if (sel.selid === 'OF') {
5541
- if (sidx + 1 + 1 > selectors.length) {
5542
- return [value];
5543
- } else {
5544
- var r1 = [];
5545
- Object.keys(value).forEach(function (keyv) {
5546
- alasql.vars[sel.args[0].variable] = keyv;
5547
- r1 = r1.concat(processSelector(selectors, sidx + 1, value[keyv]));
5548
- });
5549
- return r1;
5550
- }
5551
- } else if (sel.selid === 'TO') {
5577
+ return retval;
5578
+ } else if (sel.selid === 'OF') {
5579
+ if (sidx + 1 + 1 > selectors.length) {
5580
+ return [value];
5581
+ } else {
5582
+ var r1 = [];
5583
+ Object.keys(value).forEach(function (keyv) {
5584
+ alasql.vars[sel.args[0].variable] = keyv;
5585
+ r1 = r1.concat(processSelector(selectors, sidx + 1, value[keyv]));
5586
+ });
5587
+ return r1;
5588
+ }
5589
+ } else if (sel.selid === 'TO') {
5552
5590
 
5553
- var oldv = alasql.vars[sel.args[0]];
5554
- var newv = [];
5555
- if (oldv !== undefined) {
5591
+ var oldv = alasql.vars[sel.args[0]];
5592
+ var newv = [];
5593
+ if (oldv !== undefined) {
5556
5594
 
5557
- newv = oldv.slice(0);
5595
+ newv = oldv.slice(0);
5558
5596
 
5559
- } else {
5560
- newv = [];
5561
- }
5562
- newv.push(value);
5597
+ } else {
5598
+ newv = [];
5599
+ }
5600
+ newv.push(value);
5563
5601
 
5564
- if (sidx + 1 + 1 > selectors.length) {
5565
- return [value];
5566
- } else {
5567
- alasql.vars[sel.args[0]] = newv;
5568
- var r1 = processSelector(selectors, sidx + 1, value);
5602
+ if (sidx + 1 + 1 > selectors.length) {
5603
+ return [value];
5604
+ } else {
5605
+ alasql.vars[sel.args[0]] = newv;
5606
+ var r1 = processSelector(selectors, sidx + 1, value);
5569
5607
 
5570
- alasql.vars[sel.args[0]] = oldv;
5571
- return r1;
5572
- }
5608
+ alasql.vars[sel.args[0]] = oldv;
5609
+ return r1;
5610
+ }
5573
5611
 
5574
- } else if (sel.selid === 'ARRAY') {
5575
- var nest = processSelector(sel.args, 0, value);
5576
- if (nest.length > 0) {
5577
- val = nest;
5578
- } else {
5579
- return [];
5580
- }
5581
- if (sidx + 1 + 1 > selectors.length) {
5582
- return [val];
5583
- } else {
5584
- return processSelector(selectors, sidx + 1, val);
5585
- }
5586
- } else if (sel.selid === 'SUM') {
5587
- var nest = processSelector(sel.args, 0, value);
5588
- if (nest.length > 0) {
5589
- var val = nest.reduce(function (sum, current) {
5590
- return sum + current;
5591
- }, 0);
5592
- } else {
5593
- return [];
5594
- }
5595
- if (sidx + 1 + 1 > selectors.length) {
5596
- return [val];
5597
- } else {
5598
- return processSelector(selectors, sidx + 1, val);
5599
- }
5600
- } else if (sel.selid === 'AVG') {
5601
- nest = processSelector(sel.args, 0, value);
5602
- if (nest.length > 0) {
5603
- val =
5604
- nest.reduce(function (sum, current) {
5612
+ } else if (sel.selid === 'ARRAY') {
5613
+ var nest = processSelector(sel.args, 0, value);
5614
+ if (nest.length > 0) {
5615
+ val = nest;
5616
+ } else {
5617
+ return [];
5618
+ }
5619
+ if (sidx + 1 + 1 > selectors.length) {
5620
+ return [val];
5621
+ } else {
5622
+ return processSelector(selectors, sidx + 1, val);
5623
+ }
5624
+ } else if (sel.selid === 'SUM') {
5625
+ var nest = processSelector(sel.args, 0, value);
5626
+ if (nest.length > 0) {
5627
+ var val = nest.reduce(function (sum, current) {
5605
5628
  return sum + current;
5606
- }, 0) / nest.length;
5607
- } else {
5608
- return [];
5609
- }
5610
- if (sidx + 1 + 1 > selectors.length) {
5611
- return [val];
5612
- } else {
5613
- return processSelector(selectors, sidx + 1, val);
5614
- }
5615
- } else if (sel.selid === 'COUNT') {
5616
- nest = processSelector(sel.args, 0, value);
5617
- if (nest.length > 0) {
5618
- val = nest.length;
5619
- } else {
5620
- return [];
5621
- }
5622
- if (sidx + 1 + 1 > selectors.length) {
5623
- return [val];
5624
- } else {
5625
- return processSelector(selectors, sidx + 1, val);
5626
- }
5627
- } else if (sel.selid === 'FIRST') {
5628
- nest = processSelector(sel.args, 0, value);
5629
- if (nest.length > 0) {
5630
- val = nest[0];
5631
- } else {
5632
- return [];
5633
- }
5629
+ }, 0);
5630
+ } else {
5631
+ return [];
5632
+ }
5633
+ if (sidx + 1 + 1 > selectors.length) {
5634
+ return [val];
5635
+ } else {
5636
+ return processSelector(selectors, sidx + 1, val);
5637
+ }
5638
+ } else if (sel.selid === 'AVG') {
5639
+ nest = processSelector(sel.args, 0, value);
5640
+ if (nest.length > 0) {
5641
+ val =
5642
+ nest.reduce(function (sum, current) {
5643
+ return sum + current;
5644
+ }, 0) / nest.length;
5645
+ } else {
5646
+ return [];
5647
+ }
5648
+ if (sidx + 1 + 1 > selectors.length) {
5649
+ return [val];
5650
+ } else {
5651
+ return processSelector(selectors, sidx + 1, val);
5652
+ }
5653
+ } else if (sel.selid === 'COUNT') {
5654
+ nest = processSelector(sel.args, 0, value);
5655
+ if (nest.length > 0) {
5656
+ val = nest.length;
5657
+ } else {
5658
+ return [];
5659
+ }
5660
+ if (sidx + 1 + 1 > selectors.length) {
5661
+ return [val];
5662
+ } else {
5663
+ return processSelector(selectors, sidx + 1, val);
5664
+ }
5665
+ } else if (sel.selid === 'FIRST') {
5666
+ nest = processSelector(sel.args, 0, value);
5667
+ if (nest.length > 0) {
5668
+ val = nest[0];
5669
+ } else {
5670
+ return [];
5671
+ }
5634
5672
 
5635
- if (sidx + 1 + 1 > selectors.length) {
5636
- return [val];
5637
- } else {
5638
- return processSelector(selectors, sidx + 1, val);
5639
- }
5640
- } else if (sel.selid === 'LAST') {
5641
- nest = processSelector(sel.args, 0, value);
5642
- if (nest.length > 0) {
5643
- val = nest[nest.length - 1];
5644
- } else {
5645
- return [];
5646
- }
5673
+ if (sidx + 1 + 1 > selectors.length) {
5674
+ return [val];
5675
+ } else {
5676
+ return processSelector(selectors, sidx + 1, val);
5677
+ }
5678
+ } else if (sel.selid === 'LAST') {
5679
+ nest = processSelector(sel.args, 0, value);
5680
+ if (nest.length > 0) {
5681
+ val = nest[nest.length - 1];
5682
+ } else {
5683
+ return [];
5684
+ }
5647
5685
 
5648
- if (sidx + 1 + 1 > selectors.length) {
5649
- return [val];
5650
- } else {
5651
- return processSelector(selectors, sidx + 1, val);
5652
- }
5653
- } else if (sel.selid === 'MIN') {
5654
- nest = processSelector(sel.args, 0, value);
5655
- if (nest.length === 0) {
5656
- return [];
5657
- }
5658
- var val = nest.reduce(function (min, current) {
5659
- return Math.min(min, current);
5660
- }, Infinity);
5661
- if (sidx + 1 + 1 > selectors.length) {
5662
- return [val];
5663
- } else {
5664
- return processSelector(selectors, sidx + 1, val);
5665
- }
5666
- } else if (sel.selid === 'MAX') {
5667
- var nest = processSelector(sel.args, 0, value);
5668
- if (nest.length === 0) {
5669
- return [];
5670
- }
5671
- var val = nest.reduce(function (max, current) {
5672
- return Math.max(max, current);
5673
- }, -Infinity);
5674
- if (sidx + 1 + 1 > selectors.length) {
5675
- return [val];
5676
- } else {
5677
- return processSelector(selectors, sidx + 1, val);
5678
- }
5679
- } else if (sel.selid === 'PLUS') {
5680
- var retval = [];
5681
- // retval = retval.concat(processSelector(selectors,sidx+1,n))
5682
- var nests = processSelector(sel.args, 0, value).slice();
5683
- if (sidx + 1 + 1 > selectors.length) {
5684
- retval = retval.concat(nests);
5685
- } else {
5686
- nests.forEach(function (n) {
5687
- retval = retval.concat(processSelector(selectors, sidx + 1, n));
5688
- });
5689
- }
5686
+ if (sidx + 1 + 1 > selectors.length) {
5687
+ return [val];
5688
+ } else {
5689
+ return processSelector(selectors, sidx + 1, val);
5690
+ }
5691
+ } else if (sel.selid === 'MIN') {
5692
+ nest = processSelector(sel.args, 0, value);
5693
+ if (nest.length === 0) {
5694
+ return [];
5695
+ }
5696
+ var val = nest.reduce(function (min, current) {
5697
+ return Math.min(min, current);
5698
+ }, Infinity);
5699
+ if (sidx + 1 + 1 > selectors.length) {
5700
+ return [val];
5701
+ } else {
5702
+ return processSelector(selectors, sidx + 1, val);
5703
+ }
5704
+ } else if (sel.selid === 'MAX') {
5705
+ var nest = processSelector(sel.args, 0, value);
5706
+ if (nest.length === 0) {
5707
+ return [];
5708
+ }
5709
+ var val = nest.reduce(function (max, current) {
5710
+ return Math.max(max, current);
5711
+ }, -Infinity);
5712
+ if (sidx + 1 + 1 > selectors.length) {
5713
+ return [val];
5714
+ } else {
5715
+ return processSelector(selectors, sidx + 1, val);
5716
+ }
5717
+ } else if (sel.selid === 'PLUS') {
5718
+ var retval = [];
5719
+ // retval = retval.concat(processSelector(selectors,sidx+1,n))
5720
+ var nests = processSelector(sel.args, 0, value).slice();
5721
+ if (sidx + 1 + 1 > selectors.length) {
5722
+ retval = retval.concat(nests);
5723
+ } else {
5724
+ nests.forEach(function (n) {
5725
+ retval = retval.concat(processSelector(selectors, sidx + 1, n));
5726
+ });
5727
+ }
5690
5728
 
5691
- var i = 0;
5692
- while (nests.length > 0) {
5693
- // nest = nests[0];
5694
- // nests.shift();
5695
- var nest = nests.shift();
5729
+ var i = 0;
5730
+ while (nests.length > 0) {
5731
+ // nest = nests[0];
5732
+ // nests.shift();
5733
+ var nest = nests.shift();
5696
5734
 
5697
- nest = processSelector(sel.args, 0, nest);
5735
+ nest = processSelector(sel.args, 0, nest);
5698
5736
 
5699
- nests = nests.concat(nest);
5737
+ nests = nests.concat(nest);
5700
5738
 
5701
- if (sidx + 1 + 1 > selectors.length) {
5702
- retval = retval.concat(nest);
5703
- //return retval;
5704
- } else {
5705
- nest.forEach(function (n) {
5739
+ if (sidx + 1 + 1 > selectors.length) {
5740
+ retval = retval.concat(nest);
5741
+ //return retval;
5742
+ } else {
5743
+ nest.forEach(function (n) {
5706
5744
 
5707
- var rn = processSelector(selectors, sidx + 1, n);
5745
+ var rn = processSelector(selectors, sidx + 1, n);
5708
5746
 
5709
- retval = retval.concat(rn);
5710
- });
5747
+ retval = retval.concat(rn);
5748
+ });
5749
+ }
5750
+
5751
+ // Security brake
5752
+ i++;
5753
+ if (i > INFINITE_LOOP_BREAK) {
5754
+ throw new Error('Infinite loop brake. Number of iterations = ' + i);
5755
+ }
5711
5756
  }
5757
+ return retval;
5712
5758
 
5713
- // Security brake
5714
- i++;
5715
- if (i > INFINITE_LOOP_BREAK) {
5716
- throw new Error('Infinite loop brake. Number of iterations = ' + i);
5759
+ } else if (sel.selid === 'STAR') {
5760
+ var retval = [];
5761
+ retval = processSelector(selectors, sidx + 1, value);
5762
+ var nests = processSelector(sel.args, 0, value).slice();
5763
+ if (sidx + 1 + 1 > selectors.length) {
5764
+ retval = retval.concat(nests);
5765
+ //return nests;
5766
+ } else {
5767
+ nests.forEach(function (n) {
5768
+ retval = retval.concat(processSelector(selectors, sidx + 1, n));
5769
+ });
5717
5770
  }
5718
- }
5719
- return retval;
5771
+ var i = 0;
5772
+ while (nests.length > 0) {
5773
+ var nest = nests[0];
5774
+ nests.shift();
5720
5775
 
5721
- } else if (sel.selid === 'STAR') {
5722
- var retval = [];
5723
- retval = processSelector(selectors, sidx + 1, value);
5724
- var nests = processSelector(sel.args, 0, value).slice();
5725
- if (sidx + 1 + 1 > selectors.length) {
5726
- retval = retval.concat(nests);
5727
- //return nests;
5728
- } else {
5729
- nests.forEach(function (n) {
5730
- retval = retval.concat(processSelector(selectors, sidx + 1, n));
5731
- });
5732
- }
5733
- var i = 0;
5734
- while (nests.length > 0) {
5735
- var nest = nests[0];
5736
- nests.shift();
5776
+ nest = processSelector(sel.args, 0, nest);
5737
5777
 
5738
- nest = processSelector(sel.args, 0, nest);
5778
+ nests = nests.concat(nest);
5739
5779
 
5740
- nests = nests.concat(nest);
5780
+ if (sidx + 1 + 1 <= selectors.length) {
5781
+ nest.forEach(function (n) {
5782
+ retval = retval.concat(processSelector(selectors, sidx + 1, n));
5783
+ });
5784
+ }
5785
+
5786
+ // Security brake
5787
+ i++;
5788
+ if (i > INFINITE_LOOP_BREAK) {
5789
+ throw new Error('Infinite loop brake. Number of iterations = ' + i);
5790
+ }
5791
+ }
5741
5792
 
5793
+ return retval;
5794
+ } else if (sel.selid === 'QUESTION') {
5795
+ var retval = [];
5796
+ retval = retval.concat(processSelector(selectors, sidx + 1, value));
5797
+ var nest = processSelector(sel.args, 0, value);
5742
5798
  if (sidx + 1 + 1 <= selectors.length) {
5743
5799
  nest.forEach(function (n) {
5744
5800
  retval = retval.concat(processSelector(selectors, sidx + 1, n));
5745
5801
  });
5746
5802
  }
5803
+ return retval;
5804
+ } else if (sel.selid === 'WITH') {
5805
+ var nest = processSelector(sel.args, 0, value);
5747
5806
 
5748
- // Security brake
5749
- i++;
5750
- if (i > INFINITE_LOOP_BREAK) {
5751
- throw new Error('Infinite loop brake. Number of iterations = ' + i);
5752
- }
5753
- }
5754
-
5755
- return retval;
5756
- } else if (sel.selid === 'QUESTION') {
5757
- var retval = [];
5758
- retval = retval.concat(processSelector(selectors, sidx + 1, value));
5759
- var nest = processSelector(sel.args, 0, value);
5760
- if (sidx + 1 + 1 <= selectors.length) {
5761
- nest.forEach(function (n) {
5762
- retval = retval.concat(processSelector(selectors, sidx + 1, n));
5763
- });
5764
- }
5765
- return retval;
5766
- } else if (sel.selid === 'WITH') {
5767
- var nest = processSelector(sel.args, 0, value);
5768
-
5769
- if (nest.length === 0) {
5770
- return [];
5771
- } else {
5807
+ if (nest.length === 0) {
5808
+ return [];
5809
+ } else {
5772
5810
 
5773
- var r = {status: 1, values: nest};
5774
- }
5775
- } else if (sel.selid === 'ROOT') {
5776
- if (sidx + 1 + 1 > selectors.length) {
5777
- return [value];
5811
+ var r = {status: 1, values: nest};
5812
+ }
5813
+ } else if (sel.selid === 'ROOT') {
5814
+ if (sidx + 1 + 1 > selectors.length) {
5815
+ return [value];
5816
+ } else {
5817
+ return processSelector(selectors, sidx + 1, fromdata);
5818
+ }
5778
5819
  } else {
5779
- return processSelector(selectors, sidx + 1, fromdata);
5820
+ throw new Error('Wrong selector ' + sel.selid);
5780
5821
  }
5822
+ } else if (sel.srchid) {
5823
+ var r = alasql.srch[sel.srchid.toUpperCase()](value, sel.args, stope, params);
5824
+
5781
5825
  } else {
5782
- throw new Error('Wrong selector ' + sel.selid);
5826
+ throw new Error('Selector not found');
5783
5827
  }
5784
- } else if (sel.srchid) {
5785
- var r = alasql.srch[sel.srchid.toUpperCase()](value, sel.args, stope, params);
5786
-
5787
- } else {
5788
- throw new Error('Selector not found');
5789
- }
5790
5828
 
5791
- if (typeof r === 'undefined') {
5792
- r = {status: 1, values: [value]};
5793
- }
5829
+ if (typeof r === 'undefined') {
5830
+ r = {status: 1, values: [value]};
5831
+ }
5794
5832
 
5795
- var res = [];
5796
- if (r.status === 1) {
5797
- var arr = r.values;
5833
+ var res = [];
5834
+ if (r.status === 1) {
5835
+ var arr = r.values;
5798
5836
 
5799
- if (sidx + 1 + 1 > selectors.length) {
5800
- // if(sidx+1+1 > selectors.length) {
5801
- res = arr;
5837
+ if (sidx + 1 + 1 > selectors.length) {
5838
+ // if(sidx+1+1 > selectors.length) {
5839
+ res = arr;
5802
5840
 
5803
- } else {
5804
- for (var i = 0; i < r.values.length; i++) {
5805
- res = res.concat(processSelector(selectors, sidx + 1, arr[i]));
5841
+ } else {
5842
+ for (var i = 0; i < r.values.length; i++) {
5843
+ res = res.concat(processSelector(selectors, sidx + 1, arr[i]));
5844
+ }
5806
5845
  }
5807
5846
  }
5847
+ return res;
5808
5848
  }
5809
- return res;
5810
- }
5811
5849
 
5812
- if (selectors !== undefined && selectors.length > 0) {
5850
+ if (selectors !== undefined && selectors.length > 0) {
5813
5851
 
5814
- if (
5815
- selectors &&
5816
- selectors[0] &&
5817
- selectors[0].srchid === 'PROP' &&
5818
- selectors[0].args &&
5819
- selectors[0].args[0]
5820
- ) {
5852
+ if (
5853
+ selectors &&
5854
+ selectors[0] &&
5855
+ selectors[0].srchid === 'PROP' &&
5856
+ selectors[0].args &&
5857
+ selectors[0].args[0]
5858
+ ) {
5821
5859
 
5822
- if (selectors[0].args[0].toUpperCase() === 'XML') {
5823
- stope.mode = 'XML';
5824
- selectors.shift();
5825
- } else if (selectors[0].args[0].toUpperCase() === 'HTML') {
5826
- stope.mode = 'HTML';
5827
- selectors.shift();
5828
- } else if (selectors[0].args[0].toUpperCase() === 'JSON') {
5829
- stope.mode = 'JSON';
5860
+ if (selectors[0].args[0].toUpperCase() === 'XML') {
5861
+ stope.mode = 'XML';
5862
+ selectors.shift();
5863
+ } else if (selectors[0].args[0].toUpperCase() === 'HTML') {
5864
+ stope.mode = 'HTML';
5865
+ selectors.shift();
5866
+ } else if (selectors[0].args[0].toUpperCase() === 'JSON') {
5867
+ stope.mode = 'JSON';
5868
+ selectors.shift();
5869
+ }
5870
+ }
5871
+ if (selectors.length > 0 && selectors[0].srchid === 'VALUE') {
5872
+ stope.value = true;
5830
5873
  selectors.shift();
5831
5874
  }
5832
5875
  }
5833
- if (selectors.length > 0 && selectors[0].srchid === 'VALUE') {
5834
- stope.value = true;
5835
- selectors.shift();
5836
- }
5837
- }
5838
5876
 
5839
- if (this.from instanceof yy.Column) {
5840
- var dbid = this.from.databaseid || databaseid;
5841
- fromdata = alasql.databases[dbid].tables[this.from.columnid].data;
5842
- //selectors.unshift({srchid:'CHILD'});
5843
- } else if (this.from instanceof yy.FuncValue && alasql.from[this.from.funcid.toUpperCase()]) {
5844
- var args = this.from.args.map(function (arg) {
5845
- var as = arg.toJS();
5877
+ if (this.from instanceof yy.Column) {
5878
+ var dbid = this.from.databaseid || databaseid;
5879
+ fromdata = alasql.databases[dbid].tables[this.from.columnid].data;
5880
+ //selectors.unshift({srchid:'CHILD'});
5881
+ } else if (this.from instanceof yy.FuncValue && alasql.from[this.from.funcid.toUpperCase()]) {
5882
+ var args = this.from.args.map(function (arg) {
5883
+ var as = arg.toJS();
5846
5884
 
5847
- var fn = new Function('params,alasql', 'var y;return ' + as).bind(this);
5848
- return fn(params, alasql);
5849
- });
5850
-
5851
- fromdata = alasql.from[this.from.funcid.toUpperCase()].apply(this, args);
5852
-
5853
- } else if (typeof this.from === 'undefined') {
5854
- fromdata = alasql.databases[databaseid].objects;
5855
- } else {
5856
- var fromfn = new Function('params,alasql', 'var y;return ' + this.from.toJS());
5857
- fromdata = fromfn(params, alasql);
5858
- // Check for Mogo Collections
5859
- if (
5860
- typeof Mongo === 'object' &&
5861
- typeof Mongo.Collection !== 'object' &&
5862
- fromdata instanceof Mongo.Collection
5863
- ) {
5864
- fromdata = fromdata.find().fetch();
5865
- }
5866
-
5867
- // if(typeof fromdata == 'object' && Array.isArray(fromdata)) {
5868
- // selectors.unshift({srchid:'CHILD'});
5869
- // }
5870
- }
5871
-
5872
- // If source data is array than first step is to run over array
5873
- // var selidx = 0;
5874
- // var selvalue = fromdata;
5875
-
5876
- if (selectors !== undefined && selectors.length > 0) {
5877
- // Init variables for TO() selectors
5878
-
5879
- if (false) {
5880
- selectors.forEach(function (selector) {
5881
- if (selector.srchid === 'TO') {
5882
- //* @todo move to TO selector
5883
- alasql.vars[selector.args[0]] = [];
5884
- // TODO - process nested selectors
5885
- }
5885
+ var fn = new Function('params,alasql', 'var y;return ' + as).bind(this);
5886
+ return fn(params, alasql);
5886
5887
  });
5887
- }
5888
-
5889
- res = processSelector(selectors, 0, fromdata);
5890
- } else {
5891
- res = fromdata;
5892
- }
5893
5888
 
5894
- if (this.into) {
5895
- var a1, a2;
5896
- if (typeof this.into.args[0] !== 'undefined') {
5897
- a1 = new Function('params,alasql', 'var y;return ' + this.into.args[0].toJS())(
5898
- params,
5899
- alasql
5900
- );
5901
- }
5902
- if (typeof this.into.args[1] !== 'undefined') {
5903
- a2 = new Function('params,alasql', 'var y;return ' + this.into.args[1].toJS())(
5904
- params,
5905
- alasql
5906
- );
5907
- }
5908
- res = alasql.into[this.into.funcid.toUpperCase()](a1, a2, res, [], cb);
5909
- } else {
5910
- if (stope.value && res.length > 0) {
5911
- res = res[0];
5912
- }
5913
- if (cb) {
5914
- res = cb(res);
5915
- }
5916
- }
5917
- return res;
5918
- }
5889
+ fromdata = alasql.from[this.from.funcid.toUpperCase()].apply(this, args);
5919
5890
 
5920
- /**
5921
- Search class
5922
- @class
5923
- @example
5924
- SEARCH SUM(/a) FROM ? -- search over parameter object
5925
- */
5926
-
5927
- yy.Search = function (params) {
5928
- return yy.extend(this, params);
5929
- };
5930
-
5931
- yy.Search.prototype.toString = function () {
5932
- var s = 'SEARCH' + ' ';
5933
- if (this.selectors) {
5934
- s += this.selectors.toString();
5935
- }
5936
- if (this.from) {
5937
- s += 'FROM' + ' ' + this.from.toString();
5938
- }
5939
-
5940
- return s;
5941
- };
5942
-
5943
- yy.Search.prototype.toJS = function (context) {
5944
-
5945
- var s = 'this.queriesfn[' + (this.queriesidx - 1) + '](this.params,null,' + context + ')';
5946
- // var s = '';
5947
- return s;
5948
- };
5949
-
5950
- yy.Search.prototype.compile = function (databaseid) {
5951
- var dbid = databaseid;
5952
- var self = this;
5953
-
5954
- var statement = function (params, cb) {
5955
-
5956
- var res;
5957
- doSearch.bind(self)(dbid, params, function (data) {
5958
-
5959
- res = modify(statement.query, data);
5960
-
5961
- if (cb) {
5962
- res = cb(res);
5891
+ } else if (typeof this.from === 'undefined') {
5892
+ fromdata = alasql.databases[databaseid].objects;
5893
+ } else {
5894
+ var fromfn = new Function('params,alasql', 'var y;return ' + this.from.toJS());
5895
+ fromdata = fromfn(params, alasql);
5896
+ // Check for Mogo Collections
5897
+ if (
5898
+ typeof Mongo === 'object' &&
5899
+ typeof Mongo.Collection !== 'object' &&
5900
+ fromdata instanceof Mongo.Collection
5901
+ ) {
5902
+ fromdata = fromdata.find().fetch();
5963
5903
  }
5964
- });
5965
5904
 
5966
- // if(cb) res = cb(res);
5967
- return res;
5968
- };
5969
- statement.query = {};
5970
- return statement;
5971
- };
5905
+ // if(typeof fromdata == 'object' && Array.isArray(fromdata)) {
5906
+ // selectors.unshift({srchid:'CHILD'});
5907
+ // }
5908
+ }
5972
5909
 
5973
- // List of search functions
5974
- alasql.srch = {};
5910
+ // If source data is array than first step is to run over array
5911
+ // var selidx = 0;
5912
+ // var selvalue = fromdata;
5975
5913
 
5976
- alasql.srch.PROP = function (val, args, stope) {
5914
+ if (selectors !== undefined && selectors.length > 0) {
5915
+ // Init variables for TO() selectors
5977
5916
 
5978
- if (stope.mode === 'XML') {
5979
- var arr = [];
5980
- val.children.forEach(function (v) {
5981
- if (v.name.toUpperCase() === args[0].toUpperCase()) {
5982
- arr.push(v);
5917
+ if (false) {
5918
+ selectors.forEach(function (selector) {
5919
+ if (selector.srchid === 'TO') {
5920
+ //* @todo move to TO selector
5921
+ alasql.vars[selector.args[0]] = [];
5922
+ // TODO - process nested selectors
5923
+ }
5924
+ });
5983
5925
  }
5984
- });
5985
- if (arr.length > 0) {
5986
- return {status: 1, values: arr};
5926
+
5927
+ res = processSelector(selectors, 0, fromdata);
5987
5928
  } else {
5988
- return {status: -1, values: []};
5929
+ res = fromdata;
5989
5930
  }
5990
- } else {
5991
- if (
5992
- typeof val !== 'object' ||
5993
- val === null ||
5994
- typeof args !== 'object' ||
5995
- typeof val[args[0]] === 'undefined'
5996
- ) {
5997
- return {status: -1, values: []};
5931
+
5932
+ if (this.into) {
5933
+ var a1, a2;
5934
+ if (typeof this.into.args[0] !== 'undefined') {
5935
+ a1 = new Function('params,alasql', 'var y;return ' + this.into.args[0].toJS())(
5936
+ params,
5937
+ alasql
5938
+ );
5939
+ }
5940
+ if (typeof this.into.args[1] !== 'undefined') {
5941
+ a2 = new Function('params,alasql', 'var y;return ' + this.into.args[1].toJS())(
5942
+ params,
5943
+ alasql
5944
+ );
5945
+ }
5946
+ res = alasql.into[this.into.funcid.toUpperCase()](a1, a2, res, [], cb);
5998
5947
  } else {
5999
- return {status: 1, values: [val[args[0]]]};
5948
+ if (stope.value && res.length > 0) {
5949
+ res = res[0];
5950
+ }
5951
+ if (cb) {
5952
+ res = cb(res);
5953
+ }
6000
5954
  }
5955
+ return res;
6001
5956
  }
6002
5957
  };
6003
5958
 
6004
- alasql.srch.APROP = function (val, args) {
6005
- if (
6006
- typeof val !== 'object' ||
6007
- val === null ||
6008
- typeof args !== 'object' ||
6009
- typeof val[args[0]] === 'undefined'
6010
- ) {
6011
- return {status: 1, values: [undefined]};
6012
- } else {
6013
- return {status: 1, values: [val[args[0]]]};
6014
- }
6015
- };
6016
-
6017
- // Test expression
6018
- alasql.srch.EQ = function (val, args, stope, params) {
6019
- var exprs = args[0].toJS('x', '');
6020
- var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6021
- if (val === exprfn(val, alasql, params)) {
6022
- return {status: 1, values: [val]};
6023
- } else {
6024
- return {status: -1, values: []};
6025
- }
6026
- };
5959
+ // List of search functions
5960
+ alasql.srch = {
5961
+ PROP(val, args, stope) {
6027
5962
 
6028
- // Test expression
6029
- alasql.srch.LIKE = function (val, args, stope, params) {
6030
- var exprs = args[0].toJS('x', '');
6031
- var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6032
- if (
6033
- val
6034
- .toUpperCase()
6035
- .match(
6036
- new RegExp(
6037
- '^' +
6038
- exprfn(val, alasql, params).toUpperCase().replace(/%/g, '.*').replace(/\?|_/g, '.') +
6039
- '$'
6040
- ),
6041
- 'g'
6042
- )
6043
- ) {
6044
- return {status: 1, values: [val]};
6045
- } else {
6046
- return {status: -1, values: []};
6047
- }
6048
- };
5963
+ if (stope.mode === 'XML') {
5964
+ const values = val.children.filter((v) => v.name.toUpperCase() === args[0].toUpperCase());
6049
5965
 
6050
- alasql.srch.ATTR = function (val, args, stope) {
6051
- if (stope.mode === 'XML') {
6052
- if (typeof args === 'undefined') {
6053
- return {status: 1, values: [val.attributes]};
5966
+ return {
5967
+ status: values.length ? 1 : -1,
5968
+ values,
5969
+ };
6054
5970
  } else {
6055
5971
  if (
6056
- typeof val === 'object' &&
6057
- typeof val.attributes === 'object' &&
6058
- typeof val.attributes[args[0]] !== 'undefined'
5972
+ typeof val !== 'object' ||
5973
+ val === null ||
5974
+ typeof args !== 'object' ||
5975
+ typeof val[args[0]] === 'undefined'
6059
5976
  ) {
6060
- return {status: 1, values: [val.attributes[args[0]]]};
6061
- } else {
6062
5977
  return {status: -1, values: []};
5978
+ } else {
5979
+ return {status: 1, values: [val[args[0]]]};
6063
5980
  }
6064
5981
  }
6065
- } else {
6066
- throw new Error('ATTR is not using in usual mode');
6067
- }
6068
- };
6069
-
6070
- alasql.srch.CONTENT = function (val, args, stope) {
6071
- if (stope.mode === 'XML') {
6072
- return {status: 1, values: [val.content]};
6073
- } else {
6074
- throw new Error('ATTR is not using in usual mode');
6075
- }
6076
- };
6077
-
6078
- alasql.srch.SHARP = function (val, args) {
6079
- var obj = alasql.databases[alasql.useid].objects[args[0]];
6080
- if (typeof val !== 'undefined' && val === obj) {
6081
- return {status: 1, values: [val]};
6082
- } else {
6083
- return {status: -1, values: []};
6084
- }
6085
- };
5982
+ },
6086
5983
 
6087
- alasql.srch.PARENT = function (/*val,args,stope*/) {
6088
- // TODO: implement
6089
- console.error('PARENT not implemented', arguments);
6090
-
6091
- return {status: -1, values: []};
6092
- };
5984
+ APROP(val, args) {
5985
+ if (
5986
+ typeof val !== 'object' ||
5987
+ val === null ||
5988
+ typeof args !== 'object' ||
5989
+ typeof val[args[0]] === 'undefined'
5990
+ ) {
5991
+ return {status: 1, values: [undefined]};
5992
+ } else {
5993
+ return {status: 1, values: [val[args[0]]]};
5994
+ }
5995
+ },
6093
5996
 
6094
- alasql.srch.CHILD = function (val, args, stope) {
5997
+ EQ(val, args, stope, params) {
5998
+ var exprs = args[0].toJS('x', '');
5999
+ var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6000
+ if (val === exprfn(val, alasql, params)) {
6001
+ return {status: 1, values: [val]};
6002
+ } else {
6003
+ return {status: -1, values: []};
6004
+ }
6005
+ },
6095
6006
 
6096
- if (typeof val === 'object') {
6097
- if (Array.isArray(val)) {
6098
- return {status: 1, values: val};
6007
+ // Test expression
6008
+ LIKE(val, args, stope, params) {
6009
+ var exprs = args[0].toJS('x', '');
6010
+ var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6011
+ if (
6012
+ val
6013
+ .toUpperCase()
6014
+ .match(
6015
+ new RegExp(
6016
+ '^' +
6017
+ exprfn(val, alasql, params).toUpperCase().replace(/%/g, '.*').replace(/\?|_/g, '.') +
6018
+ '$'
6019
+ ),
6020
+ 'g'
6021
+ )
6022
+ ) {
6023
+ return {status: 1, values: [val]};
6099
6024
  } else {
6100
- if (stope.mode === 'XML') {
6101
- return {
6102
- status: 1,
6103
- values: Object.keys(val.children).map(function (key) {
6104
- return val.children[key];
6105
- }),
6106
- };
6025
+ return {status: -1, values: []};
6026
+ }
6027
+ },
6028
+
6029
+ ATTR(val, args, stope) {
6030
+ if (stope.mode === 'XML') {
6031
+ if (typeof args === 'undefined') {
6032
+ return {status: 1, values: [val.attributes]};
6107
6033
  } else {
6108
- return {
6109
- status: 1,
6110
- values: Object.keys(val).map(function (key) {
6111
- return val[key];
6112
- }),
6113
- };
6034
+ if (
6035
+ typeof val === 'object' &&
6036
+ typeof val.attributes === 'object' &&
6037
+ typeof val.attributes[args[0]] !== 'undefined'
6038
+ ) {
6039
+ return {status: 1, values: [val.attributes[args[0]]]};
6040
+ } else {
6041
+ return {status: -1, values: []};
6042
+ }
6114
6043
  }
6044
+ } else {
6045
+ throw new Error('ATTR is not using in usual mode');
6115
6046
  }
6116
- } else {
6117
- // If primitive value
6118
- return {status: 1, values: []};
6119
- }
6120
- };
6121
-
6122
- // Return all keys
6123
- alasql.srch.KEYS = function (val) {
6124
- if (typeof val === 'object' && val !== null) {
6125
- return {status: 1, values: Object.keys(val)};
6126
- } else {
6127
- // If primitive value
6128
- return {status: 1, values: []};
6129
- }
6130
- };
6131
-
6132
- // Test expression
6133
- alasql.srch.WHERE = function (val, args, stope, params) {
6134
- var exprs = args[0].toJS('x', '');
6135
- var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6136
- if (exprfn(val, alasql, params)) {
6137
- return {status: 1, values: [val]};
6138
- } else {
6139
- return {status: -1, values: []};
6140
- }
6141
- };
6047
+ },
6142
6048
 
6143
- alasql.srch.NAME = function (val, args) {
6144
- if (val.name === args[0]) {
6145
- return {status: 1, values: [val]};
6146
- } else {
6147
- return {status: -1, values: []};
6148
- }
6149
- };
6049
+ CONTENT(val, args, stope) {
6050
+ if (stope.mode !== 'XML') {
6051
+ throw new Error('ATTR is not using in usual mode');
6052
+ }
6053
+ return {status: 1, values: [val.content]};
6054
+ },
6150
6055
 
6151
- alasql.srch.CLASS = function (val, args) {
6056
+ SHARP(val, args) {
6057
+ const obj = alasql.databases[alasql.useid].objects[args[0]];
6058
+ if (val !== undefined && val === obj) {
6059
+ return {status: 1, values: [val]};
6060
+ } else {
6061
+ return {status: -1, values: []};
6062
+ }
6063
+ },
6152
6064
 
6153
- // Please avoid `===` here
6154
- if (val.$class == args) {
6155
- // jshint ignore:line
6156
- return {status: 1, values: [val]};
6157
- } else {
6158
- return {status: -1, values: []};
6159
- }
6160
- };
6065
+ PARENT(/*val,args,stope*/) {
6066
+ // TODO: implement
6067
+ console.error('PARENT not implemented', arguments);
6161
6068
 
6162
- // Transform expression
6163
- alasql.srch.VERTEX = function (val) {
6164
- if (val.$node === 'VERTEX') {
6165
- return {status: 1, values: [val]};
6166
- } else {
6167
6069
  return {status: -1, values: []};
6168
- }
6169
- };
6070
+ },
6170
6071
 
6171
- // Transform expression
6172
- alasql.srch.INSTANCEOF = function (val, args) {
6173
- if (val instanceof alasql.fn[args[0]]) {
6174
- return {status: 1, values: [val]};
6175
- } else {
6176
- return {status: -1, values: []};
6177
- }
6178
- };
6072
+ CHILD(val, args, stope) {
6179
6073
 
6180
- // Transform expression
6181
- alasql.srch.EDGE = function (val) {
6182
- if (val.$node === 'EDGE') {
6183
- return {status: 1, values: [val]};
6184
- } else {
6185
- return {status: -1, values: []};
6186
- }
6187
- };
6074
+ if (typeof val === 'object') {
6075
+ if (Array.isArray(val)) {
6076
+ return {status: 1, values: val};
6077
+ } else {
6078
+ if (stope.mode === 'XML') {
6079
+ return {
6080
+ status: 1,
6081
+ values: Object.keys(val.children).map(function (key) {
6082
+ return val.children[key];
6083
+ }),
6084
+ };
6085
+ } else {
6086
+ return {
6087
+ status: 1,
6088
+ values: Object.keys(val).map(function (key) {
6089
+ return val[key];
6090
+ }),
6091
+ };
6092
+ }
6093
+ }
6094
+ } else {
6095
+ // If primitive value
6096
+ return {status: 1, values: []};
6097
+ }
6098
+ },
6188
6099
 
6189
- // Transform expression
6190
- alasql.srch.EX = function (val, args, stope, params) {
6191
- var exprs = args[0].toJS('x', '');
6192
- var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6193
- return {status: 1, values: [exprfn(val, alasql, params)]};
6194
- };
6100
+ // Return all keys
6101
+ KEYS(val) {
6102
+ if (typeof val === 'object' && val !== null) {
6103
+ return {status: 1, values: Object.keys(val)};
6104
+ } else {
6105
+ // If primitive value
6106
+ return {status: 1, values: []};
6107
+ }
6108
+ },
6195
6109
 
6196
- // Transform expression
6197
- alasql.srch.RETURN = function (val, args, stope, params) {
6198
- var res = {};
6199
- if (args && args.length > 0) {
6200
- args.forEach(function (arg) {
6201
- var exprs = arg.toJS('x', '');
6202
- var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6203
- if (typeof arg.as === 'undefined') {
6204
- arg.as = arg.toString();
6205
- }
6206
- res[arg.as] = exprfn(val, alasql, params);
6207
- });
6208
- }
6209
- return {status: 1, values: [res]};
6210
- };
6110
+ // Test expression
6111
+ WHERE(val, args, stope, params) {
6112
+ var exprs = args[0].toJS('x', '');
6113
+ var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6114
+ if (exprfn(val, alasql, params)) {
6115
+ return {status: 1, values: [val]};
6116
+ } else {
6117
+ return {status: -1, values: []};
6118
+ }
6119
+ },
6211
6120
 
6212
- // Transform expression
6213
- alasql.srch.REF = function (val) {
6214
- return {status: 1, values: [alasql.databases[alasql.useid].objects[val]]};
6215
- };
6121
+ NAME(val, args) {
6122
+ if (val.name === args[0]) {
6123
+ return {status: 1, values: [val]};
6124
+ } else {
6125
+ return {status: -1, values: []};
6126
+ }
6127
+ },
6216
6128
 
6217
- // Transform expression
6218
- alasql.srch.OUT = function (val) {
6219
- if (val.$out && val.$out.length > 0) {
6220
- var res = val.$out.map(function (v) {
6221
- return alasql.databases[alasql.useid].objects[v];
6222
- });
6223
- return {status: 1, values: res};
6224
- } else {
6225
- return {status: -1, values: []};
6226
- }
6227
- };
6129
+ CLASS(val, args) {
6228
6130
 
6229
- alasql.srch.OUTOUT = function (val) {
6230
- if (val.$out && val.$out.length > 0) {
6231
- var res = [];
6232
- val.$out.forEach(function (v) {
6233
- var av = alasql.databases[alasql.useid].objects[v];
6234
- if (av && av.$out && av.$out.length > 0) {
6235
- av.$out.forEach(function (vv) {
6236
- res = res.concat(alasql.databases[alasql.useid].objects[vv]);
6237
- });
6238
- }
6239
- });
6240
- return {status: 1, values: res};
6241
- } else {
6242
- return {status: -1, values: []};
6243
- }
6244
- };
6131
+ // Please avoid `===` here
6132
+ if (val.$class == args) {
6133
+ // jshint ignore:line
6134
+ return {status: 1, values: [val]};
6135
+ } else {
6136
+ return {status: -1, values: []};
6137
+ }
6138
+ },
6245
6139
 
6246
- // Transform expression
6247
- alasql.srch.IN = function (val) {
6248
- if (val.$in && val.$in.length > 0) {
6249
- var res = val.$in.map(function (v) {
6250
- return alasql.databases[alasql.useid].objects[v];
6251
- });
6252
- return {status: 1, values: res};
6253
- } else {
6254
- return {status: -1, values: []};
6255
- }
6256
- };
6140
+ // Transform expression
6141
+ VERTEX(val) {
6142
+ if (val.$node === 'VERTEX') {
6143
+ return {status: 1, values: [val]};
6144
+ } else {
6145
+ return {status: -1, values: []};
6146
+ }
6147
+ },
6257
6148
 
6258
- alasql.srch.ININ = function (val) {
6259
- if (val.$in && val.$in.length > 0) {
6260
- var res = [];
6261
- val.$in.forEach(function (v) {
6262
- var av = alasql.databases[alasql.useid].objects[v];
6263
- if (av && av.$in && av.$in.length > 0) {
6264
- av.$in.forEach(function (vv) {
6265
- res = res.concat(alasql.databases[alasql.useid].objects[vv]);
6266
- });
6267
- }
6268
- });
6269
- return {status: 1, values: res};
6270
- } else {
6271
- return {status: -1, values: []};
6272
- }
6273
- };
6149
+ // Transform expression
6150
+ INSTANCEOF(val, args) {
6151
+ if (val instanceof alasql.fn[args[0]]) {
6152
+ return {status: 1, values: [val]};
6153
+ } else {
6154
+ return {status: -1, values: []};
6155
+ }
6156
+ },
6274
6157
 
6275
- // Transform expression
6276
- alasql.srch.AS = function (val, args) {
6277
- alasql.vars[args[0]] = val;
6278
- return {status: 1, values: [val]};
6279
- };
6158
+ // Transform expression
6159
+ EDGE(val) {
6160
+ if (val.$node === 'EDGE') {
6161
+ return {status: 1, values: [val]};
6162
+ } else {
6163
+ return {status: -1, values: []};
6164
+ }
6165
+ },
6166
+
6167
+ // Transform expression
6168
+ EX(val, args, stope, params) {
6169
+ var exprs = args[0].toJS('x', '');
6170
+ var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6171
+ return {status: 1, values: [exprfn(val, alasql, params)]};
6172
+ },
6173
+
6174
+ // Transform expression
6175
+ RETURN(val, args, stope, params) {
6176
+ var res = {};
6177
+ if (args && args.length > 0) {
6178
+ args.forEach(function (arg) {
6179
+ var exprs = arg.toJS('x', '');
6180
+ var exprfn = new Function('x,alasql,params', 'return ' + exprs);
6181
+ if (typeof arg.as === 'undefined') {
6182
+ arg.as = arg.toString();
6183
+ }
6184
+ res[arg.as] = exprfn(val, alasql, params);
6185
+ });
6186
+ }
6187
+ return {status: 1, values: [res]};
6188
+ },
6280
6189
 
6281
- // Transform expression
6282
- alasql.srch.AT = function (val, args) {
6283
- var v = alasql.vars[args[0]];
6284
- return {status: 1, values: [v]};
6285
- };
6190
+ // Transform expression
6191
+ REF(val) {
6192
+ return {status: 1, values: [alasql.databases[alasql.useid].objects[val]]};
6193
+ },
6286
6194
 
6287
- // Transform expression
6288
- alasql.srch.CLONEDEEP = function (val) {
6289
- // TODO something wrong
6290
- var z = cloneDeep(val);
6291
- return {status: 1, values: [z]};
6292
- };
6195
+ // Transform expression
6196
+ OUT(val) {
6197
+ if (val.$out && val.$out.length > 0) {
6198
+ var res = val.$out.map(function (v) {
6199
+ return alasql.databases[alasql.useid].objects[v];
6200
+ });
6201
+ return {status: 1, values: res};
6202
+ } else {
6203
+ return {status: -1, values: []};
6204
+ }
6205
+ },
6293
6206
 
6294
- // // Transform expression
6295
- // alasql.srch.DELETE = function(val,args) {
6207
+ OUTOUT(val) {
6208
+ if (val.$out && val.$out.length > 0) {
6209
+ var res = [];
6210
+ val.$out.forEach(function (v) {
6211
+ var av = alasql.databases[alasql.useid].objects[v];
6212
+ if (av && av.$out && av.$out.length > 0) {
6213
+ av.$out.forEach(function (vv) {
6214
+ res = res.concat(alasql.databases[alasql.useid].objects[vv]);
6215
+ });
6216
+ }
6217
+ });
6218
+ return {status: 1, values: res};
6219
+ } else {
6220
+ return {status: -1, values: []};
6221
+ }
6222
+ },
6296
6223
 
6297
- // };
6224
+ // Transform expression
6225
+ IN(val) {
6226
+ if (val.$in && val.$in.length > 0) {
6227
+ var res = val.$in.map(function (v) {
6228
+ return alasql.databases[alasql.useid].objects[v];
6229
+ });
6230
+ return {status: 1, values: res};
6231
+ } else {
6232
+ return {status: -1, values: []};
6233
+ }
6234
+ },
6298
6235
 
6299
- // Transform expression
6300
- alasql.srch.SET = function (val, args, stope, params) {
6236
+ ININ(val) {
6237
+ if (val.$in && val.$in.length > 0) {
6238
+ var res = [];
6239
+ val.$in.forEach(function (v) {
6240
+ var av = alasql.databases[alasql.useid].objects[v];
6241
+ if (av && av.$in && av.$in.length > 0) {
6242
+ av.$in.forEach(function (vv) {
6243
+ res = res.concat(alasql.databases[alasql.useid].objects[vv]);
6244
+ });
6245
+ }
6246
+ });
6247
+ return {status: 1, values: res};
6248
+ } else {
6249
+ return {status: -1, values: []};
6250
+ }
6251
+ },
6301
6252
 
6302
- var s = args
6303
- .map(function (st) {
6253
+ // Transform expression
6254
+ AS(val, args) {
6255
+ alasql.vars[args[0]] = val;
6256
+ return {status: 1, values: [val]};
6257
+ },
6258
+
6259
+ // Transform expression
6260
+ AT(val, args) {
6261
+ var v = alasql.vars[args[0]];
6262
+ return {status: 1, values: [v]};
6263
+ },
6264
+
6265
+ // Transform expression
6266
+ CLONEDEEP(val) {
6267
+ // TODO something wrong
6268
+ var z = cloneDeep(val);
6269
+ return {status: 1, values: [z]};
6270
+ },
6271
+
6272
+ // // Transform expression
6273
+ // DELETE (val,args) {
6274
+ // // TODO something wrong
6275
+ // delete val;
6276
+ // return {status: 1, values: []};
6277
+ // },
6278
+
6279
+ // Transform expression
6280
+ SET(val, args, stope, params) {
6281
+
6282
+ var s = args
6283
+ .map(function (st) {
6304
6284
 
6305
- if (st.method === '@') {
6306
- return "alasql.vars['" + st.variable + "']=" + st.expression.toJS('x', '');
6307
- } else if (st.method === '$') {
6308
- return "params['" + st.variable + "']=" + st.expression.toJS('x', '');
6309
- } else {
6310
- return "x['" + st.column.columnid + "']=" + st.expression.toJS('x', '');
6311
- }
6312
- })
6313
- .join(';');
6314
- var setfn = new Function('x,params,alasql', s);
6285
+ if (st.method === '@') {
6286
+ return "alasql.vars['" + st.variable + "']=" + st.expression.toJS('x', '');
6287
+ } else if (st.method === '$') {
6288
+ return "params['" + st.variable + "']=" + st.expression.toJS('x', '');
6289
+ } else {
6290
+ return "x['" + st.column.columnid + "']=" + st.expression.toJS('x', '');
6291
+ }
6292
+ })
6293
+ .join(';');
6294
+ var setfn = new Function('x,params,alasql', s);
6315
6295
 
6316
- setfn(val, params, alasql);
6296
+ setfn(val, params, alasql);
6317
6297
 
6318
- return {status: 1, values: [val]};
6319
- };
6298
+ return {status: 1, values: [val]};
6299
+ },
6320
6300
 
6321
- alasql.srch.ROW = function (val, args, stope, params) {
6322
- var s = 'var y;return [';
6301
+ ROW(val, args, stope, params) {
6302
+ var s = 'var y;return [';
6303
+ s += args.map((arg) => arg.toJS('x', '')).join(',');
6304
+ s += ']';
6305
+ var setfn = new Function('x,params,alasql', s);
6306
+ var rv = setfn(val, params, alasql);
6323
6307
 
6324
- s += args
6325
- .map(function (arg) {
6326
- return arg.toJS('x', '');
6327
- })
6328
- .join(',');
6329
- s += ']';
6330
- var setfn = new Function('x,params,alasql', s);
6331
- var rv = setfn(val, params, alasql);
6308
+ return {status: 1, values: [rv]};
6309
+ },
6332
6310
 
6333
- return {status: 1, values: [rv]};
6334
- };
6311
+ D3(val) {
6312
+ if (val.$node !== 'VERTEX' && val.$node === 'EDGE') {
6313
+ val.source = val.$in[0];
6314
+ val.target = val.$out[0];
6315
+ }
6335
6316
 
6336
- alasql.srch.D3 = function (val) {
6337
- if (val.$node !== 'VERTEX' && val.$node === 'EDGE') {
6338
- val.source = val.$in[0];
6339
- val.target = val.$out[0];
6340
- }
6317
+ return {status: 1, values: [val]};
6318
+ },
6341
6319
 
6342
- return {status: 1, values: [val]};
6320
+ ORDERBY(val, args /*, stope */) {
6321
+ var res = val.sort(compileSearchOrder(args));
6322
+ return {status: 1, values: res};
6323
+ },
6343
6324
  };
6344
6325
 
6345
6326
  var compileSearchOrder = function (order) {
6346
6327
  if (order) {
6347
-
6348
- if (
6349
- order &&
6350
- order.length === 1 &&
6351
- order[0].expression &&
6352
- typeof order[0].expression === 'function'
6353
- ) {
6354
-
6328
+ if (typeof order?.[0]?.expression === 'function') {
6355
6329
  var func = order[0].expression;
6356
-
6357
6330
  return function (a, b) {
6358
6331
  var ra = func(a),
6359
6332
  rb = func(b);
@@ -6447,12 +6420,6 @@ var compileSearchOrder = function (order) {
6447
6420
  }
6448
6421
  };
6449
6422
 
6450
- alasql.srch.ORDERBY = function (val, args /*,stope*/) {
6451
-
6452
- var res = val.sort(compileSearchOrder(args));
6453
- return {status: 1, values: res};
6454
- };
6455
-
6456
6423
  // Main query procedure
6457
6424
  function queryfn(query, oldscope, cb, A, B) {
6458
6425
  var aaa = query.sources.length;
@@ -7284,7 +7251,7 @@ function swapSources(query, h) {
7284
7251
  /* global yy */
7285
7252
 
7286
7253
  yy.Select = function (params) {
7287
- return yy.extend(this, params);
7254
+ return Object.assign(this, params);
7288
7255
  };
7289
7256
  yy.Select.prototype.toString = function () {
7290
7257
  var s;
@@ -7808,7 +7775,7 @@ yy.Select.prototype.execute = function (databaseid, params, cb) {
7808
7775
  */
7809
7776
 
7810
7777
  yy.ExistsValue = function (params) {
7811
- return yy.extend(this, params);
7778
+ return Object.assign(this, params);
7812
7779
  };
7813
7780
  yy.ExistsValue.prototype.toString = function () {
7814
7781
  return 'EXISTS(' + this.value.toString() + ')';
@@ -8717,16 +8684,37 @@ yy.Select.prototype.compileGroup = function (query) {
8717
8684
  ",g['$$_VALUES_" + colas + "']={},g['$$_VALUES_" + colas + "'][" + colexp + ']=true';
8718
8685
  }
8719
8686
  if (col.aggregatorid === 'SUM') {
8720
- return "'" + colas + "':(" + colexp + ')||0,';
8687
+ if ('funcid' in col.expression) {
8688
+ let colexpression = col.expression.args[0];
8689
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8690
+ return `'${colas}':(${colexp1})|| typeof ${colexp1} == 'number' ? ${colexp1} : null,`;
8691
+ }
8692
+ return `'${colas}':(${colexp})|| typeof ${colexp} == 'number' ? ${colexp} : null,`;
8721
8693
  } else if (
8722
- col.aggregatorid === 'MIN' ||
8723
- col.aggregatorid === 'MAX' ||
8724
8694
  col.aggregatorid === 'FIRST' ||
8725
8695
  col.aggregatorid === 'LAST'
8726
8696
  // || col.aggregatorid == 'AVG'
8727
8697
  // ) { return "'"+col.as+'\':r[\''+col.as+'\'],'; }//f.field.arguments[0].toJS();
8728
8698
  ) {
8729
8699
  return "'" + colas + "':" + colexp + ','; //f.field.arguments[0].toJS();
8700
+ } else if (col.aggregatorid === 'MIN') {
8701
+ if ('funcid' in col.expression) {
8702
+ let colexpression = col.expression.args[0];
8703
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8704
+ return `'${colas}': (typeof ${colexp1} == 'number' ? ${colexp1} : typeof ${colexp1} == 'object' ?
8705
+ typeof Number(${colexp1}) == 'number' && ${colexp1}!== null? ${colexp1} : null : null),`;
8706
+ }
8707
+ return `'${colas}': (typeof ${colexp} == 'number' ? ${colexp} : typeof ${colexp} == 'object' ?
8708
+ typeof Number(${colexp}) == 'number' && ${colexp}!== null? ${colexp} : null : null),`;
8709
+ } else if (col.aggregatorid === 'MAX') {
8710
+ if ('funcid' in col.expression) {
8711
+ let colexpression = col.expression.args[0];
8712
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8713
+ return `'${colas}' : (typeof ${colexp1} == 'number' ? ${colexp1} : typeof ${colexp1} == 'object' ?
8714
+ typeof Number(${colexp1}) == 'number' ? ${colexp1} : null : null),`;
8715
+ }
8716
+ return `'${colas}' : (typeof ${colexp} == 'number' ? ${colexp} : typeof ${colexp} == 'object' ?
8717
+ typeof Number(${colexp}) == 'number' ? ${colexp} : null : null),`;
8730
8718
  } else if (col.aggregatorid === 'ARRAY') {
8731
8719
  return "'" + colas + "':[" + colexp + '],';
8732
8720
  } else if (col.aggregatorid === 'COUNT') {
@@ -8820,7 +8808,34 @@ yy.Select.prototype.compileGroup = function (query) {
8820
8808
  var post = "g['$$_VALUES_" + colas + "'][" + colexp + ']=true;}';
8821
8809
  }
8822
8810
  if (col.aggregatorid === 'SUM') {
8823
- return pre + "g['" + colas + "']+=(" + colexp + '||0);' + post; //f.field.arguments[0].toJS();
8811
+ if ('funcid' in col.expression) {
8812
+ let colexpression = col.expression.args[0];
8813
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8814
+ return (
8815
+ pre +
8816
+ `if(g['${colas}'] == null && ${colexp1} == null){g['${colas}'] = null}
8817
+ else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp1}!== 'object' && typeof ${colexp1}!== 'number'){g['${colas}'] = null}
8818
+ else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp1} == 'number'){g['${colas}'] = ${colexp1}}
8819
+ else if(typeof g['${colas}']!== 'number' && typeof ${colexp1}!== 'number' && typeof ${colexp1}!== 'object'){g['${colas}'] = g['${colas}']}
8820
+ else if((g['${colas}'] == null || (typeof g['${colas}']!== 'number' && typeof g['${colas}']!== 'object')) && (${colexp1} == null || (typeof ${colexp1}!== 'number' && typeof ${colexp1}!== 'object'))){g['${colas}'] = null}
8821
+ else if(typeof g['${colas}'] == 'number' && typeof ${colexp1} ==null){g['${colas}'] = g['${colas}']}
8822
+ else if(typeof g['${colas}'] == null && typeof ${colexp1} =='number'){g['${colas}'] = ${colexp1}}
8823
+ else{g['${colas}'] += ${colexp1}||0}` +
8824
+ post
8825
+ );
8826
+ }
8827
+ return (
8828
+ pre +
8829
+ `if(g['${colas}'] == null && ${colexp} == null){g['${colas}'] = null}
8830
+ else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number'&& typeof ${colexp}!== 'object' && typeof ${colexp}!== 'number'){g['${colas}'] = null}
8831
+ else if(typeof g['${colas}']!== 'object' && typeof g['${colas}']!== 'number' && typeof ${colexp} == 'number'){g['${colas}'] = ${colexp}}
8832
+ else if(typeof g['${colas}']!== 'number' && typeof ${colexp}!== 'number' && typeof ${colexp}!== 'object'){g['${colas}'] = g['${colas}']}
8833
+ else if((g['${colas}'] == null || (typeof g['${colas}']!== 'number' && typeof g['${colas}']!== 'object')) && (${colexp} == null || (typeof ${colexp}!== 'number' && typeof ${colexp}!== 'object'))){g['${colas}'] = null}
8834
+ else if(typeof g['${colas}'] == 'number' && typeof ${colexp} ==null){g['${colas}'] = g['${colas}']}
8835
+ else if(typeof g['${colas}'] == null && typeof ${colexp} =='number'){g['${colas}'] = ${colexp}}
8836
+ else{g['${colas}'] += ${colexp}||0}` +
8837
+ post
8838
+ );
8824
8839
  } else if (col.aggregatorid === 'COUNT') {
8825
8840
 
8826
8841
  if (col.expression.columnid === '*') {
@@ -8841,12 +8856,48 @@ yy.Select.prototype.compileGroup = function (query) {
8841
8856
  } else if (col.aggregatorid === 'ARRAY') {
8842
8857
  return pre + "g['" + colas + "'].push(" + colexp + ');' + post;
8843
8858
  } else if (col.aggregatorid === 'MIN') {
8859
+ if ('funcid' in col.expression) {
8860
+ let colexpression = col.expression.args[0];
8861
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8862
+ return (
8863
+ pre +
8864
+ `if((g['${colas}'] == null && ${colexp1}!== null) ? y = ${colexp1} : (g['${colas}']!== null &&
8865
+ ${colexp1} == null) ? y = g['${colas}']:((y=${colexp1}) < g['${colas}'])){ if(typeof y == 'number')
8866
+ {g['${colas}'] = y;}else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
8867
+ else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}
8868
+ else if(g['${colas}']!== null && typeof g['${colas}'] == 'object' && y instanceof Date){g['${colas}'] = g['${colas}']}
8869
+ else if(g['${colas}']!== null && typeof g['${colas}'] == 'object'){g['${colas}'] = Number(g['${colas}'])}` +
8870
+ post
8871
+ );
8872
+ }
8844
8873
  return (
8845
- pre + 'if ((y=' + colexp + ") < g['" + colas + "']) g['" + colas + "'] = y;" + post
8874
+ pre +
8875
+ `if((g['${colas}'] == null && ${colexp}!== null) ? y = ${colexp} : (g['${colas}']!== null &&
8876
+ ${colexp} == null) ? y = g['${colas}']:((y=${colexp}) < g['${colas}'])){ if(typeof y == 'number')
8877
+ {g['${colas}'] = y;}else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
8878
+ else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}
8879
+ else if(g['${colas}']!== null && typeof g['${colas}'] == 'object' && y instanceof Date){g['${colas}'] = g['${colas}']}
8880
+ else if(g['${colas}']!== null && typeof g['${colas}'] == 'object'){g['${colas}'] = Number(g['${colas}'])}` +
8881
+ post
8846
8882
  );
8847
8883
  } else if (col.aggregatorid === 'MAX') {
8884
+ if ('funcid' in col.expression) {
8885
+ let colexpression = col.expression.args[0];
8886
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8887
+ return (
8888
+ pre +
8889
+ `if((y=${colexp1}) > g['${colas}']){if(typeof y == 'number'){g['${colas}'] = y;}
8890
+ else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
8891
+ else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}` +
8892
+ post
8893
+ );
8894
+ }
8848
8895
  return (
8849
- pre + 'if ((y=' + colexp + ") > g['" + colas + "']) g['" + colas + "'] = y;" + post
8896
+ pre +
8897
+ `if((y=${colexp}) > g['${colas}']){if(typeof y == 'number'){g['${colas}'] = y;}
8898
+ else if(typeof y == 'object' && y instanceof Date){g['${colas}'] = y;}
8899
+ else if(typeof y == 'object' && typeof Number(y) == 'number'){g['${colas}'] = Number(y);}}` +
8900
+ post
8850
8901
  );
8851
8902
  } else if (col.aggregatorid === 'FIRST') {
8852
8903
  return '';
@@ -10044,7 +10095,7 @@ yy.Select.prototype.compileDefCols = function (query, databaseid) {
10044
10095
  // SELECT UNION statement
10045
10096
 
10046
10097
  yy.Union = function (params) {
10047
- return yy.extend(this, params);
10098
+ return Object.assign(this, params);
10048
10099
  };
10049
10100
  yy.Union.prototype.toString = function () {
10050
10101
  return 'UNION';
@@ -10063,7 +10114,7 @@ yy.Union.prototype.compile = function (tableid) {
10063
10114
  */
10064
10115
 
10065
10116
  yy.Apply = function (params) {
10066
- return yy.extend(this, params);
10117
+ return Object.assign(this, params);
10067
10118
  };
10068
10119
 
10069
10120
  yy.Apply.prototype.toString = function () {
@@ -10083,7 +10134,7 @@ yy.Apply.prototype.toString = function () {
10083
10134
  */
10084
10135
 
10085
10136
  yy.Over = function (params) {
10086
- return yy.extend(this, params);
10137
+ return Object.assign(this, params);
10087
10138
  };
10088
10139
  yy.Over.prototype.toString = function () {
10089
10140
  var s = 'OVER (';
@@ -10106,13 +10157,15 @@ yy.Over.prototype.toString = function () {
10106
10157
  //
10107
10158
  */
10108
10159
 
10160
+ var assign = Object.assign;
10161
+
10109
10162
  /**
10110
10163
  Expression statement ( = 2*2; )
10111
10164
  @class
10112
10165
  @param {object} params Initial parameters
10113
10166
  */
10114
10167
  yy.ExpressionStatement = function (params) {
10115
- return yy.extend(this, params);
10168
+ return assign(this, params);
10116
10169
  };
10117
10170
 
10118
10171
  /**
@@ -10153,7 +10206,7 @@ yy.ExpressionStatement.prototype.execute = function (databaseid, params, cb) {
10153
10206
  */
10154
10207
 
10155
10208
  yy.Expression = function (params) {
10156
- return yy.extend(this, params);
10209
+ return assign(this, params);
10157
10210
  };
10158
10211
 
10159
10212
  /**
@@ -10225,7 +10278,7 @@ yy.Expression.prototype.compile = function (context, tableid, defcols) {
10225
10278
  @class
10226
10279
  */
10227
10280
  yy.JavaScript = function (params) {
10228
- return yy.extend(this, params);
10281
+ return assign(this, params);
10229
10282
  };
10230
10283
  yy.JavaScript.prototype.toString = function () {
10231
10284
  var s = '``' + this.value + '``';
@@ -10253,7 +10306,7 @@ yy.JavaScript.prototype.execute = function (databaseid, params, cb) {
10253
10306
  */
10254
10307
 
10255
10308
  yy.Literal = function (params) {
10256
- return yy.extend(this, params);
10309
+ return assign(this, params);
10257
10310
  };
10258
10311
  yy.Literal.prototype.toString = function () {
10259
10312
  var s = this.value;
@@ -10270,7 +10323,7 @@ yy.Literal.prototype.toString = function () {
10270
10323
  */
10271
10324
 
10272
10325
  yy.Join = function (params) {
10273
- return yy.extend(this, params);
10326
+ return assign(this, params);
10274
10327
  };
10275
10328
  yy.Join.prototype.toString = function () {
10276
10329
  var s = ' ';
@@ -10287,7 +10340,7 @@ yy.Join.prototype.toString = function () {
10287
10340
  */
10288
10341
 
10289
10342
  yy.Table = function (params) {
10290
- return yy.extend(this, params);
10343
+ return assign(this, params);
10291
10344
  };
10292
10345
  yy.Table.prototype.toString = function () {
10293
10346
  var s = this.tableid;
@@ -10304,7 +10357,7 @@ yy.Table.prototype.toString = function () {
10304
10357
  */
10305
10358
 
10306
10359
  yy.View = function (params) {
10307
- return yy.extend(this, params);
10360
+ return assign(this, params);
10308
10361
  };
10309
10362
  yy.View.prototype.toString = function () {
10310
10363
  var s = this.viewid;
@@ -10320,7 +10373,7 @@ yy.View.prototype.toString = function () {
10320
10373
  @class
10321
10374
  */
10322
10375
  yy.Op = function (params) {
10323
- return yy.extend(this, params);
10376
+ return assign(this, params);
10324
10377
  };
10325
10378
  yy.Op.prototype.toString = function () {
10326
10379
  if (this.op === 'IN' || this.op === 'NOT IN') {
@@ -10518,9 +10571,9 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
10518
10571
  ||
10519
10572
  (
10520
10573
  ${leftOperand} < 0
10521
- &&
10522
- true == ${rightOperand}
10523
- )
10574
+ &&
10575
+ true == ${rightOperand}
10576
+ )
10524
10577
  )`;
10525
10578
  }
10526
10579
  }
@@ -10706,7 +10759,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
10706
10759
  };
10707
10760
 
10708
10761
  yy.VarValue = function (params) {
10709
- return yy.extend(this, params);
10762
+ return assign(this, params);
10710
10763
  };
10711
10764
  yy.VarValue.prototype.toString = function () {
10712
10765
  return '@' + this.variable;
@@ -10721,7 +10774,7 @@ yy.VarValue.prototype.toJS = function () {
10721
10774
  };
10722
10775
 
10723
10776
  yy.NumValue = function (params) {
10724
- return yy.extend(this, params);
10777
+ return assign(this, params);
10725
10778
  };
10726
10779
  yy.NumValue.prototype.toString = function () {
10727
10780
  return this.value.toString();
@@ -10736,7 +10789,7 @@ yy.NumValue.prototype.toJS = function () {
10736
10789
  };
10737
10790
 
10738
10791
  yy.StringValue = function (params) {
10739
- return yy.extend(this, params);
10792
+ return assign(this, params);
10740
10793
  };
10741
10794
  yy.StringValue.prototype.toString = function () {
10742
10795
  return "'" + this.value.toString() + "'";
@@ -10751,7 +10804,7 @@ yy.StringValue.prototype.toJS = function () {
10751
10804
  };
10752
10805
 
10753
10806
  yy.DomainValueValue = function (params) {
10754
- return yy.extend(this, params);
10807
+ return assign(this, params);
10755
10808
  };
10756
10809
  yy.DomainValueValue.prototype.toString = function () {
10757
10810
  return 'VALUE';
@@ -10768,7 +10821,7 @@ yy.DomainValueValue.prototype.toJS = function (context, tableid, defcols) {
10768
10821
  };
10769
10822
 
10770
10823
  yy.ArrayValue = function (params) {
10771
- return yy.extend(this, params);
10824
+ return assign(this, params);
10772
10825
  };
10773
10826
  yy.ArrayValue.prototype.toString = function () {
10774
10827
  return 'ARRAY[]';
@@ -10791,7 +10844,7 @@ yy.ArrayValue.prototype.toJS = function (context, tableid, defcols) {
10791
10844
  };
10792
10845
 
10793
10846
  yy.LogicValue = function (params) {
10794
- return yy.extend(this, params);
10847
+ return assign(this, params);
10795
10848
  };
10796
10849
  yy.LogicValue.prototype.toString = function () {
10797
10850
  return this.value ? 'TRUE' : 'FALSE';
@@ -10806,7 +10859,7 @@ yy.LogicValue.prototype.toJS = function () {
10806
10859
  };
10807
10860
 
10808
10861
  yy.NullValue = function (params) {
10809
- return yy.extend(this, params);
10862
+ return assign(this, params);
10810
10863
  };
10811
10864
  yy.NullValue.prototype.toString = function () {
10812
10865
  return 'NULL';
@@ -10817,7 +10870,7 @@ yy.NullValue.prototype.toJS = function () {
10817
10870
  };
10818
10871
 
10819
10872
  yy.ParamValue = function (params) {
10820
- return yy.extend(this, params);
10873
+ return assign(this, params);
10821
10874
  };
10822
10875
  yy.ParamValue.prototype.toString = function () {
10823
10876
  return '$' + this.param;
@@ -10831,7 +10884,7 @@ yy.ParamValue.prototype.toJS = function () {
10831
10884
  };
10832
10885
 
10833
10886
  yy.UniOp = function (params) {
10834
- return yy.extend(this, params);
10887
+ return assign(this, params);
10835
10888
  };
10836
10889
  yy.UniOp.prototype.toString = function () {
10837
10890
  var s;
@@ -10921,7 +10974,7 @@ yy.UniOp.prototype.toJS = function (context, tableid, defcols) {
10921
10974
  };
10922
10975
 
10923
10976
  yy.Column = function (params) {
10924
- return yy.extend(this, params);
10977
+ return assign(this, params);
10925
10978
  };
10926
10979
  yy.Column.prototype.toString = function () {
10927
10980
  var s;
@@ -11002,7 +11055,7 @@ yy.Column.prototype.toJS = function (context, tableid, defcols) {
11002
11055
  };
11003
11056
 
11004
11057
  yy.AggrValue = function (params) {
11005
- return yy.extend(this, params);
11058
+ return assign(this, params);
11006
11059
  };
11007
11060
  yy.AggrValue.prototype.toString = function () {
11008
11061
  var s = '';
@@ -11077,13 +11130,13 @@ yy.AggrValue.prototype.toJS = function () {
11077
11130
  };
11078
11131
 
11079
11132
  yy.OrderExpression = function (params) {
11080
- return yy.extend(this, params);
11133
+ return assign(this, params);
11081
11134
  };
11082
11135
 
11083
11136
  yy.OrderExpression.prototype.toString = yy.Expression.prototype.toString;
11084
11137
 
11085
11138
  yy.GroupExpression = function (params) {
11086
- return yy.extend(this, params);
11139
+ return assign(this, params);
11087
11140
  };
11088
11141
  yy.GroupExpression.prototype.toString = function () {
11089
11142
  return this.type + '(' + this.group.toString() + ')';
@@ -11264,7 +11317,7 @@ yy.Select.prototype.Where = function (expr) {
11264
11317
  */
11265
11318
 
11266
11319
  yy.FuncValue = function (params) {
11267
- return yy.extend(this, params);
11320
+ return Object.assign(this, params);
11268
11321
  };
11269
11322
 
11270
11323
  var re_invalidFnNameChars = /[^0-9A-Z_$]+/i;
@@ -11726,7 +11779,7 @@ stdfn.NEWID =
11726
11779
  */
11727
11780
 
11728
11781
  yy.CaseValue = function (params) {
11729
- return yy.extend(this, params);
11782
+ return Object.assign(this, params);
11730
11783
  };
11731
11784
  yy.CaseValue.prototype.toString = function () {
11732
11785
  var s = 'CASE ';
@@ -11800,7 +11853,7 @@ yy.CaseValue.prototype.toJS = function (context, tableid, defcols) {
11800
11853
  */
11801
11854
 
11802
11855
  yy.Json = function (params) {
11803
- return yy.extend(this, params);
11856
+ return Object.assign(this, params);
11804
11857
  };
11805
11858
  yy.Json.prototype.toString = function () {
11806
11859
  var s = ''; // '@'
@@ -11909,7 +11962,7 @@ yy.Json.prototype.toJS = function (context, tableid, defcols) {
11909
11962
  */
11910
11963
 
11911
11964
  yy.Convert = function (params) {
11912
- return yy.extend(this, params);
11965
+ return Object.assign(this, params);
11913
11966
  };
11914
11967
  yy.Convert.prototype.toString = function () {
11915
11968
  var s = 'CONVERT(';
@@ -12203,7 +12256,7 @@ alasql.stdfn.CONVERT = function (value, args) {
12203
12256
  /* global alasql, yy, hash */
12204
12257
 
12205
12258
  yy.ColumnDef = function (params) {
12206
- return yy.extend(this, params);
12259
+ return Object.assign(this, params);
12207
12260
  };
12208
12261
  yy.ColumnDef.prototype.toString = function () {
12209
12262
  var s = this.columnid;
@@ -12231,7 +12284,7 @@ yy.ColumnDef.prototype.toString = function () {
12231
12284
  };
12232
12285
 
12233
12286
  yy.CreateTable = function (params) {
12234
- return yy.extend(this, params);
12287
+ return Object.assign(this, params);
12235
12288
  };
12236
12289
  yy.CreateTable.prototype.toString = function () {
12237
12290
  var s = 'CREATE';
@@ -13049,7 +13102,7 @@ function newDate(d) {
13049
13102
  */
13050
13103
 
13051
13104
  yy.DropTable = function (params) {
13052
- return yy.extend(this, params);
13105
+ return Object.assign(this, params);
13053
13106
  };
13054
13107
  yy.DropTable.prototype.toString = function () {
13055
13108
  var s = 'DROP' + ' ';
@@ -13122,7 +13175,7 @@ yy.DropTable.prototype.execute = function (databaseid, params, cb) {
13122
13175
  };
13123
13176
 
13124
13177
  yy.TruncateTable = function (params) {
13125
- return yy.extend(this, params);
13178
+ return Object.assign(this, params);
13126
13179
  };
13127
13180
  yy.TruncateTable.prototype.toString = function () {
13128
13181
  var s = 'TRUNCATE TABLE';
@@ -13158,7 +13211,7 @@ yy.TruncateTable.prototype.execute = function (databaseid, params, cb) {
13158
13211
  */
13159
13212
 
13160
13213
  yy.CreateVertex = function (params) {
13161
- return yy.extend(this, params);
13214
+ return Object.assign(this, params);
13162
13215
  };
13163
13216
  yy.CreateVertex.prototype.toString = function () {
13164
13217
  var s = 'CREATE VERTEX ';
@@ -13241,7 +13294,7 @@ yy.CreateVertex.prototype.compile = function (databaseid) {
13241
13294
  };
13242
13295
 
13243
13296
  yy.CreateEdge = function (params) {
13244
- return yy.extend(this, params);
13297
+ return Object.assign(this, params);
13245
13298
  };
13246
13299
  yy.CreateEdge.prototype.toString = function () {
13247
13300
 
@@ -13334,7 +13387,7 @@ yy.CreateEdge.prototype.compile = function (databaseid) {
13334
13387
  };
13335
13388
 
13336
13389
  yy.CreateGraph = function (params) {
13337
- return yy.extend(this, params);
13390
+ return Object.assign(this, params);
13338
13391
  };
13339
13392
  yy.CreateGraph.prototype.toString = function () {
13340
13393
  var s = 'CREATE GRAPH' + ' ';
@@ -13599,7 +13652,7 @@ yy.CreateGraph.prototype.compile1 = function (databaseid) {
13599
13652
 
13600
13653
  // ALTER TABLE table1 RENAME TO table2
13601
13654
  yy.AlterTable = function (params) {
13602
- return yy.extend(this, params);
13655
+ return Object.assign(this, params);
13603
13656
  };
13604
13657
  yy.AlterTable.prototype.toString = function () {
13605
13658
  var s = 'ALTER TABLE ' + this.table.toString();
@@ -13776,7 +13829,7 @@ yy.AlterTable.prototype.execute = function (databaseid, params, cb) {
13776
13829
  */
13777
13830
 
13778
13831
  yy.CreateIndex = function (params) {
13779
- return yy.extend(this, params);
13832
+ return Object.assign(this, params);
13780
13833
  };
13781
13834
  yy.CreateIndex.prototype.toString = function () {
13782
13835
  var s = 'CREATE';
@@ -13839,7 +13892,7 @@ yy.CreateIndex.prototype.execute = function (databaseid, params, cb) {
13839
13892
  };
13840
13893
 
13841
13894
  yy.Reindex = function (params) {
13842
- return yy.extend(this, params);
13895
+ return Object.assign(this, params);
13843
13896
  };
13844
13897
  yy.Reindex.prototype.toString = function () {
13845
13898
  var s = 'REINDEX ' + this.indexid;
@@ -13869,7 +13922,7 @@ yy.Reindex.prototype.execute = function (databaseid, params, cb) {
13869
13922
  */
13870
13923
 
13871
13924
  yy.DropIndex = function (params) {
13872
- return yy.extend(this, params);
13925
+ return Object.assign(this, params);
13873
13926
  };
13874
13927
  yy.DropIndex.prototype.toString = function () {
13875
13928
  return 'DROP INDEX' + this.indexid;
@@ -13892,7 +13945,7 @@ yy.DropIndex.prototype.compile = function (db) {
13892
13945
  */
13893
13946
 
13894
13947
  yy.WithSelect = function (params) {
13895
- return yy.extend(this, params);
13948
+ return Object.assign(this, params);
13896
13949
  };
13897
13950
  yy.WithSelect.prototype.toString = function () {
13898
13951
  var s = 'WITH ';
@@ -13941,7 +13994,7 @@ yy.WithSelect.prototype.execute = function (databaseid, params, cb) {
13941
13994
  */
13942
13995
 
13943
13996
  yy.If = function (params) {
13944
- return yy.extend(this, params);
13997
+ return Object.assign(this, params);
13945
13998
  };
13946
13999
  yy.If.prototype.toString = function () {
13947
14000
  var s = 'IF' + ' ';
@@ -13981,7 +14034,7 @@ yy.If.prototype.execute = function (databaseid, params, cb) {
13981
14034
  */
13982
14035
 
13983
14036
  yy.While = function (params) {
13984
- return yy.extend(this, params);
14037
+ return Object.assign(this, params);
13985
14038
  };
13986
14039
  yy.While.prototype.toString = function () {
13987
14040
  var s = 'WHILE ';
@@ -14023,7 +14076,7 @@ yy.While.prototype.execute = function (databaseid, params, cb) {
14023
14076
  };
14024
14077
 
14025
14078
  yy.Break = function (params) {
14026
- return yy.extend(this, params);
14079
+ return Object.assign(this, params);
14027
14080
  };
14028
14081
  yy.Break.prototype.toString = function () {
14029
14082
  var s = 'BREAK';
@@ -14037,7 +14090,7 @@ yy.Break.prototype.execute = function (databaseid, params, cb, scope) {
14037
14090
  };
14038
14091
 
14039
14092
  yy.Continue = function (params) {
14040
- return yy.extend(this, params);
14093
+ return Object.assign(this, params);
14041
14094
  };
14042
14095
  yy.Continue.prototype.toString = function () {
14043
14096
  var s = 'CONTINUE';
@@ -14051,7 +14104,7 @@ yy.Continue.prototype.execute = function (databaseid, params, cb, scope) {
14051
14104
  };
14052
14105
 
14053
14106
  yy.BeginEnd = function (params) {
14054
- return yy.extend(this, params);
14107
+ return Object.assign(this, params);
14055
14108
  };
14056
14109
  yy.BeginEnd.prototype.toString = function () {
14057
14110
  var s = 'BEGIN ' + this.statements.toString() + ' END';
@@ -14085,7 +14138,7 @@ yy.BeginEnd.prototype.execute = function (databaseid, params, cb, scope) {
14085
14138
 
14086
14139
  /* global yy alasql*/
14087
14140
  yy.Insert = function (params) {
14088
- return yy.extend(this, params);
14141
+ return Object.assign(this, params);
14089
14142
  };
14090
14143
  yy.Insert.prototype.toString = function () {
14091
14144
  var s = 'INSERT ';
@@ -14353,7 +14406,7 @@ yy.Insert.prototype.execute = function (databaseid, params, cb) {
14353
14406
  */
14354
14407
 
14355
14408
  yy.CreateTrigger = function (params) {
14356
- return yy.extend(this, params);
14409
+ return Object.assign(this, params);
14357
14410
  };
14358
14411
  yy.CreateTrigger.prototype.toString = function () {
14359
14412
  var s = 'CREATE TRIGGER ' + this.trigger + ' ';
@@ -14406,7 +14459,7 @@ yy.CreateTrigger.prototype.execute = function (databaseid, params, cb) {
14406
14459
  };
14407
14460
 
14408
14461
  yy.DropTrigger = function (params) {
14409
- return yy.extend(this, params);
14462
+ return Object.assign(this, params);
14410
14463
  };
14411
14464
  yy.DropTrigger.prototype.toString = function () {
14412
14465
  var s = 'DROP TRIGGER ' + this.trigger;
@@ -14465,7 +14518,7 @@ yy.DropTrigger.prototype.execute = function (databaseid, params, cb) {
14465
14518
  */
14466
14519
 
14467
14520
  yy.Delete = function (params) {
14468
- return yy.extend(this, params);
14521
+ return Object.assign(this, params);
14469
14522
  };
14470
14523
  yy.Delete.prototype.toString = function () {
14471
14524
  var s = 'DELETE FROM ' + this.table.toString();
@@ -14624,7 +14677,7 @@ yy.Delete.prototype.execute = function (databaseid, params, cb) {
14624
14677
  /* global yy alasql */
14625
14678
 
14626
14679
  yy.Update = function (params) {
14627
- return yy.extend(this, params);
14680
+ return Object.assign(this, params);
14628
14681
  };
14629
14682
  yy.Update.prototype.toString = function () {
14630
14683
  var s = 'UPDATE ' + this.table.toString();
@@ -14634,7 +14687,7 @@ yy.Update.prototype.toString = function () {
14634
14687
  };
14635
14688
 
14636
14689
  yy.SetColumn = function (params) {
14637
- return yy.extend(this, params);
14690
+ return Object.assign(this, params);
14638
14691
  };
14639
14692
  yy.SetColumn.prototype.toString = function () {
14640
14693
  return this.column.toString() + '=' + this.expression.toString();
@@ -14736,7 +14789,7 @@ yy.Update.prototype.execute = function (databaseid, params, cb) {
14736
14789
  /* global alasql, yy */
14737
14790
 
14738
14791
  yy.Merge = function (params) {
14739
- return yy.extend(this, params);
14792
+ return Object.assign(this, params);
14740
14793
  };
14741
14794
  yy.Merge.prototype.toString = function () {
14742
14795
  var s = 'MERGE ';
@@ -14794,7 +14847,7 @@ yy.Merge.prototype.execute = function (databaseid, params, cb) {
14794
14847
 
14795
14848
  // CREATE DATABASE databaseid
14796
14849
  yy.CreateDatabase = function (params) {
14797
- return yy.extend(this, params);
14850
+ return Object.assign(this, params);
14798
14851
  };
14799
14852
  yy.CreateDatabase.prototype.toString = function () {
14800
14853
  var s = 'CREATE';
@@ -14847,7 +14900,7 @@ yy.CreateDatabase.prototype.execute = function (databaseid, params, cb) {
14847
14900
 
14848
14901
  // CREATE DATABASE databaseid
14849
14902
  yy.AttachDatabase = function (params) {
14850
- return yy.extend(this, params);
14903
+ return Object.assign(this, params);
14851
14904
  };
14852
14905
  yy.AttachDatabase.prototype.toString = function (args) {
14853
14906
  var s = 'ATTACH';
@@ -14885,7 +14938,7 @@ yy.AttachDatabase.prototype.execute = function (databaseid, params, cb) {
14885
14938
 
14886
14939
  // CREATE DATABASE databaseid
14887
14940
  yy.DetachDatabase = function (params) {
14888
- return yy.extend(this, params);
14941
+ return Object.assign(this, params);
14889
14942
  };
14890
14943
  yy.DetachDatabase.prototype.toString = function () {
14891
14944
  var s = 'DETACH';
@@ -14946,7 +14999,7 @@ yy.DetachDatabase.prototype.execute = function (databaseid, params, cb) {
14946
14999
  // USE DATABSE databaseid
14947
15000
  // USE databaseid
14948
15001
  yy.UseDatabase = function (params) {
14949
- return yy.extend(this, params);
15002
+ return Object.assign(this, params);
14950
15003
  };
14951
15004
  yy.UseDatabase.prototype.toString = function () {
14952
15005
  return 'USE' + ' ' + 'DATABASE' + ' ' + this.databaseid;
@@ -14965,7 +15018,7 @@ yy.UseDatabase.prototype.execute = function (databaseid, params, cb) {
14965
15018
 
14966
15019
  // DROP DATABASE databaseid
14967
15020
  yy.DropDatabase = function (params) {
14968
- return yy.extend(this, params);
15021
+ return Object.assign(this, params);
14969
15022
  };
14970
15023
  yy.DropDatabase.prototype.toString = function () {
14971
15024
  var s = 'DROP';
@@ -15015,7 +15068,7 @@ yy.DropDatabase.prototype.execute = function (databaseid, params, cb) {
15015
15068
  */
15016
15069
 
15017
15070
  yy.Declare = function (params) {
15018
- return yy.extend(this, params);
15071
+ return Object.assign(this, params);
15019
15072
  };
15020
15073
  yy.Declare.prototype.toString = function () {
15021
15074
  var s = 'DECLARE ';
@@ -15087,7 +15140,7 @@ yy.Declare.prototype.execute = function (databaseid, params, cb) {
15087
15140
  */
15088
15141
 
15089
15142
  yy.ShowDatabases = function (params) {
15090
- return yy.extend(this, params);
15143
+ return Object.assign(this, params);
15091
15144
  };
15092
15145
  yy.ShowDatabases.prototype.toString = function () {
15093
15146
  var s = 'SHOW DATABASES';
@@ -15115,7 +15168,7 @@ yy.ShowDatabases.prototype.execute = function (databaseid, params, cb) {
15115
15168
  };
15116
15169
 
15117
15170
  yy.ShowTables = function (params) {
15118
- return yy.extend(this, params);
15171
+ return Object.assign(this, params);
15119
15172
  };
15120
15173
  yy.ShowTables.prototype.toString = function () {
15121
15174
  var s = 'SHOW TABLES';
@@ -15142,7 +15195,7 @@ yy.ShowTables.prototype.execute = function (databaseid, params, cb) {
15142
15195
  };
15143
15196
 
15144
15197
  yy.ShowColumns = function (params) {
15145
- return yy.extend(this, params);
15198
+ return Object.assign(this, params);
15146
15199
  };
15147
15200
  yy.ShowColumns.prototype.toString = function () {
15148
15201
  var s = 'SHOW COLUMNS';
@@ -15168,7 +15221,7 @@ yy.ShowColumns.prototype.execute = function (databaseid, params, cb) {
15168
15221
  };
15169
15222
 
15170
15223
  yy.ShowIndex = function (params) {
15171
- return yy.extend(this, params);
15224
+ return Object.assign(this, params);
15172
15225
  };
15173
15226
  yy.ShowIndex.prototype.toString = function () {
15174
15227
  var s = 'SHOW INDEX';
@@ -15191,7 +15244,7 @@ yy.ShowIndex.prototype.execute = function (databaseid, params, cb) {
15191
15244
  };
15192
15245
 
15193
15246
  yy.ShowCreateTable = function (params) {
15194
- return yy.extend(this, params);
15247
+ return Object.assign(this, params);
15195
15248
  };
15196
15249
  yy.ShowCreateTable.prototype.toString = function () {
15197
15250
  var s = 'SHOW CREATE TABLE ' + this.table.tableid;
@@ -15230,7 +15283,7 @@ yy.ShowCreateTable.prototype.execute = function (databaseid) {
15230
15283
  */
15231
15284
 
15232
15285
  yy.SetVariable = function (params) {
15233
- return yy.extend(this, params);
15286
+ return Object.assign(this, params);
15234
15287
  };
15235
15288
  yy.SetVariable.prototype.toString = function () {
15236
15289
  var s = 'SET ';
@@ -15621,7 +15674,7 @@ alasql.prompt = function (el, useidel, firstsql) {
15621
15674
  //
15622
15675
  */
15623
15676
  yy.BeginTransaction = function (params) {
15624
- return yy.extend(this, params);
15677
+ return Object.assign(this, params);
15625
15678
  };
15626
15679
  yy.BeginTransaction.prototype.toString = function () {
15627
15680
  return 'BEGIN TRANSACTION';
@@ -15639,7 +15692,7 @@ yy.BeginTransaction.prototype.execute = function (databaseid, params, cb) {
15639
15692
  };
15640
15693
 
15641
15694
  yy.CommitTransaction = function (params) {
15642
- return yy.extend(this, params);
15695
+ return Object.assign(this, params);
15643
15696
  };
15644
15697
  yy.CommitTransaction.prototype.toString = function () {
15645
15698
  return 'COMMIT TRANSACTION';
@@ -15657,7 +15710,7 @@ yy.CommitTransaction.prototype.execute = function (databaseid, params, cb) {
15657
15710
  };
15658
15711
 
15659
15712
  yy.RollbackTransaction = function (params) {
15660
- return yy.extend(this, params);
15713
+ return Object.assign(this, params);
15661
15714
  };
15662
15715
  yy.RollbackTransaction.prototype.toString = function () {
15663
15716
  return 'ROLLBACK TRANSACTION';
@@ -17526,7 +17579,7 @@ alasql.from.GEXF = function (filename, opts, cb, idx, query) {
17526
17579
  /* globals: alasql, yy */
17527
17580
 
17528
17581
  /**
17529
- Print statement
17582
+ Print statement
17530
17583
  @class
17531
17584
  @param {object} params Initial setup properties
17532
17585
  */
@@ -17534,11 +17587,11 @@ alasql.from.GEXF = function (filename, opts, cb, idx, query) {
17534
17587
  /* global alasql, yy */
17535
17588
 
17536
17589
  yy.Print = function (params) {
17537
- return yy.extend(this, params);
17590
+ return Object.assign(this, params);
17538
17591
  };
17539
17592
 
17540
- /**
17541
- Generate SQL string
17593
+ /**
17594
+ Generate SQL string
17542
17595
  @this Print statement object
17543
17596
  */
17544
17597
  yy.Print.prototype.toString = function () {
@@ -17551,7 +17604,7 @@ yy.Print.prototype.toString = function () {
17551
17604
  Print result of select statement or expression
17552
17605
  @param {string} databaseid Database identificator
17553
17606
  @param {object} params Query parameters
17554
- @param {statement-callback} cb Callback function
17607
+ @param {statement-callback} cb Callback function
17555
17608
  @this Print statement object
17556
17609
  */
17557
17610
  yy.Print.prototype.execute = function (databaseid, params, cb) {
@@ -17592,7 +17645,7 @@ yy.Print.prototype.execute = function (databaseid, params, cb) {
17592
17645
  */
17593
17646
 
17594
17647
  yy.Source = function (params) {
17595
- return yy.extend(this, params);
17648
+ return Object.assign(this, params);
17596
17649
  };
17597
17650
  yy.Source.prototype.toString = function () {
17598
17651
  var s = 'SOURCE';
@@ -17632,7 +17685,7 @@ yy.Source.prototype.execute = function (databaseid, params, cb) {
17632
17685
  /* global alasql, yy */
17633
17686
 
17634
17687
  yy.Require = function (params) {
17635
- return yy.extend(this, params);
17688
+ return Object.assign(this, params);
17636
17689
  };
17637
17690
  yy.Require.prototype.toString = function () {
17638
17691
  var s = 'REQUIRE';
@@ -17704,7 +17757,7 @@ yy.Require.prototype.execute = function (databaseid, params, cb) {
17704
17757
  */
17705
17758
 
17706
17759
  yy.Assert = function (params) {
17707
- return yy.extend(this, params);
17760
+ return Object.assign(this, params);
17708
17761
  };
17709
17762
  yy.Source.prototype.toString = function () {
17710
17763
  var s = 'ASSERT';
@@ -17781,29 +17834,46 @@ var IDB = (alasql.engines.INDEXEDDB = function () {
17781
17834
  '';
17782
17835
  });
17783
17836
 
17784
- if (utils.hasIndexedDB) {
17785
- // For Chrome it work normally, for Firefox - simple shim
17786
- if (typeof utils.global.indexedDB.webkitGetDatabaseNames == 'function') {
17787
- IDB.getDatabaseNames = utils.global.indexedDB.webkitGetDatabaseNames.bind(
17788
- utils.global.indexedDB
17789
- );
17790
- } else {
17791
- IDB.getDatabaseNames = function () {
17792
- var request = {};
17793
- var result = {
17794
- contains: function (name) {
17795
- return true; // Always return true
17796
- },
17797
- notsupported: true,
17798
- };
17799
- setTimeout(function () {
17800
- var event = {target: {result: result}};
17801
- request.onsuccess(event);
17802
- }, 0);
17803
- return request;
17804
- };
17805
- IDB.getDatabaseNamesNotSupported = true;
17837
+ /**
17838
+ * @param {string} name
17839
+ * @returns {Promise<{name: string, version: number}|0>}
17840
+ */
17841
+ async function _databaseExists(name) {
17842
+ const indexedDB = globalThis.indexedDB;
17843
+
17844
+ if (!indexedDB) {
17845
+ throw new Error('IndexedDB is not supported in this browser');
17846
+ }
17847
+
17848
+ if (indexedDB.databases) {
17849
+ const dbs = await indexedDB.databases();
17850
+ const db = dbs.find((db) => db.name === name);
17851
+ // @ts-ignore
17852
+ return db || 0;
17806
17853
  }
17854
+
17855
+ // Try if it exist
17856
+ const req = indexedDB.open(name);
17857
+
17858
+ return new Promise(function (resolve, reject) {
17859
+ req.onsuccess = () => {
17860
+ req.result.close();
17861
+ resolve({name, version: req.result.version});
17862
+ };
17863
+
17864
+ req.onupgradeneeded = (evt) => {
17865
+ evt.target.transaction.abort();
17866
+ resolve(0);
17867
+ };
17868
+
17869
+ req.onerror = () => {
17870
+ reject(new Error('IndexedDB error'));
17871
+ };
17872
+
17873
+ req.onblocked = () => {
17874
+ resolve({name, version: req.result.version});
17875
+ };
17876
+ });
17807
17877
  }
17808
17878
 
17809
17879
  //
@@ -17811,333 +17881,235 @@ if (utils.hasIndexedDB) {
17811
17881
  // work only in chrome
17812
17882
  //
17813
17883
  IDB.showDatabases = function (like, cb) {
17884
+ if (!indexedDB.databases) {
17885
+ cb(null, new Error('SHOW DATABASE is not supported in this browser'));
17886
+ return;
17887
+ }
17888
+
17889
+ indexedDB.databases().then((dblist) => {
17890
+ const res = [];
17891
+ const relike = like && new RegExp(like.value.replace(/\%/g, '.*'), 'g');
17814
17892
 
17815
- var request = IDB.getDatabaseNames();
17816
- request.onsuccess = function (event) {
17817
- var dblist = event.target.result;
17818
- if (IDB.getDatabaseNamesNotSupported) {
17819
- throw new Error('SHOW DATABASE is not supported in this browser');
17820
- }
17821
- var res = [];
17822
- if (like) {
17823
- var relike = new RegExp(like.value.replace(/\%/g, '.*'), 'g');
17824
- }
17825
17893
  for (var i = 0; i < dblist.length; i++) {
17826
- if (!like || dblist[i].match(relike)) {
17827
- res.push({databaseid: dblist[i]});
17894
+ if (!like || dblist[i].name.match(relike)) {
17895
+ res.push({databaseid: dblist[i].name});
17828
17896
  }
17829
17897
  }
17898
+
17830
17899
  cb(res);
17831
- };
17900
+ });
17832
17901
  };
17833
17902
 
17834
- IDB.createDatabase = function (ixdbid, args, ifnotexists, dbid, cb) {
17835
-
17836
- var indexedDB = utils.global.indexedDB;
17837
- if (ifnotexists) {
17838
- var request2 = indexedDB.open(ixdbid, 1);
17839
- request2.onsuccess = function (event) {
17840
- event.target.result.close();
17841
- if (cb) cb(1);
17842
- };
17843
- } else {
17844
- var request1 = indexedDB.open(ixdbid, 1);
17845
- request1.onupgradeneeded = function (e) {
17846
-
17847
- e.target.transaction.abort();
17848
- };
17849
- request1.onsuccess = function (e) {
17850
-
17851
- if (ifnotexists) {
17852
- if (cb) cb(0);
17853
- } else {
17854
- throw new Error(
17855
- 'IndexedDB: Cannot create new database "' + ixdbid + '" because it already exists'
17856
- );
17857
- }
17858
- };
17859
- }
17860
-
17861
- };
17903
+ IDB.createDatabase = async function (ixdbid, args, ifnotexists, dbid, cb) {
17904
+ const found = await _databaseExists(ixdbid).catch((err) => {
17905
+ if (cb) cb(null, err);
17906
+ throw err;
17907
+ });
17862
17908
 
17863
- IDB.createDatabase = function (ixdbid, args, ifnotexists, dbid, cb) {
17864
- var indexedDB = utils.global.indexedDB;
17865
- if (IDB.getDatabaseNamesNotSupported) {
17866
- // Hack for Firefox
17909
+ if (found) {
17867
17910
  if (ifnotexists) {
17868
-
17869
- var dbExists = true;
17870
- var request2 = indexedDB.open(ixdbid);
17871
-
17872
- request2.onupgradeneeded = function (e) {
17873
-
17874
- dbExists = false;
17875
- // e.target.transaction.abort();
17876
- // cb(0);
17877
- };
17878
- request2.onsuccess = function (event) {
17879
-
17880
- event.target.result.close();
17881
- if (dbExists) {
17882
- if (cb) cb(0);
17883
- } else {
17884
- if (cb) cb(1);
17885
- }
17886
- };
17911
+ cb && cb(0);
17887
17912
  } else {
17888
-
17889
- var request1 = indexedDB.open(ixdbid);
17890
- request1.onupgradeneeded = function (e) {
17891
- e.target.transaction.abort();
17892
- };
17893
- request1.onabort = function (event) {
17894
- if (cb) cb(1);
17895
- };
17896
- request1.onsuccess = function (event) {
17897
- event.target.result.close();
17898
- throw new Error(
17899
- 'IndexedDB: Cannot create new database "' + ixdbid + '" because it already exists'
17900
- );
17901
- // cb(0);
17902
- };
17913
+ const err = new Error(
17914
+ `IndexedDB: Cannot create new database "${ixdbid}" because it already exists`
17915
+ );
17916
+ if (cb) cb(null, err);
17903
17917
  }
17904
17918
  } else {
17905
- var request1 = IDB.getDatabaseNames();
17906
- request1.onsuccess = function (event) {
17907
- var dblist = event.target.result;
17908
- if (dblist.contains(ixdbid)) {
17909
- if (ifnotexists) {
17910
- if (cb) cb(0);
17911
- return;
17912
- } else {
17913
- throw new Error(
17914
- 'IndexedDB: Cannot create new database "' + ixdbid + '" because it already exists'
17915
- );
17916
- }
17917
- }
17918
-
17919
- var request2 = indexedDB.open(ixdbid, 1);
17920
- request2.onsuccess = function (event) {
17921
- event.target.result.close();
17922
- if (cb) cb(1);
17923
- };
17919
+ const request = indexedDB.open(ixdbid, 1);
17920
+ request.onsuccess = () => {
17921
+ request.result.close();
17922
+ cb(1);
17924
17923
  };
17925
17924
  }
17926
17925
  };
17927
17926
 
17928
- IDB.dropDatabase = function (ixdbid, ifexists, cb) {
17929
- var indexedDB = utils.global.indexedDB;
17930
- var request1 = IDB.getDatabaseNames();
17931
- request1.onsuccess = function (event) {
17932
- var dblist = event.target.result;
17933
- if (!dblist.contains(ixdbid)) {
17934
- if (ifexists) {
17935
- if (cb) cb(0);
17936
- return;
17937
- } else {
17938
- throw new Error(
17939
- 'IndexedDB: Cannot drop new database "' + ixdbid + '" because it does not exist'
17940
- );
17941
- }
17942
- }
17943
- var request2 = indexedDB.deleteDatabase(ixdbid);
17944
- request2.onsuccess = function (event) {
17927
+ IDB.dropDatabase = async function (ixdbid, ifexists, cb) {
17928
+ const found = await _databaseExists(ixdbid).catch((err) => {
17929
+ if (cb) cb(null, err);
17930
+ throw err;
17931
+ });
17945
17932
 
17933
+ if (found) {
17934
+ const request = indexedDB.deleteDatabase(ixdbid);
17935
+ request.onsuccess = () => {
17946
17936
  if (cb) cb(1);
17947
17937
  };
17948
- };
17949
- };
17950
-
17951
- IDB.attachDatabase = function (ixdbid, dbid, args, params, cb) {
17952
- if (!utils.hasIndexedDB) {
17953
- throw new Error('The current browser does not support IndexedDB');
17954
- }
17955
- var indexedDB = utils.global.indexedDB;
17956
- var request1 = IDB.getDatabaseNames();
17957
- request1.onsuccess = function (event) {
17958
- var dblist = event.target.result;
17959
- if (!dblist.contains(ixdbid)) {
17960
- throw new Error(
17961
- 'IndexedDB: Cannot attach database "' + ixdbid + '" because it does not exist'
17962
- );
17938
+ } else {
17939
+ if (ifexists) {
17940
+ cb && cb(0);
17941
+ } else {
17942
+ cb &&
17943
+ cb(
17944
+ null,
17945
+ new Error(`IndexedDB: Cannot drop new database "${ixdbid}" because it does not exist'`)
17946
+ );
17963
17947
  }
17964
- var request2 = indexedDB.open(ixdbid);
17965
- request2.onsuccess = function (event) {
17966
- var ixdb = event.target.result;
17967
- var db = new alasql.Database(dbid || ixdbid);
17968
- db.engineid = 'INDEXEDDB';
17969
- db.ixdbid = ixdbid;
17970
- db.tables = [];
17971
- var tblist = ixdb.objectStoreNames;
17972
- for (var i = 0; i < tblist.length; i++) {
17973
- db.tables[tblist[i]] = {};
17974
- }
17975
-
17976
- event.target.result.close();
17977
- if (cb) cb(1);
17978
- };
17979
- };
17948
+ }
17980
17949
  };
17981
17950
 
17982
- IDB.createTable = function (databaseid, tableid, ifnotexists, cb) {
17983
- var indexedDB = utils.global.indexedDB;
17984
-
17985
- var ixdbid = alasql.databases[databaseid].ixdbid;
17951
+ IDB.attachDatabase = async function (ixdbid, dbid, args, params, cb) {
17952
+ const found = await _databaseExists(ixdbid).catch((err) => {
17953
+ if (cb) cb(null, err);
17954
+ throw err;
17955
+ });
17986
17956
 
17987
- var request1 = IDB.getDatabaseNames();
17988
- request1.onsuccess = function (event__) {
17989
- var dblist = event__.target.result;
17990
- if (!dblist.contains(ixdbid)) {
17991
- throw new Error(
17992
- 'IndexedDB: Cannot create table in database "' + ixdbid + '" because it does not exist'
17993
- );
17994
- }
17995
- var request2 = indexedDB.open(ixdbid);
17996
- request2.onversionchange = function (event_) {
17957
+ if (!found) {
17958
+ const err = new Error(
17959
+ `IndexedDB: Cannot attach database "${ixdbid}" because it does not exist`
17960
+ );
17961
+ if (cb) cb(null, err);
17962
+ throw err;
17963
+ }
17997
17964
 
17998
- event_.target.result.close();
17965
+ const stores = await new Promise((resolve, reject) => {
17966
+ const request = indexedDB.open(ixdbid);
17967
+ request.onsuccess = () => {
17968
+ resolve(request.result.objectStoreNames);
17969
+ request.result.close();
17999
17970
  };
18000
- request2.onsuccess = function (event_) {
18001
- var version = event_.target.result.version;
18002
- event_.target.result.close();
17971
+ });
18003
17972
 
18004
- var request3 = indexedDB.open(ixdbid, version + 1);
18005
- request3.onupgradeneeded = function (event) {
18006
- var ixdb = event.target.result;
17973
+ const db = new alasql.Database(dbid || ixdbid);
17974
+ db.engineid = 'INDEXEDDB';
17975
+ db.ixdbid = ixdbid;
17976
+ db.tables = [];
18007
17977
 
18008
- var store = ixdb.createObjectStore(tableid, {autoIncrement: true});
17978
+ for (var i = 0; i < stores.length; i++) {
17979
+ db.tables[stores[i]] = {};
17980
+ }
18009
17981
 
18010
- };
18011
- request3.onsuccess = function (event) {
17982
+ if (cb) cb(1);
17983
+ };
18012
17984
 
18013
- event.target.result.close();
18014
- if (cb) cb(1);
18015
- };
18016
- request3.onerror = function (event) {
18017
- throw event;
17985
+ IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
17986
+ const ixdbid = alasql.databases[databaseid].ixdbid;
17987
+ const found = await _databaseExists(ixdbid).catch((err) => {
17988
+ if (cb) cb(null, err);
17989
+ throw err;
17990
+ });
18018
17991
 
18019
- };
18020
- request3.onblocked = function (event) {
18021
- throw new Error(
18022
- 'Cannot create table "' + tableid + '" because database "' + databaseid + '" is blocked'
18023
- );
17992
+ if (!found) {
17993
+ const err = new Error(
17994
+ 'IndexedDB: Cannot create table in database "' + ixdbid + '" because it does not exist'
17995
+ );
17996
+ if (cb) cb(null, err);
17997
+ throw err;
17998
+ }
18024
17999
 
18025
- };
18026
- };
18000
+ const request = indexedDB.open(ixdbid, found.version + 1);
18001
+ request.onupgradeneeded = function (event) {
18002
+ request.result.createObjectStore(tableid, {autoIncrement: true});
18003
+ };
18004
+ request.onsuccess = function (event) {
18005
+ request.result.close();
18006
+ if (cb) cb(1);
18007
+ };
18008
+ request.onerror = (evt) => {
18009
+ cb(null, evt);
18010
+ };
18011
+ request.onblocked = function (event) {
18012
+ cb(
18013
+ null,
18014
+ new Error(`Cannot create table "${tableid}" because database "${databaseid}" is blocked`)
18015
+ );
18027
18016
  };
18028
18017
  };
18029
18018
 
18030
- IDB.dropTable = function (databaseid, tableid, ifexists, cb) {
18031
- var indexedDB = utils.global.indexedDB;
18032
- var ixdbid = alasql.databases[databaseid].ixdbid;
18033
-
18034
- var request1 = IDB.getDatabaseNames();
18035
- request1.onsuccess = function (event) {
18036
- var dblist = event.target.result;
18037
-
18038
- if (!dblist.contains(ixdbid)) {
18039
- throw new Error(
18040
- 'IndexedDB: Cannot drop table in database "' + ixdbid + '" because it does not exist'
18041
- );
18042
- }
18043
-
18044
- var request2 = indexedDB.open(ixdbid);
18045
- request2.onversionchange = function (event) {
18046
- event.target.result.close();
18047
- };
18048
-
18049
- request2.onsuccess = function (event) {
18050
- var version = event.target.result.version;
18051
- event.target.result.close();
18052
-
18053
- var request3 = indexedDB.open(ixdbid, version + 1);
18054
- request3.onupgradeneeded = function (event) {
18055
- var ixdb = event.target.result;
18056
- if (ixdb.objectStoreNames.contains(tableid)) {
18057
- ixdb.deleteObjectStore(tableid);
18058
- delete alasql.databases[databaseid].tables[tableid];
18059
- } else {
18060
- if (!ifexists) {
18061
- throw new Error(
18062
- 'IndexedDB: Cannot drop table "' + tableid + '" because it does not exist'
18063
- );
18064
- }
18065
- }
18066
- // var store = ixdb.createObjectStore(tableid);
18067
-
18068
- };
18069
- request3.onsuccess = function (event) {
18019
+ IDB.dropTable = async function (databaseid, tableid, ifexists, cb) {
18020
+ const ixdbid = alasql.databases[databaseid].ixdbid;
18021
+ const found = await _databaseExists(ixdbid).catch((err) => {
18022
+ if (cb) cb(null, err);
18023
+ throw err;
18024
+ });
18070
18025
 
18071
- event.target.result.close();
18072
- if (cb) cb(1);
18073
- };
18074
- request3.onerror = function (event) {
18026
+ if (!found) {
18027
+ const err = new Error(
18028
+ 'IndexedDB: Cannot drop table in database "' + ixdbid + '" because it does not exist'
18029
+ );
18030
+ if (cb) cb(null, err);
18031
+ throw err;
18032
+ }
18075
18033
 
18076
- throw event;
18077
- };
18078
- request3.onblocked = function (event) {
18079
- throw new Error(
18080
- 'Cannot drop table "' + tableid + '" because database "' + databaseid + '" is blocked'
18081
- );
18034
+ const request = indexedDB.open(ixdbid, found.version + 1);
18082
18035
 
18083
- };
18084
- };
18036
+ let err;
18037
+ request.onupgradeneeded = function (evt) {
18038
+ var ixdb = request.result;
18039
+ if (ixdb.objectStoreNames.contains(tableid)) {
18040
+ ixdb.deleteObjectStore(tableid);
18041
+ delete alasql.databases[databaseid].tables[tableid];
18042
+ } else {
18043
+ if (!ifexists) {
18044
+ err = new Error(`IndexedDB: Cannot drop table "${tableid}" because it does not exist`);
18045
+ evt.target.transaction.abort();
18046
+ }
18047
+ }
18048
+ };
18049
+ request.onsuccess = function (event) {
18050
+ request.result.close();
18051
+ if (cb) cb(1);
18052
+ };
18053
+ request.onerror = function (event) {
18054
+ cb && cb(null, err || event);
18055
+ };
18056
+ request.onblocked = function (event) {
18057
+ cb(
18058
+ null,
18059
+ new Error(`Cannot drop table "${tableid}" because database "${databaseid}" is blocked`)
18060
+ );
18085
18061
  };
18086
18062
  };
18087
18063
 
18088
18064
  IDB.intoTable = function (databaseid, tableid, value, columns, cb) {
18065
+ const ixdbid = alasql.databases[databaseid].ixdbid;
18066
+ const request = indexedDB.open(ixdbid);
18089
18067
 
18090
- // console.trace();
18068
+ request.onupgradeneeded = (evt) => {
18069
+ evt.target.transaction.abort();
18070
+ const err = new Error(
18071
+ `Cannot insert into table "${tableid}" because database "${databaseid}" does not exist`
18072
+ );
18073
+ if (cb) cb(null, err);
18074
+ };
18091
18075
 
18092
- var indexedDB = utils.global.indexedDB;
18093
- var ixdbid = alasql.databases[databaseid].ixdbid;
18094
- var request1 = indexedDB.open(ixdbid);
18095
- request1.onsuccess = function (event) {
18096
- var ixdb = event.target.result;
18076
+ request.onsuccess = () => {
18077
+ var ixdb = request.result;
18097
18078
  var tx = ixdb.transaction([tableid], 'readwrite');
18098
18079
  var tb = tx.objectStore(tableid);
18099
-
18100
18080
  for (var i = 0, ilen = value.length; i < ilen; i++) {
18101
18081
  tb.add(value[i]);
18102
18082
  }
18103
18083
  tx.oncomplete = function () {
18104
18084
  ixdb.close();
18105
-
18106
18085
  if (cb) cb(ilen);
18107
18086
  };
18108
18087
  };
18109
-
18110
18088
  };
18111
18089
 
18112
18090
  IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
18091
+ const ixdbid = alasql.databases[databaseid].ixdbid;
18092
+ const request = indexedDB.open(ixdbid);
18113
18093
 
18114
- // console.trace();
18115
- var indexedDB = utils.global.indexedDB;
18116
- var ixdbid = alasql.databases[databaseid].ixdbid;
18117
- var request = indexedDB.open(ixdbid);
18118
- request.onsuccess = function (event) {
18119
- var res = [];
18120
- var ixdb = event.target.result;
18121
-
18122
- var tx = ixdb.transaction([tableid]);
18123
- var store = tx.objectStore(tableid);
18124
- var cur = store.openCursor();
18125
-
18126
- cur.onblocked = function (event) {
18127
-
18128
- };
18129
- cur.onerror = function (event) {
18130
-
18131
- };
18132
- cur.onsuccess = function (event) {
18094
+ request.onupgradeneeded = (evt) => {
18095
+ evt.target.transaction.abort();
18096
+ const err = new Error(
18097
+ `Cannot select from table "${tableid}" because database "${databaseid}" does not exist`
18098
+ );
18099
+ if (cb) cb(null, err);
18100
+ };
18133
18101
 
18134
- var cursor = event.target.result;
18102
+ request.onsuccess = () => {
18103
+ const res = [];
18104
+ const ixdb = request.result;
18105
+ const cur = ixdb.transaction([tableid]).objectStore(tableid).openCursor();
18135
18106
 
18107
+ cur.onsuccess = () => {
18108
+ const cursor = cur.result;
18136
18109
  if (cursor) {
18137
18110
  res.push(cursor.value);
18138
18111
  cursor.continue();
18139
18112
  } else {
18140
-
18141
18113
  ixdb.close();
18142
18114
  if (cb) cb(res, idx, query);
18143
18115
  }
@@ -18146,39 +18118,23 @@ IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
18146
18118
  };
18147
18119
 
18148
18120
  IDB.deleteFromTable = function (databaseid, tableid, wherefn, params, cb) {
18121
+ const ixdbid = alasql.databases[databaseid].ixdbid;
18122
+ const request = indexedDB.open(ixdbid);
18149
18123
 
18150
- // console.trace();
18151
- var indexedDB = utils.global.indexedDB;
18152
- var ixdbid = alasql.databases[databaseid].ixdbid;
18153
- var request = indexedDB.open(ixdbid);
18154
- request.onsuccess = function (event) {
18155
- var res = [];
18156
- var ixdb = event.target.result;
18157
-
18158
- var tx = ixdb.transaction([tableid], 'readwrite');
18159
- var store = tx.objectStore(tableid);
18160
- var cur = store.openCursor();
18161
- var num = 0;
18162
-
18163
- cur.onblocked = function (event) {
18164
-
18165
- };
18166
- cur.onerror = function (event) {
18167
-
18168
- };
18169
- cur.onsuccess = function (event) {
18170
-
18171
- var cursor = event.target.result;
18124
+ request.onsuccess = () => {
18125
+ const ixdb = request.result;
18126
+ const cur = ixdb.transaction([tableid], 'readwrite').objectStore(tableid).openCursor();
18172
18127
 
18128
+ let num = 0;
18129
+ cur.onsuccess = () => {
18130
+ var cursor = cur.result;
18173
18131
  if (cursor) {
18174
- if (!wherefn || wherefn(cursor.value, params)) {
18175
-
18132
+ if (!wherefn || wherefn(cursor.value, params, alasql)) {
18176
18133
  cursor.delete();
18177
18134
  num++;
18178
18135
  }
18179
18136
  cursor.continue();
18180
18137
  } else {
18181
-
18182
18138
  ixdb.close();
18183
18139
  if (cb) cb(num);
18184
18140
  }
@@ -18187,42 +18143,24 @@ IDB.deleteFromTable = function (databaseid, tableid, wherefn, params, cb) {
18187
18143
  };
18188
18144
 
18189
18145
  IDB.updateTable = function (databaseid, tableid, assignfn, wherefn, params, cb) {
18190
-
18191
- // console.trace();
18192
- var indexedDB = utils.global.indexedDB;
18193
- var ixdbid = alasql.databases[databaseid].ixdbid;
18194
- var request = indexedDB.open(ixdbid);
18195
- request.onsuccess = function (event) {
18196
- var res = [];
18197
- var ixdb = event.target.result;
18198
-
18199
- var tx = ixdb.transaction([tableid], 'readwrite');
18200
- var store = tx.objectStore(tableid);
18201
- var cur = store.openCursor();
18202
- var num = 0;
18203
-
18204
- cur.onblocked = function (event) {
18205
-
18206
- };
18207
- cur.onerror = function (event) {
18208
-
18209
- };
18210
- cur.onsuccess = function (event) {
18211
-
18212
- var cursor = event.target.result;
18213
-
18146
+ const ixdbid = alasql.databases[databaseid].ixdbid;
18147
+ const request = indexedDB.open(ixdbid);
18148
+ request.onsuccess = function () {
18149
+ const ixdb = request.result;
18150
+ const cur = ixdb.transaction([tableid], 'readwrite').objectStore(tableid).openCursor();
18151
+
18152
+ let num = 0;
18153
+ cur.onsuccess = () => {
18154
+ var cursor = cur.result;
18214
18155
  if (cursor) {
18215
18156
  if (!wherefn || wherefn(cursor.value, params)) {
18216
-
18217
18157
  var r = cursor.value;
18218
18158
  assignfn(r, params);
18219
-
18220
18159
  cursor.update(r);
18221
18160
  num++;
18222
18161
  }
18223
18162
  cursor.continue();
18224
18163
  } else {
18225
-
18226
18164
  ixdb.close();
18227
18165
  if (cb) cb(num);
18228
18166
  }