alasql 4.1.2 → 4.1.4

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 v4.1.1 build: develop-a17cafee | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.1.3 build: develop-04e3bf66 | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.1.1
4
+ @version 4.1.3
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2023 Andrey Gershun & Mathias Wulff
@@ -142,8 +142,8 @@ var alasql = function(sql, params, cb, scope) {
142
142
  Current version of alasql
143
143
  @constant {string}
144
144
  */
145
- alasql.version = '4.1.1';
146
- alasql.build = 'develop-a17cafee';
145
+ alasql.version = '4.1.3';
146
+ alasql.build = 'develop-04e3bf66';
147
147
 
148
148
  /**
149
149
  Debug flag
@@ -3490,7 +3490,7 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
3490
3490
  });
3491
3491
  } else {
3492
3492
  if (/^[a-z]+:\/\//i.test(path)) {
3493
- fetchData(path, (x) => success(cutbom(x)), error, asy);
3493
+ fetchData(path, x => success(cutbom(x)), error, asy);
3494
3494
  } else {
3495
3495
  //If async callthen call async
3496
3496
  if (asy) {
@@ -3553,7 +3553,7 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
3553
3553
  Simply read file from HTTP request, like:
3554
3554
  SELECT * FROM TXT('http://alasql.org/README.md');
3555
3555
  */
3556
- fetchData(path, (x) => success(cutbom(x)), error, asy);
3556
+ fetchData(path, x => success(cutbom(x)), error, asy);
3557
3557
  }
3558
3558
  } else if (path instanceof Event) {
3559
3559
  /*
@@ -3594,13 +3594,13 @@ async function fetchData(path, success, error, async) {
3594
3594
 
3595
3595
  function getData(path, success, error) {
3596
3596
  return _fetch(path)
3597
- .then((response) => response.arrayBuffer())
3598
- .then((buf) => {
3597
+ .then(response => response.arrayBuffer())
3598
+ .then(buf => {
3599
3599
  var a = new Uint8Array(buf);
3600
- var b = [...a].map((e) => String.fromCharCode(e)).join('');
3600
+ var b = [...a].map(e => String.fromCharCode(e)).join('');
3601
3601
  success(b);
3602
3602
  })
3603
- .catch((e) => {
3603
+ .catch(e => {
3604
3604
  if (error) return error(e);
3605
3605
  console.error(e);
3606
3606
  throw e;
@@ -3622,7 +3622,7 @@ var loadBinaryFile = (utils.loadBinaryFile = function (
3622
3622
  path,
3623
3623
  runAsync,
3624
3624
  success,
3625
- error = (x) => {
3625
+ error = x => {
3626
3626
  throw x;
3627
3627
  }
3628
3628
  ) {
@@ -4866,9 +4866,9 @@ var promiseExec = function (sql, params, counterStep, counterTotal) {
4866
4866
 
4867
4867
  const sequentialPromiseResolver = (promiseData, Promise) => {
4868
4868
  var startingPoint = Promise.resolve([]);
4869
- promiseData.forEach((p) => {
4870
- startingPoint = startingPoint.then((previousResult) =>
4871
- promiseExec(p.sql, p.params, p.i, p.length).then((result) => [...previousResult, result])
4869
+ promiseData.forEach(p => {
4870
+ startingPoint = startingPoint.then(previousResult =>
4871
+ promiseExec(p.sql, p.params, p.i, p.length).then(result => [...previousResult, result])
4872
4872
  );
4873
4873
  });
4874
4874
 
@@ -4955,7 +4955,7 @@ var Database = (alasql.Database = function (databaseid) {
4955
4955
  alasql.databases[databaseid] = self;
4956
4956
  // }
4957
4957
  if (!self) {
4958
- throw new Error('Database "' + databaseid + '" not found');
4958
+ throw new Error(`Database ${databaseid} not found`);
4959
4959
  }
4960
4960
  } else {
4961
4961
  // Create new database (or get alasql?)
@@ -5272,16 +5272,16 @@ yy.Statements = class Statements {
5272
5272
  }
5273
5273
 
5274
5274
  toString() {
5275
- return this.statements.map((st) => st.toString()).join('; ');
5275
+ return this.statements.map(st => st.toString()).join('; ');
5276
5276
  }
5277
5277
 
5278
5278
  // Compile array of statements into single statement
5279
5279
  compile(db) {
5280
- const statements = this.statements.map((st) => st.compile(db));
5280
+ const statements = this.statements.map(st => st.compile(db));
5281
5281
  return statements.length === 1
5282
5282
  ? statements[0]
5283
5283
  : (params, cb) => {
5284
- const res = statements.map((st) => st(params));
5284
+ const res = statements.map(st => st(params));
5285
5285
  if (cb) cb(res);
5286
5286
  return res;
5287
5287
  };
@@ -5351,10 +5351,6 @@ yy.Search = class Search {
5351
5351
  r, // temp value used many places
5352
5352
  sel = selectors[sidx];
5353
5353
 
5354
- // if(!alasql.srch[sel.srchid]) {
5355
- // throw new Error('Selector "'+sel.srchid+'" not found');
5356
- // };
5357
-
5358
5354
  var INFINITE_LOOP_BREAK = alasql.options.loopbreak || 100000;
5359
5355
 
5360
5356
  if (sel.selid) {
@@ -5977,7 +5973,7 @@ alasql.srch = {
5977
5973
  PROP(val, args, stope) {
5978
5974
 
5979
5975
  if (stope.mode === 'XML') {
5980
- const values = val.children.filter((v) => v.name.toUpperCase() === args[0].toUpperCase());
5976
+ const values = val.children.filter(v => v.name.toUpperCase() === args[0].toUpperCase());
5981
5977
 
5982
5978
  return {
5983
5979
  status: values.length ? 1 : -1,
@@ -6297,13 +6293,12 @@ alasql.srch = {
6297
6293
 
6298
6294
  var s = args
6299
6295
  .map(function (st) {
6300
-
6301
6296
  if (st.method === '@') {
6302
- return "alasql.vars['" + st.variable + "']=" + st.expression.toJS('x', '');
6297
+ return `alasql.vars[${JSON.stringify(st.variable)}]=` + st.expression.toJS('x', '');
6303
6298
  } else if (st.method === '$') {
6304
- return "params['" + st.variable + "']=" + st.expression.toJS('x', '');
6299
+ return `params[${JSON.stringify(st.variable)}]=` + st.expression.toJS('x', '');
6305
6300
  } else {
6306
- return "x['" + st.column.columnid + "']=" + st.expression.toJS('x', '');
6301
+ return `x[${JSON.stringify(st.column.columnid)}]=` + st.expression.toJS('x', '');
6307
6302
  }
6308
6303
  })
6309
6304
  .join(';');
@@ -6316,7 +6311,7 @@ alasql.srch = {
6316
6311
 
6317
6312
  ROW(val, args, stope, params) {
6318
6313
  var s = 'var y;return [';
6319
- s += args.map((arg) => arg.toJS('x', '')).join(',');
6314
+ s += args.map(arg => arg.toJS('x', '')).join(',');
6320
6315
  s += ']';
6321
6316
  var setfn = new Function('x,params,alasql', s);
6322
6317
  var rv = setfn(val, params, alasql);
@@ -6382,18 +6377,18 @@ var compileSearchOrder = function (order) {
6382
6377
  s += 'if(a' + dg + (ord.direction === 'ASC' ? '>' : '<') + 'b' + dg + ')return 1;';
6383
6378
  s += 'if(a' + dg + '==b' + dg + '){';
6384
6379
  } else {
6385
- s +=
6386
- "if((a['" +
6387
- columnid +
6388
- "']||'')" +
6389
- dg +
6390
- (ord.direction === 'ASC' ? '>' : '<') +
6391
- "(b['" +
6392
- columnid +
6393
- "']||'')" +
6394
- dg +
6395
- ')return 1;';
6396
- s += "if((a['" + columnid + "']||'')" + dg + "==(b['" + columnid + "']||'')" + dg + '){';
6380
+ s += `if (
6381
+ (a[${JSON.stringify(columnid)}]||'')${dg}
6382
+ ${ord.direction === 'ASC' ? '>' : '<'}
6383
+ (b[${JSON.stringify(columnid)}]||'')${dg}
6384
+ ) return 1;
6385
+
6386
+ if(
6387
+ (a[${JSON.stringify(columnid)}]||'')${dg}
6388
+ ==
6389
+ (b[${JSON.stringify(columnid)}]||'')${dg}
6390
+ ){
6391
+ `;
6397
6392
  }
6398
6393
  } else {
6399
6394
  dg = '.valueOf()';
@@ -6596,23 +6591,16 @@ function queryfn3(query) {
6596
6591
  if (query.aggrKeys.length > 0) {
6597
6592
  var gfns = '';
6598
6593
  query.aggrKeys.forEach(function (col) {
6599
- gfns +=
6600
- "g['" +
6601
- col.nick +
6602
- "']=alasql.aggr['" +
6603
- col.funcid +
6604
- "'](undefined,g['" +
6605
- col.nick +
6606
- "'],3);";
6594
+ gfns += `g[${JSON.stringify(col.nick)}] = alasql.aggr[${JSON.stringify(
6595
+ col.funcid
6596
+ )}](undefined,g[${JSON.stringify(col.nick)}],3);`;
6597
+
6607
6598
  // gfns += 'return g[\''+col.nick+'\];';
6608
6599
  });
6609
6600
 
6610
6601
  var gfn = new Function('g,params,alasql', 'var y;' + gfns);
6611
6602
  }
6612
6603
 
6613
- // return "'"+colas+'\':alasql.aggr[\''+col.funcid+'\']('+colexp+',undefined,(acc={}),1),'
6614
- // +'\'__REDUCE__'+colas+'\':acc,';
6615
-
6616
6604
  // *******
6617
6605
 
6618
6606
  // debugger;
@@ -7558,34 +7546,34 @@ yy.Select = class Select {
7558
7546
  alasql.databases[this.into.databaseid || databaseid].engineid
7559
7547
  ) {
7560
7548
  // For external database when AUTOCOMMIT is ONs
7561
- query.intoallfns =
7562
- 'return alasql.engines["' +
7563
- alasql.databases[this.into.databaseid || databaseid].engineid +
7564
- '"]' +
7565
- '.intoTable("' +
7566
- (this.into.databaseid || databaseid) +
7567
- '","' +
7568
- this.into.tableid +
7569
- '",this.data, columns, cb);';
7549
+ query.intoallfns = `return alasql
7550
+ .engines[${JSON.stringify(alasql.databases[this.into.databaseid || databaseid].engineid)}]
7551
+ .intoTable(
7552
+ ${JSON.stringify(this.into.databaseid || databaseid)},
7553
+ ${JSON.stringify(this.into.tableid)},
7554
+ this.data,
7555
+ columns,
7556
+ cb
7557
+ );`;
7570
7558
  } else {
7571
7559
  // Into AlaSQL tables
7572
- query.intofns =
7573
- "alasql.databases['" +
7574
- (this.into.databaseid || databaseid) +
7575
- "'].tables" +
7576
- "['" +
7577
- this.into.tableid +
7578
- "'].data.push(r);";
7560
+ query.intofns = `alasql
7561
+ .databases[${JSON.stringify(this.into.databaseid || databaseid)}]
7562
+ .tables[${JSON.stringify(this.into.tableid)}]
7563
+ .data.push(r);
7564
+ `;
7579
7565
  }
7580
7566
  } else if (this.into instanceof yy.VarValue) {
7581
7567
  //
7582
7568
  // Save into local variable
7583
7569
  // SELECT * INTO @VAR1 FROM ?
7584
7570
  //
7585
- query.intoallfns =
7586
- 'alasql.vars["' +
7587
- this.into.variable +
7588
- '"]=this.data;res=this.data.length;if(cb)res=cb(res);return res;';
7571
+ query.intoallfns = `
7572
+ alasql.vars[${JSON.stringify(this.into.variable)}]=this.data;
7573
+ res=this.data.length;
7574
+ if(cb) res = cb(res);
7575
+ return res;
7576
+ `;
7589
7577
  } else if (this.into instanceof yy.FuncValue) {
7590
7578
  //
7591
7579
  // If this is INTO() function, then call it
@@ -7609,7 +7597,7 @@ yy.Select = class Select {
7609
7597
  // Save data into parameters array
7610
7598
  // like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
7611
7599
  //
7612
- query.intofns = "params['" + this.into.param + "'].push(r)";
7600
+ query.intofns = `params[${JSON.stringify(this.into.param)}].push(r)`;
7613
7601
  }
7614
7602
 
7615
7603
  if (query.intofns) {
@@ -8712,7 +8700,7 @@ yy.Select.prototype.compileGroup = function (query) {
8712
8700
  // if(col instanceof yy.Column) colas = col.columnid;
8713
8701
  // else colas = col.toString();
8714
8702
  // };
8715
- let colExpIfFunIdExists = (expression) => {
8703
+ let colExpIfFunIdExists = expression => {
8716
8704
  let colexpression = expression.args[0];
8717
8705
  return colexpression.toJS('p', tableid, defcols);
8718
8706
  };
@@ -8837,7 +8825,7 @@ yy.Select.prototype.compileGroup = function (query) {
8837
8825
  var colas = col.nick;
8838
8826
 
8839
8827
  var colexp = col.expression.toJS('p', tableid, defcols);
8840
- let colExpIfFunIdExists = (expression) => {
8828
+ let colExpIfFunIdExists = expression => {
8841
8829
  let colexpression = expression.args[0];
8842
8830
  return colexpression.toJS('p', tableid, defcols);
8843
8831
  };
@@ -11677,7 +11665,7 @@ stdlib.UPPER = stdlib.UCASE = function (s) {
11677
11665
  // Concatination of strings
11678
11666
  stdfn.CONCAT_WS = function () {
11679
11667
  var args = Array.prototype.slice.call(arguments);
11680
- args = args.filter((x) => !(x === null || typeof x === 'undefined'));
11668
+ args = args.filter(x => !(x === null || typeof x === 'undefined'));
11681
11669
  return args.slice(1, args.length).join(args[0] || '');
11682
11670
  };
11683
11671
 
@@ -12462,14 +12450,14 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12462
12450
  }
12463
12451
 
12464
12452
  if (col.default) {
12465
- ss.push("'" + col.columnid + "':" + col.default.toJS('r', ''));
12453
+ ss.push(JSON.stringify('' + col.columnid) + ':' + col.default.toJS('r', ''));
12466
12454
  }
12467
12455
 
12468
12456
  // Check for primary key
12469
12457
  if (col.primarykey) {
12470
12458
  var pk = (table.pk = {});
12471
12459
  pk.columns = [col.columnid];
12472
- pk.onrightfns = "r['" + col.columnid + "']";
12460
+ pk.onrightfns = `r[${JSON.stringify(col.columnid)}]`;
12473
12461
  pk.onrightfn = new Function('r', 'var y;return ' + pk.onrightfns);
12474
12462
  pk.hh = hash(pk.onrightfns);
12475
12463
  table.uniqs[pk.hh] = {};
@@ -12481,7 +12469,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12481
12469
  table.uk = table.uk || [];
12482
12470
  table.uk.push(uk);
12483
12471
  uk.columns = [col.columnid];
12484
- uk.onrightfns = "r['" + col.columnid + "']";
12472
+ uk.onrightfns = `r[${JSON.stringify(col.columnid)}]`;
12485
12473
  uk.onrightfn = new Function('r', 'var y;return ' + uk.onrightfns);
12486
12474
  uk.hh = hash(uk.onrightfns);
12487
12475
  table.uniqs[uk.hh] = {};
@@ -12510,10 +12498,6 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12510
12498
 
12511
12499
  if (!fktable.uniqs[fktable.pk.hh][addr]) {
12512
12500
  throw new Error(
12513
- // 'Foreign key "' +
12514
- // r[col.columnid] +
12515
- // '" is not found in table ' +
12516
- // fktable.tableid
12517
12501
  'Foreign key violation' //changed error message
12518
12502
  );
12519
12503
  }
@@ -12524,7 +12508,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12524
12508
  }
12525
12509
 
12526
12510
  if (col.onupdate) {
12527
- uss.push("r['" + col.columnid + "']=" + col.onupdate.toJS('r', ''));
12511
+ uss.push(`r[${JSON.stringify(col.columnid)}]=` + col.onupdate.toJS('r', ''));
12528
12512
  }
12529
12513
 
12530
12514
  table.columns.push(newcol);
@@ -12547,7 +12531,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12547
12531
  pk.columns = con.columns;
12548
12532
  pk.onrightfns = pk.columns
12549
12533
  .map(function (columnid) {
12550
- return "r['" + columnid + "']";
12534
+ return `r[${JSON.stringify(columnid)}]`;
12551
12535
  })
12552
12536
  .join("+'`'+");
12553
12537
  pk.onrightfn = new Function('r', 'var y;return ' + pk.onrightfns);
@@ -12564,7 +12548,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12564
12548
  uk.columns = con.columns;
12565
12549
  uk.onrightfns = uk.columns
12566
12550
  .map(function (columnid) {
12567
- return "r['" + columnid + "']";
12551
+ return `r[${JSON.stringify(columnid)}]`;
12568
12552
  })
12569
12553
  .join("+'`'+");
12570
12554
  uk.onrightfn = new Function('r', 'var y;return ' + uk.onrightfns);
@@ -12617,7 +12601,11 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
12617
12601
  };
12618
12602
  }
12619
12603
  if (checkfn) {
12620
- table.checks.push({fn: checkfn, id: con.constraintid, fk: con.type === 'FOREIGN KEY'});
12604
+ table.checks.push({
12605
+ fn: checkfn,
12606
+ id: con.constraintid,
12607
+ fk: con.type === 'FOREIGN KEY',
12608
+ });
12621
12609
  }
12622
12610
  });
12623
12611
 
@@ -13198,7 +13186,9 @@ yy.DropTable.prototype.execute = function (databaseid, params, cb) {
13198
13186
  if (!db.tables[tableid]) {
13199
13187
  if (!alasql.options.dropifnotexists) {
13200
13188
  throw new Error(
13201
- "Can not drop table '" + table.tableid + "', because it does not exist in the database."
13189
+ `Can not drop table ${JSON.strnigify(
13190
+ table.tableid
13191
+ )} because it does not exist in the database.`
13202
13192
  );
13203
13193
  }
13204
13194
  } else {
@@ -13312,7 +13302,7 @@ yy.CreateVertex.prototype.compile = function (databaseid) {
13312
13302
  if (this.sets && this.sets.length > 0) {
13313
13303
  var s = this.sets
13314
13304
  .map(function (st) {
13315
- return "x['" + st.column.columnid + "']=" + st.expression.toJS('x', '');
13305
+ return `x[${JSON.stringify(st.column.columnid)}]=` + st.expression.toJS('x', '');
13316
13306
  })
13317
13307
  .join(';');
13318
13308
  var setfn = new Function('x,params,alasql', s);
@@ -13385,7 +13375,7 @@ yy.CreateEdge.prototype.compile = function (databaseid) {
13385
13375
  if (this.sets && this.sets.length > 0) {
13386
13376
  var s = this.sets
13387
13377
  .map(function (st) {
13388
- return "x['" + st.column.columnid + "']=" + st.expression.toJS('x', '');
13378
+ return `x[${JSON.stringify(st.column.columnid)}]=` + st.expression.toJS('x', '');
13389
13379
  })
13390
13380
  .join(';');
13391
13381
  var setfn = new Function('x,params,alasql', 'var y;' + s);
@@ -13651,7 +13641,7 @@ yy.CreateGraph.prototype.compile1 = function (databaseid) {
13651
13641
  if (this.sets && this.sets.length > 0) {
13652
13642
  var s = this.sets
13653
13643
  .map(function (st) {
13654
- return "x['" + st.column.columnid + "']=" + st.expression.toJS('x', '');
13644
+ return `x[${JSON.stringify(st.column.columnid)}]=` + st.expression.toJS('x', '');
13655
13645
  })
13656
13646
  .join(';');
13657
13647
  var setfn = new Function('x,params,alasql', 'var y;' + s);
@@ -13726,14 +13716,10 @@ yy.AlterTable.prototype.execute = function (databaseid, params, cb) {
13726
13716
  var res = 1;
13727
13717
  if (db.tables[newtableid]) {
13728
13718
  throw new Error(
13729
- "Can not rename a table '" +
13730
- oldtableid +
13731
- "' to '" +
13732
- newtableid +
13733
- "', because the table with this name already exists"
13719
+ `Can not rename a table "${oldtableid}" to "${newtableid}" because the table with this name already exists`
13734
13720
  );
13735
13721
  } else if (newtableid === oldtableid) {
13736
- throw new Error("Can not rename a table '" + oldtableid + "' to itself");
13722
+ throw new Error(`Can not rename a table "${oldtableid}" to itself`);
13737
13723
  } else {
13738
13724
  db.tables[newtableid] = db.tables[oldtableid];
13739
13725
  delete db.tables[oldtableid];
@@ -13749,11 +13735,7 @@ yy.AlterTable.prototype.execute = function (databaseid, params, cb) {
13749
13735
  var columnid = this.addcolumn.columnid;
13750
13736
  if (table.xcolumns[columnid]) {
13751
13737
  throw new Error(
13752
- 'Cannot add column "' +
13753
- columnid +
13754
- '", because it already exists in the table "' +
13755
- tableid +
13756
- '"'
13738
+ `Cannot add column "${columnid}" because it already exists in table "${tableid}"`
13757
13739
  );
13758
13740
  }
13759
13741
 
@@ -13787,11 +13769,7 @@ yy.AlterTable.prototype.execute = function (databaseid, params, cb) {
13787
13769
 
13788
13770
  if (!table.xcolumns[columnid]) {
13789
13771
  throw new Error(
13790
- 'Cannot modify column "' +
13791
- columnid +
13792
- '", because it was not found in the table "' +
13793
- tableid +
13794
- '"'
13772
+ `Cannot modify column "${columnid}" because it was not found in table "${tableid}"`
13795
13773
  );
13796
13774
  }
13797
13775
 
@@ -13857,11 +13835,7 @@ yy.AlterTable.prototype.execute = function (databaseid, params, cb) {
13857
13835
 
13858
13836
  if (!found) {
13859
13837
  throw new Error(
13860
- 'Cannot drop column "' +
13861
- columnid +
13862
- '", because it was not found in the table "' +
13863
- tableid +
13864
- '"'
13838
+ `Cannot drop column "${columnid}" because it was not found in the table ${tableid}"`
13865
13839
  );
13866
13840
  }
13867
13841
 
@@ -14021,7 +13995,9 @@ yy.WithSelect.prototype.execute = function (databaseid, params, cb) {
14021
13995
  var savedTables = [];
14022
13996
  self.withs.forEach(function (w) {
14023
13997
  savedTables.push(alasql.databases[databaseid].tables[w.name]);
14024
- var tb = (alasql.databases[databaseid].tables[w.name] = new Table({tableid: w.name}));
13998
+ var tb = (alasql.databases[databaseid].tables[w.name] = new Table({
13999
+ tableid: w.name,
14000
+ }));
14025
14001
  tb.data = w.select.execute(databaseid, params);
14026
14002
  });
14027
14003
 
@@ -15270,7 +15246,11 @@ yy.ShowColumns.prototype.execute = function (databaseid, params, cb) {
15270
15246
 
15271
15247
  if (table && table.columns) {
15272
15248
  var res = table.columns.map(function (col) {
15273
- return {columnid: col.columnid, dbtypeid: col.dbtypeid, dbsize: col.dbsize};
15249
+ return {
15250
+ columnid: col.columnid,
15251
+ dbtypeid: col.dbtypeid,
15252
+ dbsize: col.dbsize,
15253
+ };
15274
15254
  });
15275
15255
  if (cb) cb(res);
15276
15256
  return res;
@@ -16520,7 +16500,7 @@ alasql.into.XLSXML = function (filename, opts, data, columns, cb) {
16520
16500
  } else {
16521
16501
  s += 'ss:';
16522
16502
  }
16523
- s += attr + '="' + st[key][attr] + '"';
16503
+ s += attr + '=' + JSON.stringify(st[key][attr]);
16524
16504
  }
16525
16505
  s += '/>';
16526
16506
  }
@@ -16530,8 +16510,8 @@ alasql.into.XLSXML = function (filename, opts, data, columns, cb) {
16530
16510
  if (styles[hh]) {
16531
16511
  } else {
16532
16512
  styles[hh] = {styleid: stylesn};
16533
- s2 += '<Style ss:ID="s' + stylesn + '">';
16534
- s2 += s;
16513
+ s2 += `<Style ss:ID=${JSON.stringify('s' + stylesn)}>`;
16514
+ s2 += s.replace(/<\s*\/\s*Style /gi, '<');
16535
16515
  s2 += '</Style>';
16536
16516
  stylesn++;
16537
16517
  }
@@ -16597,9 +16577,9 @@ alasql.into.XLSXML = function (filename, opts, data, columns, cb) {
16597
16577
 
16598
16578
  // Header
16599
16579
  s3 +=
16600
- '<Worksheet ss:Name="' +
16601
- sheetid +
16602
- '"> \
16580
+ '<Worksheet ss:Name=' +
16581
+ JSON.stringify(sheetid) +
16582
+ '> \
16603
16583
  <Table ss:ExpandedColumnCount="' +
16604
16584
  columns.length +
16605
16585
  '" ss:ExpandedRowCount="' +
@@ -16608,12 +16588,12 @@ alasql.into.XLSXML = function (filename, opts, data, columns, cb) {
16608
16588
  x:FullRows="1" ss:DefaultColumnWidth="65" ss:DefaultRowHeight="15">';
16609
16589
 
16610
16590
  columns.forEach(function (column, columnidx) {
16611
- s3 +=
16612
- '<Column ss:Index="' +
16613
- (columnidx + 1) +
16614
- '" ss:AutoFitWidth="0" ss:Width="' +
16615
- column.width +
16616
- '"/>';
16591
+ s3 += `
16592
+ <Column
16593
+ ss:Index="${columnidx + 1}"
16594
+ ss:AutoFitWidth="0"
16595
+ ss:Width=${JSON.stringify('' + column.width)}
16596
+ />`;
16617
16597
  });
16618
16598
 
16619
16599
  // Headers
@@ -16633,7 +16613,7 @@ alasql.into.XLSXML = function (filename, opts, data, columns, cb) {
16633
16613
  } else {
16634
16614
  extend(st, column.style);
16635
16615
  }
16636
- s3 += 'ss:StyleID="' + hstyle(st) + '"';
16616
+ s3 += 'ss:StyleID=' + JSON.stringify(hstyle(st));
16637
16617
  }
16638
16618
 
16639
16619
  s3 += '><Data ss:Type="String">';
@@ -16677,7 +16657,7 @@ alasql.into.XLSXML = function (filename, opts, data, columns, cb) {
16677
16657
  } else {
16678
16658
  extend(st, srow.style);
16679
16659
  }
16680
- s3 += 'ss:StyleID="' + hstyle(st) + '"';
16660
+ s3 += 'ss:StyleID=' + JSON.stringify(hstyle(st));
16681
16661
  }
16682
16662
  }
16683
16663
 
@@ -16743,7 +16723,6 @@ alasql.into.XLSXML = function (filename, opts, data, columns, cb) {
16743
16723
  typestyle = typestyle || 'mso-number-format:"\\@";'; // Default type style
16744
16724
 
16745
16725
  s3 += '<Cell ';
16746
-
16747
16726
  // Row style fromdefault sheet
16748
16727
  var st = {};
16749
16728
  if (typeof cell.style != 'undefined') {
@@ -16752,12 +16731,12 @@ alasql.into.XLSXML = function (filename, opts, data, columns, cb) {
16752
16731
  } else {
16753
16732
  extend(st, cell.style);
16754
16733
  }
16755
- s3 += 'ss:StyleID="' + hstyle(st) + '"';
16734
+ s3 += 'ss:StyleID=' + JSON.stringify(hstyle(st));
16756
16735
  }
16757
16736
 
16758
16737
  s3 += '>';
16759
16738
 
16760
- s3 += '<Data ss:Type="' + Type + '">';
16739
+ s3 += '<Data ss:Type=' + JSON.stringify(Type) + '>';
16761
16740
 
16762
16741
  // TODO Replace with extend...
16763
16742
  var format = cell.format;
@@ -16929,7 +16908,9 @@ alasql.into.XLSX = function (filename, opts, data, columns, cb) {
16929
16908
 
16930
16909
  if (opt.headers) {
16931
16910
  columns.forEach(function (col, idx) {
16932
- cells[alasql.utils.xlsnc(col0 + idx) + '' + i] = {v: col.columnid.trim()};
16911
+ cells[alasql.utils.xlsnc(col0 + idx) + '' + i] = {
16912
+ v: col.columnid.trim(),
16913
+ };
16933
16914
  });
16934
16915
  i++;
16935
16916
  }
@@ -16981,10 +16962,6 @@ alasql.into.XLSX = function (filename, opts, data, columns, cb) {
16981
16962
  return buf;
16982
16963
  };
16983
16964
 
16984
- /* the saveAs call downloads a file on the local machine */
16985
- // saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), '"'+filename+'"')
16986
- // saveAs(new Blob([s2ab(wbout)],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), filename)
16987
- // saveAs(new Blob([s2ab(wbout)],{type:"application/vnd.ms-excel"}), '"'+filename+'"');
16988
16965
  saveAs(new Blob([s2ab(wbout)], {type: 'application/octet-stream'}), filename);
16989
16966
  }
16990
16967
  }
@@ -17173,7 +17150,7 @@ alasql.from.CSV = function (contents, opts, cb, idx, query) {
17173
17150
  separator: ',',
17174
17151
  quote: '"',
17175
17152
  headers: true,
17176
- raw: false
17153
+ raw: false,
17177
17154
  };
17178
17155
  alasql.utils.extend(opt, opts);
17179
17156
  var res;
@@ -17256,7 +17233,12 @@ alasql.from.CSV = function (contents, opts, cb, idx, query) {
17256
17233
  hs.forEach(function (h, idx) {
17257
17234
  r[h] = a[idx];
17258
17235
  // Please avoid === here
17259
- if (!opt.raw && typeof r[h] !== 'undefined' && r[h].length !== 0 && r[h].trim() == +r[h]) {
17236
+ if (
17237
+ !opt.raw &&
17238
+ typeof r[h] !== 'undefined' &&
17239
+ r[h].length !== 0 &&
17240
+ r[h].trim() == +r[h]
17241
+ ) {
17260
17242
  // jshint ignore:line
17261
17243
  r[h] = +r[h];
17262
17244
  }
@@ -17267,7 +17249,12 @@ alasql.from.CSV = function (contents, opts, cb, idx, query) {
17267
17249
  var r = {};
17268
17250
  hs.forEach(function (h, idx) {
17269
17251
  r[h] = a[idx];
17270
- if (!opt.raw && typeof r[h] !== 'undefined' && r[h].length !== 0 && r[h].trim() == +r[h]) {
17252
+ if (
17253
+ !opt.raw &&
17254
+ typeof r[h] !== 'undefined' &&
17255
+ r[h].length !== 0 &&
17256
+ r[h].trim() == +r[h]
17257
+ ) {
17271
17258
  // jshint ignore:line
17272
17259
  r[h] = +r[h];
17273
17260
  }
@@ -17280,7 +17267,12 @@ alasql.from.CSV = function (contents, opts, cb, idx, query) {
17280
17267
  // different bug here, if headers are not defined, the numerical values will not be parsed
17281
17268
  a.forEach(function (v, idx) {
17282
17269
  r[idx] = a[idx];
17283
- if (!opt.raw && typeof r[idx] !== 'undefined' && r[idx].length !== 0 && r[idx].trim() == +r[idx]) {
17270
+ if (
17271
+ !opt.raw &&
17272
+ typeof r[idx] !== 'undefined' &&
17273
+ r[idx].length !== 0 &&
17274
+ r[idx].trim() == +r[idx]
17275
+ ) {
17284
17276
  // jshint ignore:line
17285
17277
  r[idx] = +r[idx];
17286
17278
  }
@@ -17351,9 +17343,17 @@ function XLSXLSX(X, filename, opts, cb, idx, query) {
17351
17343
  // function processData(data) {
17352
17344
  if (data instanceof ArrayBuffer) {
17353
17345
  var arr = fixdata(data);
17354
- var workbook = X.read(btoa(arr), {type: 'base64', ...alasql.options.excel, ...opts});
17346
+ var workbook = X.read(btoa(arr), {
17347
+ type: 'base64',
17348
+ ...alasql.options.excel,
17349
+ ...opts,
17350
+ });
17355
17351
  } else {
17356
- var workbook = X.read(data, {type: 'binary', ...alasql.options.excel, ...opts});
17352
+ var workbook = X.read(data, {
17353
+ type: 'binary',
17354
+ ...alasql.options.excel,
17355
+ ...opts,
17356
+ });
17357
17357
  }
17358
17358
 
17359
17359
  var sheetid;
@@ -17871,7 +17871,7 @@ async function _databaseExists(name) {
17871
17871
 
17872
17872
  if (indexedDB.databases) {
17873
17873
  const dbs = await indexedDB.databases();
17874
- const db = dbs.find((db) => db.name === name);
17874
+ const db = dbs.find(db => db.name === name);
17875
17875
  // @ts-ignore
17876
17876
  return db || 0;
17877
17877
  }
@@ -17885,7 +17885,7 @@ async function _databaseExists(name) {
17885
17885
  resolve({name, version: req.result.version});
17886
17886
  };
17887
17887
 
17888
- req.onupgradeneeded = (evt) => {
17888
+ req.onupgradeneeded = evt => {
17889
17889
  evt.target.transaction.abort();
17890
17890
  resolve(0);
17891
17891
  };
@@ -17910,7 +17910,7 @@ IDB.showDatabases = function (like, cb) {
17910
17910
  return;
17911
17911
  }
17912
17912
 
17913
- indexedDB.databases().then((dblist) => {
17913
+ indexedDB.databases().then(dblist => {
17914
17914
  const res = [];
17915
17915
  const relike = like && new RegExp(like.value.replace(/\%/g, '.*'), 'g');
17916
17916
 
@@ -17925,7 +17925,7 @@ IDB.showDatabases = function (like, cb) {
17925
17925
  };
17926
17926
 
17927
17927
  IDB.createDatabase = async function (ixdbid, args, ifnotexists, dbid, cb) {
17928
- const found = await _databaseExists(ixdbid).catch((err) => {
17928
+ const found = await _databaseExists(ixdbid).catch(err => {
17929
17929
  if (cb) cb(null, err);
17930
17930
  throw err;
17931
17931
  });
@@ -17949,7 +17949,7 @@ IDB.createDatabase = async function (ixdbid, args, ifnotexists, dbid, cb) {
17949
17949
  };
17950
17950
 
17951
17951
  IDB.dropDatabase = async function (ixdbid, ifexists, cb) {
17952
- const found = await _databaseExists(ixdbid).catch((err) => {
17952
+ const found = await _databaseExists(ixdbid).catch(err => {
17953
17953
  if (cb) cb(null, err);
17954
17954
  throw err;
17955
17955
  });
@@ -17973,7 +17973,7 @@ IDB.dropDatabase = async function (ixdbid, ifexists, cb) {
17973
17973
  };
17974
17974
 
17975
17975
  IDB.attachDatabase = async function (ixdbid, dbid, args, params, cb) {
17976
- const found = await _databaseExists(ixdbid).catch((err) => {
17976
+ const found = await _databaseExists(ixdbid).catch(err => {
17977
17977
  if (cb) cb(null, err);
17978
17978
  throw err;
17979
17979
  });
@@ -18008,7 +18008,7 @@ IDB.attachDatabase = async function (ixdbid, dbid, args, params, cb) {
18008
18008
 
18009
18009
  IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
18010
18010
  const ixdbid = alasql.databases[databaseid].ixdbid;
18011
- const found = await _databaseExists(ixdbid).catch((err) => {
18011
+ const found = await _databaseExists(ixdbid).catch(err => {
18012
18012
  if (cb) cb(null, err);
18013
18013
  throw err;
18014
18014
  });
@@ -18029,7 +18029,7 @@ IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
18029
18029
  request.result.close();
18030
18030
  if (cb) cb(1);
18031
18031
  };
18032
- request.onerror = (evt) => {
18032
+ request.onerror = evt => {
18033
18033
  cb(null, evt);
18034
18034
  };
18035
18035
  request.onblocked = function (event) {
@@ -18042,7 +18042,7 @@ IDB.createTable = async function (databaseid, tableid, ifnotexists, cb) {
18042
18042
 
18043
18043
  IDB.dropTable = async function (databaseid, tableid, ifexists, cb) {
18044
18044
  const ixdbid = alasql.databases[databaseid].ixdbid;
18045
- const found = await _databaseExists(ixdbid).catch((err) => {
18045
+ const found = await _databaseExists(ixdbid).catch(err => {
18046
18046
  if (cb) cb(null, err);
18047
18047
  throw err;
18048
18048
  });
@@ -18091,7 +18091,7 @@ IDB.intoTable = function (databaseid, tableid, value, columns, cb) {
18091
18091
  var db = alasql.databases[databaseid];
18092
18092
  var table = db.tables[tableid];
18093
18093
 
18094
- request.onupgradeneeded = (evt) => {
18094
+ request.onupgradeneeded = evt => {
18095
18095
  evt.target.transaction.abort();
18096
18096
  const err = new Error(
18097
18097
  `Cannot insert into table "${tableid}" because database "${databaseid}" does not exist`
@@ -18127,7 +18127,7 @@ IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
18127
18127
  const ixdbid = alasql.databases[databaseid].ixdbid;
18128
18128
  const request = indexedDB.open(ixdbid);
18129
18129
 
18130
- request.onupgradeneeded = (evt) => {
18130
+ request.onupgradeneeded = evt => {
18131
18131
  evt.target.transaction.abort();
18132
18132
  const err = new Error(
18133
18133
  `Cannot select from table "${tableid}" because database "${databaseid}" does not exist`
@@ -18143,7 +18143,9 @@ IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
18143
18143
  cur.onsuccess = () => {
18144
18144
  const cursor = cur.result;
18145
18145
  if (cursor) {
18146
- res.push(cursor.value);
18146
+ // if keyPath(columns) is not present then we take the key and value as object.
18147
+ const cursorValue = typeof cursor === Object ? cursor.value : {[cursor.key]: cursor.value};
18148
+ res.push(cursorValue);
18147
18149
  cursor.continue();
18148
18150
  } else {
18149
18151
  ixdb.close();
@@ -19181,7 +19183,9 @@ var saveAs =
19181
19183
  blob.type
19182
19184
  )
19183
19185
  ) {
19184
- return new Blob([String.fromCharCode(0xfeff), blob], {type: blob.type});
19186
+ return new Blob([String.fromCharCode(0xfeff), blob], {
19187
+ type: blob.type,
19188
+ });
19185
19189
  }
19186
19190
  return blob;
19187
19191
  },