alasql 2.2.2 → 2.2.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/README.md +5 -5
- package/dist/alasql-echo.js +1 -1
- package/dist/alasql-prolog.js +2 -2
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql-worker.min.js +1 -1
- package/dist/alasql.fs.js +1290 -1436
- package/dist/alasql.js +1566 -1704
- package/dist/alasql.min.js +7 -7
- package/package.json +5 -6
package/dist/alasql.fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.2.
|
|
1
|
+
//! AlaSQL v2.2.3-develop-21117291 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.2.
|
|
4
|
+
@version 2.2.3-develop-21117291
|
|
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.
|
|
145
|
+
alasql.version = '2.2.3-develop-21117291';
|
|
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
|
-
//
|
|
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
|
-
|
|
5026
|
-
|
|
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
|
-
|
|
5039
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
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
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
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
|
-
|
|
5081
|
+
queryArrayOfArrays (sql, params, cb) {
|
|
5082
|
+
return arrayOfArrays(this.exec(sql, params, cb));
|
|
5083
|
+
}
|
|
5079
5084
|
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
5221
|
-
|
|
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
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5233
|
+
var yy = {
|
|
5234
|
+
// Utility
|
|
5235
|
+
/** @deprecated use `Object.assign` instead */
|
|
5236
|
+
extend: Object.assign,
|
|
5227
5237
|
|
|
5228
|
-
|
|
5229
|
-
|
|
5238
|
+
// Option for case sensitive
|
|
5239
|
+
casesensitive: alasql.options.casesensitive,
|
|
5240
|
+
Base,
|
|
5241
|
+
};
|
|
5230
5242
|
|
|
5231
|
-
|
|
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
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
}
|
|
5253
|
+
yy.Statements = class Statements {
|
|
5254
|
+
constructor(params) {
|
|
5255
|
+
Object.assign(this, params);
|
|
5256
|
+
}
|
|
5246
5257
|
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
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
|
-
|
|
5257
|
-
|
|
5258
|
-
return
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
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
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5285
|
+
/**
|
|
5286
|
+
Search class
|
|
5287
|
+
@example
|
|
5288
|
+
SEARCH SUM(/a) FROM ? -- search over parameter object
|
|
5289
|
+
*/
|
|
5290
5290
|
|
|
5291
|
-
|
|
5292
|
-
|
|
5291
|
+
yy.Search = class Search {
|
|
5292
|
+
constructor(params) {
|
|
5293
|
+
Object.assign(this, params);
|
|
5294
|
+
}
|
|
5293
5295
|
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
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
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5303
|
+
toJS(context) {
|
|
5304
|
+
const s = `this.queriesfn[${this.queriesidx - 1}](this.params,null,${context})`;
|
|
5305
|
+
return s;
|
|
5306
|
+
}
|
|
5302
5307
|
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
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);
|
|
5368
|
+
}
|
|
5320
5369
|
} else {
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5370
|
+
if (typeof visited[node.$id] !== 'undefined') {
|
|
5371
|
+
continue;
|
|
5372
|
+
} else {
|
|
5373
|
+
|
|
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
|
+
});
|
|
5384
|
+
});
|
|
5385
|
+
}
|
|
5326
5386
|
}
|
|
5327
|
-
return rv;
|
|
5328
|
-
// return processSelector(selectors,sidx+1,stack);
|
|
5329
5387
|
}
|
|
5388
|
+
}
|
|
5389
|
+
// Else return fail
|
|
5390
|
+
return [];
|
|
5391
|
+
}
|
|
5392
|
+
if (sel.selid === 'NOT') {
|
|
5393
|
+
var nest = processSelector(sel.args, 0, value);
|
|
5394
|
+
|
|
5395
|
+
if (nest.length > 0) {
|
|
5396
|
+
return [];
|
|
5397
|
+
} else {
|
|
5398
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5399
|
+
return [value];
|
|
5400
|
+
} else {
|
|
5401
|
+
return processSelector(selectors, sidx + 1, value);
|
|
5402
|
+
}
|
|
5403
|
+
}
|
|
5404
|
+
} else if (sel.selid === 'DISTINCT') {
|
|
5405
|
+
var nest;
|
|
5406
|
+
if (typeof sel.args === 'undefined' || sel.args.length === 0) {
|
|
5407
|
+
nest = distinctArray(value);
|
|
5408
|
+
} else {
|
|
5409
|
+
nest = processSelector(sel.args, 0, value);
|
|
5410
|
+
}
|
|
5411
|
+
if (nest.length === 0) {
|
|
5412
|
+
return [];
|
|
5413
|
+
} else {
|
|
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
|
+
}
|
|
5420
|
+
}
|
|
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 [];
|
|
5330
5428
|
} else {
|
|
5331
|
-
if (
|
|
5332
|
-
|
|
5429
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5430
|
+
return [value];
|
|
5333
5431
|
} else {
|
|
5432
|
+
return processSelector(selectors, sidx + 1, value);
|
|
5433
|
+
}
|
|
5434
|
+
}
|
|
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 [];
|
|
5442
|
+
} else {
|
|
5443
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5444
|
+
return [value];
|
|
5445
|
+
} else {
|
|
5446
|
+
return processSelector(selectors, sidx + 1, value);
|
|
5447
|
+
}
|
|
5448
|
+
}
|
|
5449
|
+
} else if (sel.selid === 'ALL') {
|
|
5450
|
+
var nest = processSelector(sel.args[0], 0, value);
|
|
5451
|
+
if (nest.length === 0) {
|
|
5452
|
+
return [];
|
|
5453
|
+
} else {
|
|
5454
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5455
|
+
return nest;
|
|
5456
|
+
} else {
|
|
5457
|
+
return processSelector(selectors, sidx + 1, nest);
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
} else if (sel.selid === 'ANY') {
|
|
5461
|
+
var nest = processSelector(sel.args[0], 0, value);
|
|
5462
|
+
if (nest.length === 0) {
|
|
5463
|
+
return [];
|
|
5464
|
+
} else {
|
|
5465
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5466
|
+
return [nest[0]];
|
|
5467
|
+
} else {
|
|
5468
|
+
return processSelector(selectors, sidx + 1, [nest[0]]);
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
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 [];
|
|
5478
|
+
} else {
|
|
5479
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5480
|
+
return nest;
|
|
5481
|
+
} else {
|
|
5482
|
+
return processSelector(selectors, sidx + 1, nest);
|
|
5483
|
+
}
|
|
5484
|
+
}
|
|
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 [];
|
|
5493
|
+
} else {
|
|
5494
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5495
|
+
return nest;
|
|
5496
|
+
} else {
|
|
5497
|
+
return processSelector(selectors, sidx + 1, nest);
|
|
5498
|
+
}
|
|
5499
|
+
}
|
|
5500
|
+
} else if (sel.selid === 'IF') {
|
|
5501
|
+
var nest = processSelector(sel.args, 0, value);
|
|
5334
5502
|
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5503
|
+
if (nest.length === 0) {
|
|
5504
|
+
return [];
|
|
5505
|
+
} else {
|
|
5506
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5507
|
+
return [value];
|
|
5508
|
+
} else {
|
|
5509
|
+
return processSelector(selectors, sidx + 1, value);
|
|
5510
|
+
}
|
|
5511
|
+
}
|
|
5512
|
+
} else if (sel.selid === 'REPEAT') {
|
|
5513
|
+
|
|
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;
|
|
5526
|
+
|
|
5527
|
+
var retval = [];
|
|
5528
|
+
|
|
5529
|
+
if (lmin === 0) {
|
|
5530
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5531
|
+
retval = [value];
|
|
5532
|
+
} else {
|
|
5533
|
+
if (lvar) {
|
|
5534
|
+
alasql.vars[lvar] = 0;
|
|
5535
|
+
}
|
|
5536
|
+
retval = retval.concat(processSelector(selectors, sidx + 1, value));
|
|
5537
|
+
}
|
|
5538
|
+
}
|
|
5539
|
+
|
|
5540
|
+
// var nests = processSelector(sel.sels,0,value).slice();
|
|
5541
|
+
if (lmax > 0) {
|
|
5542
|
+
var nests = [{value: value, lvl: 1}];
|
|
5543
|
+
|
|
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});
|
|
5345
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
|
+
}
|
|
5568
|
+
}
|
|
5569
|
+
}
|
|
5570
|
+
// Security brake
|
|
5571
|
+
i++;
|
|
5572
|
+
if (i > INFINITE_LOOP_BREAK) {
|
|
5573
|
+
throw new Error('Infinite loop brake. Number of iterations = ' + i);
|
|
5346
5574
|
}
|
|
5347
5575
|
}
|
|
5348
5576
|
}
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
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') {
|
|
5590
|
+
|
|
5591
|
+
var oldv = alasql.vars[sel.args[0]];
|
|
5592
|
+
var newv = [];
|
|
5593
|
+
if (oldv !== undefined) {
|
|
5594
|
+
|
|
5595
|
+
newv = oldv.slice(0);
|
|
5596
|
+
|
|
5597
|
+
} else {
|
|
5598
|
+
newv = [];
|
|
5599
|
+
}
|
|
5600
|
+
newv.push(value);
|
|
5355
5601
|
|
|
5356
|
-
if (nest.length > 0) {
|
|
5357
|
-
return [];
|
|
5358
|
-
} else {
|
|
5359
5602
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5360
5603
|
return [value];
|
|
5361
5604
|
} else {
|
|
5362
|
-
|
|
5605
|
+
alasql.vars[sel.args[0]] = newv;
|
|
5606
|
+
var r1 = processSelector(selectors, sidx + 1, value);
|
|
5607
|
+
|
|
5608
|
+
alasql.vars[sel.args[0]] = oldv;
|
|
5609
|
+
return r1;
|
|
5610
|
+
}
|
|
5611
|
+
|
|
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 [];
|
|
5363
5618
|
}
|
|
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
5619
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5377
|
-
return
|
|
5620
|
+
return [val];
|
|
5378
5621
|
} else {
|
|
5379
|
-
return processSelector(selectors, sidx + 1,
|
|
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) {
|
|
5628
|
+
return sum + current;
|
|
5629
|
+
}, 0);
|
|
5630
|
+
} else {
|
|
5631
|
+
return [];
|
|
5380
5632
|
}
|
|
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
5633
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5391
|
-
return [
|
|
5634
|
+
return [val];
|
|
5392
5635
|
} else {
|
|
5393
|
-
return processSelector(selectors, sidx + 1,
|
|
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 [];
|
|
5394
5647
|
}
|
|
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
5648
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5405
|
-
return [
|
|
5649
|
+
return [val];
|
|
5406
5650
|
} else {
|
|
5407
|
-
return processSelector(selectors, sidx + 1,
|
|
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 [];
|
|
5408
5659
|
}
|
|
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
5660
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5416
|
-
return
|
|
5661
|
+
return [val];
|
|
5417
5662
|
} else {
|
|
5418
|
-
return processSelector(selectors, sidx + 1,
|
|
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 [];
|
|
5419
5671
|
}
|
|
5420
|
-
}
|
|
5421
|
-
} else if (sel.selid === 'ANY') {
|
|
5422
|
-
var nest = processSelector(sel.args[0], 0, value);
|
|
5423
5672
|
|
|
5424
|
-
if (nest.length === 0) {
|
|
5425
|
-
return [];
|
|
5426
|
-
} else {
|
|
5427
5673
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5428
|
-
return [
|
|
5674
|
+
return [val];
|
|
5429
5675
|
} else {
|
|
5430
|
-
return processSelector(selectors, sidx + 1,
|
|
5676
|
+
return processSelector(selectors, sidx + 1, val);
|
|
5431
5677
|
}
|
|
5432
|
-
}
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
} else {
|
|
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
|
+
}
|
|
5685
|
+
|
|
5441
5686
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5442
|
-
return
|
|
5687
|
+
return [val];
|
|
5443
5688
|
} else {
|
|
5444
|
-
return processSelector(selectors, sidx + 1,
|
|
5689
|
+
return processSelector(selectors, sidx + 1, val);
|
|
5445
5690
|
}
|
|
5446
|
-
}
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
return [];
|
|
5455
|
-
} else {
|
|
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);
|
|
5456
5699
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5457
|
-
return
|
|
5700
|
+
return [val];
|
|
5458
5701
|
} else {
|
|
5459
|
-
return processSelector(selectors, sidx + 1,
|
|
5702
|
+
return processSelector(selectors, sidx + 1, val);
|
|
5460
5703
|
}
|
|
5461
|
-
}
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
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);
|
|
5468
5712
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5469
|
-
return [
|
|
5713
|
+
return [val];
|
|
5470
5714
|
} else {
|
|
5471
|
-
return processSelector(selectors, sidx + 1,
|
|
5715
|
+
return processSelector(selectors, sidx + 1, val);
|
|
5472
5716
|
}
|
|
5473
|
-
}
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
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;
|
|
5488
|
-
|
|
5489
|
-
var retval = [];
|
|
5490
|
-
|
|
5491
|
-
if (lmin === 0) {
|
|
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();
|
|
5492
5721
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5493
|
-
retval =
|
|
5722
|
+
retval = retval.concat(nests);
|
|
5494
5723
|
} else {
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
}
|
|
5498
|
-
retval = retval.concat(processSelector(selectors, sidx + 1, value));
|
|
5724
|
+
nests.forEach(function (n) {
|
|
5725
|
+
retval = retval.concat(processSelector(selectors, sidx + 1, n));
|
|
5726
|
+
});
|
|
5499
5727
|
}
|
|
5500
|
-
}
|
|
5501
|
-
|
|
5502
|
-
// var nests = processSelector(sel.sels,0,value).slice();
|
|
5503
|
-
if (lmax > 0) {
|
|
5504
|
-
var nests = [{value: value, lvl: 1}];
|
|
5505
5728
|
|
|
5506
5729
|
var i = 0;
|
|
5507
5730
|
while (nests.length > 0) {
|
|
5508
|
-
|
|
5731
|
+
// nest = nests[0];
|
|
5732
|
+
// nests.shift();
|
|
5733
|
+
var nest = nests.shift();
|
|
5509
5734
|
|
|
5510
|
-
|
|
5511
|
-
if (nest.lvl <= lmax) {
|
|
5512
|
-
if (lvar) {
|
|
5513
|
-
alasql.vars[lvar] = nest.lvl;
|
|
5514
|
-
}
|
|
5735
|
+
nest = processSelector(sel.args, 0, nest);
|
|
5515
5736
|
|
|
5516
|
-
|
|
5737
|
+
nests = nests.concat(nest);
|
|
5517
5738
|
|
|
5518
|
-
|
|
5519
|
-
|
|
5739
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5740
|
+
retval = retval.concat(nest);
|
|
5741
|
+
//return retval;
|
|
5742
|
+
} else {
|
|
5743
|
+
nest.forEach(function (n) {
|
|
5744
|
+
|
|
5745
|
+
var rn = processSelector(selectors, sidx + 1, n);
|
|
5746
|
+
|
|
5747
|
+
retval = retval.concat(rn);
|
|
5520
5748
|
});
|
|
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
|
-
});
|
|
5529
|
-
}
|
|
5530
|
-
}
|
|
5531
5749
|
}
|
|
5750
|
+
|
|
5532
5751
|
// Security brake
|
|
5533
5752
|
i++;
|
|
5534
5753
|
if (i > INFINITE_LOOP_BREAK) {
|
|
5535
5754
|
throw new Error('Infinite loop brake. Number of iterations = ' + i);
|
|
5536
5755
|
}
|
|
5537
5756
|
}
|
|
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') {
|
|
5552
|
-
|
|
5553
|
-
var oldv = alasql.vars[sel.args[0]];
|
|
5554
|
-
var newv = [];
|
|
5555
|
-
if (oldv !== undefined) {
|
|
5556
|
-
|
|
5557
|
-
newv = oldv.slice(0);
|
|
5558
|
-
|
|
5559
|
-
} else {
|
|
5560
|
-
newv = [];
|
|
5561
|
-
}
|
|
5562
|
-
newv.push(value);
|
|
5563
|
-
|
|
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);
|
|
5569
|
-
|
|
5570
|
-
alasql.vars[sel.args[0]] = oldv;
|
|
5571
|
-
return r1;
|
|
5572
|
-
}
|
|
5573
|
-
|
|
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) {
|
|
5605
|
-
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
|
-
}
|
|
5634
|
-
|
|
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
|
-
}
|
|
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 === '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
|
-
}
|
|
5690
|
-
|
|
5691
|
-
var i = 0;
|
|
5692
|
-
while (nests.length > 0) {
|
|
5693
|
-
// nest = nests[0];
|
|
5694
|
-
// nests.shift();
|
|
5695
|
-
var nest = nests.shift();
|
|
5696
|
-
|
|
5697
|
-
nest = processSelector(sel.args, 0, nest);
|
|
5698
|
-
|
|
5699
|
-
nests = nests.concat(nest);
|
|
5757
|
+
return retval;
|
|
5700
5758
|
|
|
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();
|
|
5701
5763
|
if (sidx + 1 + 1 > selectors.length) {
|
|
5702
|
-
retval = retval.concat(
|
|
5703
|
-
//return
|
|
5764
|
+
retval = retval.concat(nests);
|
|
5765
|
+
//return nests;
|
|
5704
5766
|
} else {
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
var rn = processSelector(selectors, sidx + 1, n);
|
|
5708
|
-
|
|
5709
|
-
retval = retval.concat(rn);
|
|
5767
|
+
nests.forEach(function (n) {
|
|
5768
|
+
retval = retval.concat(processSelector(selectors, sidx + 1, n));
|
|
5710
5769
|
});
|
|
5711
5770
|
}
|
|
5771
|
+
var i = 0;
|
|
5772
|
+
while (nests.length > 0) {
|
|
5773
|
+
var nest = nests[0];
|
|
5774
|
+
nests.shift();
|
|
5712
5775
|
|
|
5713
|
-
|
|
5714
|
-
i++;
|
|
5715
|
-
if (i > INFINITE_LOOP_BREAK) {
|
|
5716
|
-
throw new Error('Infinite loop brake. Number of iterations = ' + i);
|
|
5717
|
-
}
|
|
5718
|
-
}
|
|
5719
|
-
return retval;
|
|
5776
|
+
nest = processSelector(sel.args, 0, nest);
|
|
5720
5777
|
|
|
5721
|
-
|
|
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();
|
|
5778
|
+
nests = nests.concat(nest);
|
|
5737
5779
|
|
|
5738
|
-
|
|
5780
|
+
if (sidx + 1 + 1 <= selectors.length) {
|
|
5781
|
+
nest.forEach(function (n) {
|
|
5782
|
+
retval = retval.concat(processSelector(selectors, sidx + 1, n));
|
|
5783
|
+
});
|
|
5784
|
+
}
|
|
5739
5785
|
|
|
5740
|
-
|
|
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
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
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
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
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
|
-
|
|
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('
|
|
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
5828
|
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
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
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5833
|
+
var res = [];
|
|
5834
|
+
if (r.status === 1) {
|
|
5835
|
+
var arr = r.values;
|
|
5798
5836
|
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5837
|
+
if (sidx + 1 + 1 > selectors.length) {
|
|
5838
|
+
// if(sidx+1+1 > selectors.length) {
|
|
5839
|
+
res = arr;
|
|
5802
5840
|
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
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
|
-
|
|
5850
|
+
if (selectors !== undefined && selectors.length > 0) {
|
|
5813
5851
|
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
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
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
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
|
-
|
|
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();
|
|
5846
|
-
|
|
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
5876
|
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
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();
|
|
5875
5884
|
|
|
5876
|
-
|
|
5877
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
5919
5888
|
|
|
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
|
-
};
|
|
5889
|
+
fromdata = alasql.from[this.from.funcid.toUpperCase()].apply(this, args);
|
|
5930
5890
|
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
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();
|
|
5903
|
+
}
|
|
5944
5904
|
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
}
|
|
5905
|
+
// if(typeof fromdata == 'object' && Array.isArray(fromdata)) {
|
|
5906
|
+
// selectors.unshift({srchid:'CHILD'});
|
|
5907
|
+
// }
|
|
5908
|
+
}
|
|
5949
5909
|
|
|
5950
|
-
|
|
5951
|
-
var
|
|
5952
|
-
var
|
|
5910
|
+
// If source data is array than first step is to run over array
|
|
5911
|
+
// var selidx = 0;
|
|
5912
|
+
// var selvalue = fromdata;
|
|
5953
5913
|
|
|
5954
|
-
|
|
5914
|
+
if (selectors !== undefined && selectors.length > 0) {
|
|
5915
|
+
// Init variables for TO() selectors
|
|
5955
5916
|
|
|
5956
|
-
|
|
5957
|
-
|
|
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
|
+
});
|
|
5925
|
+
}
|
|
5958
5926
|
|
|
5959
|
-
res =
|
|
5927
|
+
res = processSelector(selectors, 0, fromdata);
|
|
5928
|
+
} else {
|
|
5929
|
+
res = fromdata;
|
|
5930
|
+
}
|
|
5960
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);
|
|
5947
|
+
} else {
|
|
5948
|
+
if (stope.value && res.length > 0) {
|
|
5949
|
+
res = res[0];
|
|
5950
|
+
}
|
|
5961
5951
|
if (cb) {
|
|
5962
5952
|
res = cb(res);
|
|
5963
5953
|
}
|
|
5964
|
-
}
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
return res;
|
|
5968
|
-
};
|
|
5969
|
-
statement.query = {};
|
|
5970
|
-
return statement;
|
|
5954
|
+
}
|
|
5955
|
+
return res;
|
|
5956
|
+
}
|
|
5971
5957
|
};
|
|
5972
5958
|
|
|
5973
5959
|
// List of search functions
|
|
5974
|
-
alasql.srch = {
|
|
5960
|
+
alasql.srch = {
|
|
5961
|
+
PROP(val, args, stope) {
|
|
5975
5962
|
|
|
5976
|
-
|
|
5963
|
+
if (stope.mode === 'XML') {
|
|
5964
|
+
const values = val.children.filter((v) => v.name.toUpperCase() === args[0].toUpperCase());
|
|
5977
5965
|
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
arr.push(v);
|
|
5983
|
-
}
|
|
5984
|
-
});
|
|
5985
|
-
if (arr.length > 0) {
|
|
5986
|
-
return {status: 1, values: arr};
|
|
5966
|
+
return {
|
|
5967
|
+
status: values.length ? 1 : -1,
|
|
5968
|
+
values,
|
|
5969
|
+
};
|
|
5987
5970
|
} else {
|
|
5988
|
-
|
|
5971
|
+
if (
|
|
5972
|
+
typeof val !== 'object' ||
|
|
5973
|
+
val === null ||
|
|
5974
|
+
typeof args !== 'object' ||
|
|
5975
|
+
typeof val[args[0]] === 'undefined'
|
|
5976
|
+
) {
|
|
5977
|
+
return {status: -1, values: []};
|
|
5978
|
+
} else {
|
|
5979
|
+
return {status: 1, values: [val[args[0]]]};
|
|
5980
|
+
}
|
|
5989
5981
|
}
|
|
5990
|
-
}
|
|
5982
|
+
},
|
|
5983
|
+
|
|
5984
|
+
APROP(val, args) {
|
|
5991
5985
|
if (
|
|
5992
5986
|
typeof val !== 'object' ||
|
|
5993
5987
|
val === null ||
|
|
5994
5988
|
typeof args !== 'object' ||
|
|
5995
5989
|
typeof val[args[0]] === 'undefined'
|
|
5996
5990
|
) {
|
|
5997
|
-
return {status:
|
|
5991
|
+
return {status: 1, values: [undefined]};
|
|
5998
5992
|
} else {
|
|
5999
5993
|
return {status: 1, values: [val[args[0]]]};
|
|
6000
5994
|
}
|
|
6001
|
-
}
|
|
6002
|
-
};
|
|
5995
|
+
},
|
|
6003
5996
|
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
val ===
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
}
|
|
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
|
-
};
|
|
6027
|
-
|
|
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
|
-
};
|
|
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
|
+
},
|
|
6049
6006
|
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
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]};
|
|
6054
6024
|
} else {
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
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]};
|
|
6061
6033
|
} else {
|
|
6062
|
-
|
|
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
|
+
}
|
|
6063
6043
|
}
|
|
6044
|
+
} else {
|
|
6045
|
+
throw new Error('ATTR is not using in usual mode');
|
|
6064
6046
|
}
|
|
6065
|
-
}
|
|
6066
|
-
throw new Error('ATTR is not using in usual mode');
|
|
6067
|
-
}
|
|
6068
|
-
};
|
|
6047
|
+
},
|
|
6069
6048
|
|
|
6070
|
-
|
|
6071
|
-
|
|
6049
|
+
CONTENT(val, args, stope) {
|
|
6050
|
+
if (stope.mode !== 'XML') {
|
|
6051
|
+
throw new Error('ATTR is not using in usual mode');
|
|
6052
|
+
}
|
|
6072
6053
|
return {status: 1, values: [val.content]};
|
|
6073
|
-
}
|
|
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
|
-
};
|
|
6054
|
+
},
|
|
6086
6055
|
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
return {status: -1, values: []};
|
|
6092
|
-
};
|
|
6093
|
-
|
|
6094
|
-
alasql.srch.CHILD = function (val, args, stope) {
|
|
6095
|
-
|
|
6096
|
-
if (typeof val === 'object') {
|
|
6097
|
-
if (Array.isArray(val)) {
|
|
6098
|
-
return {status: 1, values: val};
|
|
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]};
|
|
6099
6060
|
} else {
|
|
6100
|
-
|
|
6101
|
-
return {
|
|
6102
|
-
status: 1,
|
|
6103
|
-
values: Object.keys(val.children).map(function (key) {
|
|
6104
|
-
return val.children[key];
|
|
6105
|
-
}),
|
|
6106
|
-
};
|
|
6107
|
-
} else {
|
|
6108
|
-
return {
|
|
6109
|
-
status: 1,
|
|
6110
|
-
values: Object.keys(val).map(function (key) {
|
|
6111
|
-
return val[key];
|
|
6112
|
-
}),
|
|
6113
|
-
};
|
|
6114
|
-
}
|
|
6061
|
+
return {status: -1, values: []};
|
|
6115
6062
|
}
|
|
6116
|
-
}
|
|
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
|
-
};
|
|
6063
|
+
},
|
|
6131
6064
|
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
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
|
-
};
|
|
6142
|
-
|
|
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
|
-
};
|
|
6150
|
-
|
|
6151
|
-
alasql.srch.CLASS = function (val, args) {
|
|
6152
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
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
|
-
//
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
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
|
-
//
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
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
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
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
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
}
|
|
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
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
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
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
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
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
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
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
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
|
-
|
|
6295
|
-
|
|
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
|
-
|
|
6300
|
-
|
|
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
|
-
|
|
6303
|
-
|
|
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
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
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
|
-
|
|
6296
|
+
setfn(val, params, alasql);
|
|
6317
6297
|
|
|
6318
|
-
|
|
6319
|
-
}
|
|
6298
|
+
return {status: 1, values: [val]};
|
|
6299
|
+
},
|
|
6320
6300
|
|
|
6321
|
-
|
|
6322
|
-
|
|
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
|
-
|
|
6325
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6337
|
-
|
|
6338
|
-
val.source = val.$in[0];
|
|
6339
|
-
val.target = val.$out[0];
|
|
6340
|
-
}
|
|
6317
|
+
return {status: 1, values: [val]};
|
|
6318
|
+
},
|
|
6341
6319
|
|
|
6342
|
-
|
|
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
|
|
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
|
|
7778
|
+
return Object.assign(this, params);
|
|
7812
7779
|
};
|
|
7813
7780
|
yy.ExistsValue.prototype.toString = function () {
|
|
7814
7781
|
return 'EXISTS(' + this.value.toString() + ')';
|
|
@@ -10128,7 +10095,7 @@ yy.Select.prototype.compileDefCols = function (query, databaseid) {
|
|
|
10128
10095
|
// SELECT UNION statement
|
|
10129
10096
|
|
|
10130
10097
|
yy.Union = function (params) {
|
|
10131
|
-
return
|
|
10098
|
+
return Object.assign(this, params);
|
|
10132
10099
|
};
|
|
10133
10100
|
yy.Union.prototype.toString = function () {
|
|
10134
10101
|
return 'UNION';
|
|
@@ -10147,7 +10114,7 @@ yy.Union.prototype.compile = function (tableid) {
|
|
|
10147
10114
|
*/
|
|
10148
10115
|
|
|
10149
10116
|
yy.Apply = function (params) {
|
|
10150
|
-
return
|
|
10117
|
+
return Object.assign(this, params);
|
|
10151
10118
|
};
|
|
10152
10119
|
|
|
10153
10120
|
yy.Apply.prototype.toString = function () {
|
|
@@ -10167,7 +10134,7 @@ yy.Apply.prototype.toString = function () {
|
|
|
10167
10134
|
*/
|
|
10168
10135
|
|
|
10169
10136
|
yy.Over = function (params) {
|
|
10170
|
-
return
|
|
10137
|
+
return Object.assign(this, params);
|
|
10171
10138
|
};
|
|
10172
10139
|
yy.Over.prototype.toString = function () {
|
|
10173
10140
|
var s = 'OVER (';
|
|
@@ -10190,13 +10157,15 @@ yy.Over.prototype.toString = function () {
|
|
|
10190
10157
|
//
|
|
10191
10158
|
*/
|
|
10192
10159
|
|
|
10160
|
+
var assign = Object.assign;
|
|
10161
|
+
|
|
10193
10162
|
/**
|
|
10194
10163
|
Expression statement ( = 2*2; )
|
|
10195
10164
|
@class
|
|
10196
10165
|
@param {object} params Initial parameters
|
|
10197
10166
|
*/
|
|
10198
10167
|
yy.ExpressionStatement = function (params) {
|
|
10199
|
-
return
|
|
10168
|
+
return assign(this, params);
|
|
10200
10169
|
};
|
|
10201
10170
|
|
|
10202
10171
|
/**
|
|
@@ -10237,7 +10206,7 @@ yy.ExpressionStatement.prototype.execute = function (databaseid, params, cb) {
|
|
|
10237
10206
|
*/
|
|
10238
10207
|
|
|
10239
10208
|
yy.Expression = function (params) {
|
|
10240
|
-
return
|
|
10209
|
+
return assign(this, params);
|
|
10241
10210
|
};
|
|
10242
10211
|
|
|
10243
10212
|
/**
|
|
@@ -10309,7 +10278,7 @@ yy.Expression.prototype.compile = function (context, tableid, defcols) {
|
|
|
10309
10278
|
@class
|
|
10310
10279
|
*/
|
|
10311
10280
|
yy.JavaScript = function (params) {
|
|
10312
|
-
return
|
|
10281
|
+
return assign(this, params);
|
|
10313
10282
|
};
|
|
10314
10283
|
yy.JavaScript.prototype.toString = function () {
|
|
10315
10284
|
var s = '``' + this.value + '``';
|
|
@@ -10337,7 +10306,7 @@ yy.JavaScript.prototype.execute = function (databaseid, params, cb) {
|
|
|
10337
10306
|
*/
|
|
10338
10307
|
|
|
10339
10308
|
yy.Literal = function (params) {
|
|
10340
|
-
return
|
|
10309
|
+
return assign(this, params);
|
|
10341
10310
|
};
|
|
10342
10311
|
yy.Literal.prototype.toString = function () {
|
|
10343
10312
|
var s = this.value;
|
|
@@ -10354,7 +10323,7 @@ yy.Literal.prototype.toString = function () {
|
|
|
10354
10323
|
*/
|
|
10355
10324
|
|
|
10356
10325
|
yy.Join = function (params) {
|
|
10357
|
-
return
|
|
10326
|
+
return assign(this, params);
|
|
10358
10327
|
};
|
|
10359
10328
|
yy.Join.prototype.toString = function () {
|
|
10360
10329
|
var s = ' ';
|
|
@@ -10371,7 +10340,7 @@ yy.Join.prototype.toString = function () {
|
|
|
10371
10340
|
*/
|
|
10372
10341
|
|
|
10373
10342
|
yy.Table = function (params) {
|
|
10374
|
-
return
|
|
10343
|
+
return assign(this, params);
|
|
10375
10344
|
};
|
|
10376
10345
|
yy.Table.prototype.toString = function () {
|
|
10377
10346
|
var s = this.tableid;
|
|
@@ -10388,7 +10357,7 @@ yy.Table.prototype.toString = function () {
|
|
|
10388
10357
|
*/
|
|
10389
10358
|
|
|
10390
10359
|
yy.View = function (params) {
|
|
10391
|
-
return
|
|
10360
|
+
return assign(this, params);
|
|
10392
10361
|
};
|
|
10393
10362
|
yy.View.prototype.toString = function () {
|
|
10394
10363
|
var s = this.viewid;
|
|
@@ -10404,7 +10373,7 @@ yy.View.prototype.toString = function () {
|
|
|
10404
10373
|
@class
|
|
10405
10374
|
*/
|
|
10406
10375
|
yy.Op = function (params) {
|
|
10407
|
-
return
|
|
10376
|
+
return assign(this, params);
|
|
10408
10377
|
};
|
|
10409
10378
|
yy.Op.prototype.toString = function () {
|
|
10410
10379
|
if (this.op === 'IN' || this.op === 'NOT IN') {
|
|
@@ -10602,9 +10571,9 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10602
10571
|
||
|
|
10603
10572
|
(
|
|
10604
10573
|
${leftOperand} < 0
|
|
10605
|
-
&&
|
|
10606
|
-
true == ${rightOperand}
|
|
10607
|
-
)
|
|
10574
|
+
&&
|
|
10575
|
+
true == ${rightOperand}
|
|
10576
|
+
)
|
|
10608
10577
|
)`;
|
|
10609
10578
|
}
|
|
10610
10579
|
}
|
|
@@ -10790,7 +10759,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10790
10759
|
};
|
|
10791
10760
|
|
|
10792
10761
|
yy.VarValue = function (params) {
|
|
10793
|
-
return
|
|
10762
|
+
return assign(this, params);
|
|
10794
10763
|
};
|
|
10795
10764
|
yy.VarValue.prototype.toString = function () {
|
|
10796
10765
|
return '@' + this.variable;
|
|
@@ -10805,7 +10774,7 @@ yy.VarValue.prototype.toJS = function () {
|
|
|
10805
10774
|
};
|
|
10806
10775
|
|
|
10807
10776
|
yy.NumValue = function (params) {
|
|
10808
|
-
return
|
|
10777
|
+
return assign(this, params);
|
|
10809
10778
|
};
|
|
10810
10779
|
yy.NumValue.prototype.toString = function () {
|
|
10811
10780
|
return this.value.toString();
|
|
@@ -10820,7 +10789,7 @@ yy.NumValue.prototype.toJS = function () {
|
|
|
10820
10789
|
};
|
|
10821
10790
|
|
|
10822
10791
|
yy.StringValue = function (params) {
|
|
10823
|
-
return
|
|
10792
|
+
return assign(this, params);
|
|
10824
10793
|
};
|
|
10825
10794
|
yy.StringValue.prototype.toString = function () {
|
|
10826
10795
|
return "'" + this.value.toString() + "'";
|
|
@@ -10835,7 +10804,7 @@ yy.StringValue.prototype.toJS = function () {
|
|
|
10835
10804
|
};
|
|
10836
10805
|
|
|
10837
10806
|
yy.DomainValueValue = function (params) {
|
|
10838
|
-
return
|
|
10807
|
+
return assign(this, params);
|
|
10839
10808
|
};
|
|
10840
10809
|
yy.DomainValueValue.prototype.toString = function () {
|
|
10841
10810
|
return 'VALUE';
|
|
@@ -10852,7 +10821,7 @@ yy.DomainValueValue.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10852
10821
|
};
|
|
10853
10822
|
|
|
10854
10823
|
yy.ArrayValue = function (params) {
|
|
10855
|
-
return
|
|
10824
|
+
return assign(this, params);
|
|
10856
10825
|
};
|
|
10857
10826
|
yy.ArrayValue.prototype.toString = function () {
|
|
10858
10827
|
return 'ARRAY[]';
|
|
@@ -10875,7 +10844,7 @@ yy.ArrayValue.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10875
10844
|
};
|
|
10876
10845
|
|
|
10877
10846
|
yy.LogicValue = function (params) {
|
|
10878
|
-
return
|
|
10847
|
+
return assign(this, params);
|
|
10879
10848
|
};
|
|
10880
10849
|
yy.LogicValue.prototype.toString = function () {
|
|
10881
10850
|
return this.value ? 'TRUE' : 'FALSE';
|
|
@@ -10890,7 +10859,7 @@ yy.LogicValue.prototype.toJS = function () {
|
|
|
10890
10859
|
};
|
|
10891
10860
|
|
|
10892
10861
|
yy.NullValue = function (params) {
|
|
10893
|
-
return
|
|
10862
|
+
return assign(this, params);
|
|
10894
10863
|
};
|
|
10895
10864
|
yy.NullValue.prototype.toString = function () {
|
|
10896
10865
|
return 'NULL';
|
|
@@ -10901,7 +10870,7 @@ yy.NullValue.prototype.toJS = function () {
|
|
|
10901
10870
|
};
|
|
10902
10871
|
|
|
10903
10872
|
yy.ParamValue = function (params) {
|
|
10904
|
-
return
|
|
10873
|
+
return assign(this, params);
|
|
10905
10874
|
};
|
|
10906
10875
|
yy.ParamValue.prototype.toString = function () {
|
|
10907
10876
|
return '$' + this.param;
|
|
@@ -10915,7 +10884,7 @@ yy.ParamValue.prototype.toJS = function () {
|
|
|
10915
10884
|
};
|
|
10916
10885
|
|
|
10917
10886
|
yy.UniOp = function (params) {
|
|
10918
|
-
return
|
|
10887
|
+
return assign(this, params);
|
|
10919
10888
|
};
|
|
10920
10889
|
yy.UniOp.prototype.toString = function () {
|
|
10921
10890
|
var s;
|
|
@@ -11005,7 +10974,7 @@ yy.UniOp.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11005
10974
|
};
|
|
11006
10975
|
|
|
11007
10976
|
yy.Column = function (params) {
|
|
11008
|
-
return
|
|
10977
|
+
return assign(this, params);
|
|
11009
10978
|
};
|
|
11010
10979
|
yy.Column.prototype.toString = function () {
|
|
11011
10980
|
var s;
|
|
@@ -11086,7 +11055,7 @@ yy.Column.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11086
11055
|
};
|
|
11087
11056
|
|
|
11088
11057
|
yy.AggrValue = function (params) {
|
|
11089
|
-
return
|
|
11058
|
+
return assign(this, params);
|
|
11090
11059
|
};
|
|
11091
11060
|
yy.AggrValue.prototype.toString = function () {
|
|
11092
11061
|
var s = '';
|
|
@@ -11161,13 +11130,13 @@ yy.AggrValue.prototype.toJS = function () {
|
|
|
11161
11130
|
};
|
|
11162
11131
|
|
|
11163
11132
|
yy.OrderExpression = function (params) {
|
|
11164
|
-
return
|
|
11133
|
+
return assign(this, params);
|
|
11165
11134
|
};
|
|
11166
11135
|
|
|
11167
11136
|
yy.OrderExpression.prototype.toString = yy.Expression.prototype.toString;
|
|
11168
11137
|
|
|
11169
11138
|
yy.GroupExpression = function (params) {
|
|
11170
|
-
return
|
|
11139
|
+
return assign(this, params);
|
|
11171
11140
|
};
|
|
11172
11141
|
yy.GroupExpression.prototype.toString = function () {
|
|
11173
11142
|
return this.type + '(' + this.group.toString() + ')';
|
|
@@ -11348,7 +11317,7 @@ yy.Select.prototype.Where = function (expr) {
|
|
|
11348
11317
|
*/
|
|
11349
11318
|
|
|
11350
11319
|
yy.FuncValue = function (params) {
|
|
11351
|
-
return
|
|
11320
|
+
return Object.assign(this, params);
|
|
11352
11321
|
};
|
|
11353
11322
|
|
|
11354
11323
|
var re_invalidFnNameChars = /[^0-9A-Z_$]+/i;
|
|
@@ -11810,7 +11779,7 @@ stdfn.NEWID =
|
|
|
11810
11779
|
*/
|
|
11811
11780
|
|
|
11812
11781
|
yy.CaseValue = function (params) {
|
|
11813
|
-
return
|
|
11782
|
+
return Object.assign(this, params);
|
|
11814
11783
|
};
|
|
11815
11784
|
yy.CaseValue.prototype.toString = function () {
|
|
11816
11785
|
var s = 'CASE ';
|
|
@@ -11884,7 +11853,7 @@ yy.CaseValue.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11884
11853
|
*/
|
|
11885
11854
|
|
|
11886
11855
|
yy.Json = function (params) {
|
|
11887
|
-
return
|
|
11856
|
+
return Object.assign(this, params);
|
|
11888
11857
|
};
|
|
11889
11858
|
yy.Json.prototype.toString = function () {
|
|
11890
11859
|
var s = ''; // '@'
|
|
@@ -11993,7 +11962,7 @@ yy.Json.prototype.toJS = function (context, tableid, defcols) {
|
|
|
11993
11962
|
*/
|
|
11994
11963
|
|
|
11995
11964
|
yy.Convert = function (params) {
|
|
11996
|
-
return
|
|
11965
|
+
return Object.assign(this, params);
|
|
11997
11966
|
};
|
|
11998
11967
|
yy.Convert.prototype.toString = function () {
|
|
11999
11968
|
var s = 'CONVERT(';
|
|
@@ -12287,7 +12256,7 @@ alasql.stdfn.CONVERT = function (value, args) {
|
|
|
12287
12256
|
/* global alasql, yy, hash */
|
|
12288
12257
|
|
|
12289
12258
|
yy.ColumnDef = function (params) {
|
|
12290
|
-
return
|
|
12259
|
+
return Object.assign(this, params);
|
|
12291
12260
|
};
|
|
12292
12261
|
yy.ColumnDef.prototype.toString = function () {
|
|
12293
12262
|
var s = this.columnid;
|
|
@@ -12315,7 +12284,7 @@ yy.ColumnDef.prototype.toString = function () {
|
|
|
12315
12284
|
};
|
|
12316
12285
|
|
|
12317
12286
|
yy.CreateTable = function (params) {
|
|
12318
|
-
return
|
|
12287
|
+
return Object.assign(this, params);
|
|
12319
12288
|
};
|
|
12320
12289
|
yy.CreateTable.prototype.toString = function () {
|
|
12321
12290
|
var s = 'CREATE';
|
|
@@ -13133,7 +13102,7 @@ function newDate(d) {
|
|
|
13133
13102
|
*/
|
|
13134
13103
|
|
|
13135
13104
|
yy.DropTable = function (params) {
|
|
13136
|
-
return
|
|
13105
|
+
return Object.assign(this, params);
|
|
13137
13106
|
};
|
|
13138
13107
|
yy.DropTable.prototype.toString = function () {
|
|
13139
13108
|
var s = 'DROP' + ' ';
|
|
@@ -13206,7 +13175,7 @@ yy.DropTable.prototype.execute = function (databaseid, params, cb) {
|
|
|
13206
13175
|
};
|
|
13207
13176
|
|
|
13208
13177
|
yy.TruncateTable = function (params) {
|
|
13209
|
-
return
|
|
13178
|
+
return Object.assign(this, params);
|
|
13210
13179
|
};
|
|
13211
13180
|
yy.TruncateTable.prototype.toString = function () {
|
|
13212
13181
|
var s = 'TRUNCATE TABLE';
|
|
@@ -13242,7 +13211,7 @@ yy.TruncateTable.prototype.execute = function (databaseid, params, cb) {
|
|
|
13242
13211
|
*/
|
|
13243
13212
|
|
|
13244
13213
|
yy.CreateVertex = function (params) {
|
|
13245
|
-
return
|
|
13214
|
+
return Object.assign(this, params);
|
|
13246
13215
|
};
|
|
13247
13216
|
yy.CreateVertex.prototype.toString = function () {
|
|
13248
13217
|
var s = 'CREATE VERTEX ';
|
|
@@ -13325,7 +13294,7 @@ yy.CreateVertex.prototype.compile = function (databaseid) {
|
|
|
13325
13294
|
};
|
|
13326
13295
|
|
|
13327
13296
|
yy.CreateEdge = function (params) {
|
|
13328
|
-
return
|
|
13297
|
+
return Object.assign(this, params);
|
|
13329
13298
|
};
|
|
13330
13299
|
yy.CreateEdge.prototype.toString = function () {
|
|
13331
13300
|
|
|
@@ -13418,7 +13387,7 @@ yy.CreateEdge.prototype.compile = function (databaseid) {
|
|
|
13418
13387
|
};
|
|
13419
13388
|
|
|
13420
13389
|
yy.CreateGraph = function (params) {
|
|
13421
|
-
return
|
|
13390
|
+
return Object.assign(this, params);
|
|
13422
13391
|
};
|
|
13423
13392
|
yy.CreateGraph.prototype.toString = function () {
|
|
13424
13393
|
var s = 'CREATE GRAPH' + ' ';
|
|
@@ -13683,7 +13652,7 @@ yy.CreateGraph.prototype.compile1 = function (databaseid) {
|
|
|
13683
13652
|
|
|
13684
13653
|
// ALTER TABLE table1 RENAME TO table2
|
|
13685
13654
|
yy.AlterTable = function (params) {
|
|
13686
|
-
return
|
|
13655
|
+
return Object.assign(this, params);
|
|
13687
13656
|
};
|
|
13688
13657
|
yy.AlterTable.prototype.toString = function () {
|
|
13689
13658
|
var s = 'ALTER TABLE ' + this.table.toString();
|
|
@@ -13860,7 +13829,7 @@ yy.AlterTable.prototype.execute = function (databaseid, params, cb) {
|
|
|
13860
13829
|
*/
|
|
13861
13830
|
|
|
13862
13831
|
yy.CreateIndex = function (params) {
|
|
13863
|
-
return
|
|
13832
|
+
return Object.assign(this, params);
|
|
13864
13833
|
};
|
|
13865
13834
|
yy.CreateIndex.prototype.toString = function () {
|
|
13866
13835
|
var s = 'CREATE';
|
|
@@ -13923,7 +13892,7 @@ yy.CreateIndex.prototype.execute = function (databaseid, params, cb) {
|
|
|
13923
13892
|
};
|
|
13924
13893
|
|
|
13925
13894
|
yy.Reindex = function (params) {
|
|
13926
|
-
return
|
|
13895
|
+
return Object.assign(this, params);
|
|
13927
13896
|
};
|
|
13928
13897
|
yy.Reindex.prototype.toString = function () {
|
|
13929
13898
|
var s = 'REINDEX ' + this.indexid;
|
|
@@ -13953,7 +13922,7 @@ yy.Reindex.prototype.execute = function (databaseid, params, cb) {
|
|
|
13953
13922
|
*/
|
|
13954
13923
|
|
|
13955
13924
|
yy.DropIndex = function (params) {
|
|
13956
|
-
return
|
|
13925
|
+
return Object.assign(this, params);
|
|
13957
13926
|
};
|
|
13958
13927
|
yy.DropIndex.prototype.toString = function () {
|
|
13959
13928
|
return 'DROP INDEX' + this.indexid;
|
|
@@ -13976,7 +13945,7 @@ yy.DropIndex.prototype.compile = function (db) {
|
|
|
13976
13945
|
*/
|
|
13977
13946
|
|
|
13978
13947
|
yy.WithSelect = function (params) {
|
|
13979
|
-
return
|
|
13948
|
+
return Object.assign(this, params);
|
|
13980
13949
|
};
|
|
13981
13950
|
yy.WithSelect.prototype.toString = function () {
|
|
13982
13951
|
var s = 'WITH ';
|
|
@@ -14025,7 +13994,7 @@ yy.WithSelect.prototype.execute = function (databaseid, params, cb) {
|
|
|
14025
13994
|
*/
|
|
14026
13995
|
|
|
14027
13996
|
yy.If = function (params) {
|
|
14028
|
-
return
|
|
13997
|
+
return Object.assign(this, params);
|
|
14029
13998
|
};
|
|
14030
13999
|
yy.If.prototype.toString = function () {
|
|
14031
14000
|
var s = 'IF' + ' ';
|
|
@@ -14065,7 +14034,7 @@ yy.If.prototype.execute = function (databaseid, params, cb) {
|
|
|
14065
14034
|
*/
|
|
14066
14035
|
|
|
14067
14036
|
yy.While = function (params) {
|
|
14068
|
-
return
|
|
14037
|
+
return Object.assign(this, params);
|
|
14069
14038
|
};
|
|
14070
14039
|
yy.While.prototype.toString = function () {
|
|
14071
14040
|
var s = 'WHILE ';
|
|
@@ -14107,7 +14076,7 @@ yy.While.prototype.execute = function (databaseid, params, cb) {
|
|
|
14107
14076
|
};
|
|
14108
14077
|
|
|
14109
14078
|
yy.Break = function (params) {
|
|
14110
|
-
return
|
|
14079
|
+
return Object.assign(this, params);
|
|
14111
14080
|
};
|
|
14112
14081
|
yy.Break.prototype.toString = function () {
|
|
14113
14082
|
var s = 'BREAK';
|
|
@@ -14121,7 +14090,7 @@ yy.Break.prototype.execute = function (databaseid, params, cb, scope) {
|
|
|
14121
14090
|
};
|
|
14122
14091
|
|
|
14123
14092
|
yy.Continue = function (params) {
|
|
14124
|
-
return
|
|
14093
|
+
return Object.assign(this, params);
|
|
14125
14094
|
};
|
|
14126
14095
|
yy.Continue.prototype.toString = function () {
|
|
14127
14096
|
var s = 'CONTINUE';
|
|
@@ -14135,7 +14104,7 @@ yy.Continue.prototype.execute = function (databaseid, params, cb, scope) {
|
|
|
14135
14104
|
};
|
|
14136
14105
|
|
|
14137
14106
|
yy.BeginEnd = function (params) {
|
|
14138
|
-
return
|
|
14107
|
+
return Object.assign(this, params);
|
|
14139
14108
|
};
|
|
14140
14109
|
yy.BeginEnd.prototype.toString = function () {
|
|
14141
14110
|
var s = 'BEGIN ' + this.statements.toString() + ' END';
|
|
@@ -14169,7 +14138,7 @@ yy.BeginEnd.prototype.execute = function (databaseid, params, cb, scope) {
|
|
|
14169
14138
|
|
|
14170
14139
|
/* global yy alasql*/
|
|
14171
14140
|
yy.Insert = function (params) {
|
|
14172
|
-
return
|
|
14141
|
+
return Object.assign(this, params);
|
|
14173
14142
|
};
|
|
14174
14143
|
yy.Insert.prototype.toString = function () {
|
|
14175
14144
|
var s = 'INSERT ';
|
|
@@ -14437,7 +14406,7 @@ yy.Insert.prototype.execute = function (databaseid, params, cb) {
|
|
|
14437
14406
|
*/
|
|
14438
14407
|
|
|
14439
14408
|
yy.CreateTrigger = function (params) {
|
|
14440
|
-
return
|
|
14409
|
+
return Object.assign(this, params);
|
|
14441
14410
|
};
|
|
14442
14411
|
yy.CreateTrigger.prototype.toString = function () {
|
|
14443
14412
|
var s = 'CREATE TRIGGER ' + this.trigger + ' ';
|
|
@@ -14490,7 +14459,7 @@ yy.CreateTrigger.prototype.execute = function (databaseid, params, cb) {
|
|
|
14490
14459
|
};
|
|
14491
14460
|
|
|
14492
14461
|
yy.DropTrigger = function (params) {
|
|
14493
|
-
return
|
|
14462
|
+
return Object.assign(this, params);
|
|
14494
14463
|
};
|
|
14495
14464
|
yy.DropTrigger.prototype.toString = function () {
|
|
14496
14465
|
var s = 'DROP TRIGGER ' + this.trigger;
|
|
@@ -14549,7 +14518,7 @@ yy.DropTrigger.prototype.execute = function (databaseid, params, cb) {
|
|
|
14549
14518
|
*/
|
|
14550
14519
|
|
|
14551
14520
|
yy.Delete = function (params) {
|
|
14552
|
-
return
|
|
14521
|
+
return Object.assign(this, params);
|
|
14553
14522
|
};
|
|
14554
14523
|
yy.Delete.prototype.toString = function () {
|
|
14555
14524
|
var s = 'DELETE FROM ' + this.table.toString();
|
|
@@ -14708,7 +14677,7 @@ yy.Delete.prototype.execute = function (databaseid, params, cb) {
|
|
|
14708
14677
|
/* global yy alasql */
|
|
14709
14678
|
|
|
14710
14679
|
yy.Update = function (params) {
|
|
14711
|
-
return
|
|
14680
|
+
return Object.assign(this, params);
|
|
14712
14681
|
};
|
|
14713
14682
|
yy.Update.prototype.toString = function () {
|
|
14714
14683
|
var s = 'UPDATE ' + this.table.toString();
|
|
@@ -14718,7 +14687,7 @@ yy.Update.prototype.toString = function () {
|
|
|
14718
14687
|
};
|
|
14719
14688
|
|
|
14720
14689
|
yy.SetColumn = function (params) {
|
|
14721
|
-
return
|
|
14690
|
+
return Object.assign(this, params);
|
|
14722
14691
|
};
|
|
14723
14692
|
yy.SetColumn.prototype.toString = function () {
|
|
14724
14693
|
return this.column.toString() + '=' + this.expression.toString();
|
|
@@ -14820,7 +14789,7 @@ yy.Update.prototype.execute = function (databaseid, params, cb) {
|
|
|
14820
14789
|
/* global alasql, yy */
|
|
14821
14790
|
|
|
14822
14791
|
yy.Merge = function (params) {
|
|
14823
|
-
return
|
|
14792
|
+
return Object.assign(this, params);
|
|
14824
14793
|
};
|
|
14825
14794
|
yy.Merge.prototype.toString = function () {
|
|
14826
14795
|
var s = 'MERGE ';
|
|
@@ -14878,7 +14847,7 @@ yy.Merge.prototype.execute = function (databaseid, params, cb) {
|
|
|
14878
14847
|
|
|
14879
14848
|
// CREATE DATABASE databaseid
|
|
14880
14849
|
yy.CreateDatabase = function (params) {
|
|
14881
|
-
return
|
|
14850
|
+
return Object.assign(this, params);
|
|
14882
14851
|
};
|
|
14883
14852
|
yy.CreateDatabase.prototype.toString = function () {
|
|
14884
14853
|
var s = 'CREATE';
|
|
@@ -14931,7 +14900,7 @@ yy.CreateDatabase.prototype.execute = function (databaseid, params, cb) {
|
|
|
14931
14900
|
|
|
14932
14901
|
// CREATE DATABASE databaseid
|
|
14933
14902
|
yy.AttachDatabase = function (params) {
|
|
14934
|
-
return
|
|
14903
|
+
return Object.assign(this, params);
|
|
14935
14904
|
};
|
|
14936
14905
|
yy.AttachDatabase.prototype.toString = function (args) {
|
|
14937
14906
|
var s = 'ATTACH';
|
|
@@ -14969,7 +14938,7 @@ yy.AttachDatabase.prototype.execute = function (databaseid, params, cb) {
|
|
|
14969
14938
|
|
|
14970
14939
|
// CREATE DATABASE databaseid
|
|
14971
14940
|
yy.DetachDatabase = function (params) {
|
|
14972
|
-
return
|
|
14941
|
+
return Object.assign(this, params);
|
|
14973
14942
|
};
|
|
14974
14943
|
yy.DetachDatabase.prototype.toString = function () {
|
|
14975
14944
|
var s = 'DETACH';
|
|
@@ -15030,7 +14999,7 @@ yy.DetachDatabase.prototype.execute = function (databaseid, params, cb) {
|
|
|
15030
14999
|
// USE DATABSE databaseid
|
|
15031
15000
|
// USE databaseid
|
|
15032
15001
|
yy.UseDatabase = function (params) {
|
|
15033
|
-
return
|
|
15002
|
+
return Object.assign(this, params);
|
|
15034
15003
|
};
|
|
15035
15004
|
yy.UseDatabase.prototype.toString = function () {
|
|
15036
15005
|
return 'USE' + ' ' + 'DATABASE' + ' ' + this.databaseid;
|
|
@@ -15049,7 +15018,7 @@ yy.UseDatabase.prototype.execute = function (databaseid, params, cb) {
|
|
|
15049
15018
|
|
|
15050
15019
|
// DROP DATABASE databaseid
|
|
15051
15020
|
yy.DropDatabase = function (params) {
|
|
15052
|
-
return
|
|
15021
|
+
return Object.assign(this, params);
|
|
15053
15022
|
};
|
|
15054
15023
|
yy.DropDatabase.prototype.toString = function () {
|
|
15055
15024
|
var s = 'DROP';
|
|
@@ -15099,7 +15068,7 @@ yy.DropDatabase.prototype.execute = function (databaseid, params, cb) {
|
|
|
15099
15068
|
*/
|
|
15100
15069
|
|
|
15101
15070
|
yy.Declare = function (params) {
|
|
15102
|
-
return
|
|
15071
|
+
return Object.assign(this, params);
|
|
15103
15072
|
};
|
|
15104
15073
|
yy.Declare.prototype.toString = function () {
|
|
15105
15074
|
var s = 'DECLARE ';
|
|
@@ -15171,7 +15140,7 @@ yy.Declare.prototype.execute = function (databaseid, params, cb) {
|
|
|
15171
15140
|
*/
|
|
15172
15141
|
|
|
15173
15142
|
yy.ShowDatabases = function (params) {
|
|
15174
|
-
return
|
|
15143
|
+
return Object.assign(this, params);
|
|
15175
15144
|
};
|
|
15176
15145
|
yy.ShowDatabases.prototype.toString = function () {
|
|
15177
15146
|
var s = 'SHOW DATABASES';
|
|
@@ -15199,7 +15168,7 @@ yy.ShowDatabases.prototype.execute = function (databaseid, params, cb) {
|
|
|
15199
15168
|
};
|
|
15200
15169
|
|
|
15201
15170
|
yy.ShowTables = function (params) {
|
|
15202
|
-
return
|
|
15171
|
+
return Object.assign(this, params);
|
|
15203
15172
|
};
|
|
15204
15173
|
yy.ShowTables.prototype.toString = function () {
|
|
15205
15174
|
var s = 'SHOW TABLES';
|
|
@@ -15226,7 +15195,7 @@ yy.ShowTables.prototype.execute = function (databaseid, params, cb) {
|
|
|
15226
15195
|
};
|
|
15227
15196
|
|
|
15228
15197
|
yy.ShowColumns = function (params) {
|
|
15229
|
-
return
|
|
15198
|
+
return Object.assign(this, params);
|
|
15230
15199
|
};
|
|
15231
15200
|
yy.ShowColumns.prototype.toString = function () {
|
|
15232
15201
|
var s = 'SHOW COLUMNS';
|
|
@@ -15252,7 +15221,7 @@ yy.ShowColumns.prototype.execute = function (databaseid, params, cb) {
|
|
|
15252
15221
|
};
|
|
15253
15222
|
|
|
15254
15223
|
yy.ShowIndex = function (params) {
|
|
15255
|
-
return
|
|
15224
|
+
return Object.assign(this, params);
|
|
15256
15225
|
};
|
|
15257
15226
|
yy.ShowIndex.prototype.toString = function () {
|
|
15258
15227
|
var s = 'SHOW INDEX';
|
|
@@ -15275,7 +15244,7 @@ yy.ShowIndex.prototype.execute = function (databaseid, params, cb) {
|
|
|
15275
15244
|
};
|
|
15276
15245
|
|
|
15277
15246
|
yy.ShowCreateTable = function (params) {
|
|
15278
|
-
return
|
|
15247
|
+
return Object.assign(this, params);
|
|
15279
15248
|
};
|
|
15280
15249
|
yy.ShowCreateTable.prototype.toString = function () {
|
|
15281
15250
|
var s = 'SHOW CREATE TABLE ' + this.table.tableid;
|
|
@@ -15314,7 +15283,7 @@ yy.ShowCreateTable.prototype.execute = function (databaseid) {
|
|
|
15314
15283
|
*/
|
|
15315
15284
|
|
|
15316
15285
|
yy.SetVariable = function (params) {
|
|
15317
|
-
return
|
|
15286
|
+
return Object.assign(this, params);
|
|
15318
15287
|
};
|
|
15319
15288
|
yy.SetVariable.prototype.toString = function () {
|
|
15320
15289
|
var s = 'SET ';
|
|
@@ -15705,7 +15674,7 @@ alasql.prompt = function (el, useidel, firstsql) {
|
|
|
15705
15674
|
//
|
|
15706
15675
|
*/
|
|
15707
15676
|
yy.BeginTransaction = function (params) {
|
|
15708
|
-
return
|
|
15677
|
+
return Object.assign(this, params);
|
|
15709
15678
|
};
|
|
15710
15679
|
yy.BeginTransaction.prototype.toString = function () {
|
|
15711
15680
|
return 'BEGIN TRANSACTION';
|
|
@@ -15723,7 +15692,7 @@ yy.BeginTransaction.prototype.execute = function (databaseid, params, cb) {
|
|
|
15723
15692
|
};
|
|
15724
15693
|
|
|
15725
15694
|
yy.CommitTransaction = function (params) {
|
|
15726
|
-
return
|
|
15695
|
+
return Object.assign(this, params);
|
|
15727
15696
|
};
|
|
15728
15697
|
yy.CommitTransaction.prototype.toString = function () {
|
|
15729
15698
|
return 'COMMIT TRANSACTION';
|
|
@@ -15741,7 +15710,7 @@ yy.CommitTransaction.prototype.execute = function (databaseid, params, cb) {
|
|
|
15741
15710
|
};
|
|
15742
15711
|
|
|
15743
15712
|
yy.RollbackTransaction = function (params) {
|
|
15744
|
-
return
|
|
15713
|
+
return Object.assign(this, params);
|
|
15745
15714
|
};
|
|
15746
15715
|
yy.RollbackTransaction.prototype.toString = function () {
|
|
15747
15716
|
return 'ROLLBACK TRANSACTION';
|
|
@@ -17610,7 +17579,7 @@ alasql.from.GEXF = function (filename, opts, cb, idx, query) {
|
|
|
17610
17579
|
/* globals: alasql, yy */
|
|
17611
17580
|
|
|
17612
17581
|
/**
|
|
17613
|
-
Print statement
|
|
17582
|
+
Print statement
|
|
17614
17583
|
@class
|
|
17615
17584
|
@param {object} params Initial setup properties
|
|
17616
17585
|
*/
|
|
@@ -17618,11 +17587,11 @@ alasql.from.GEXF = function (filename, opts, cb, idx, query) {
|
|
|
17618
17587
|
/* global alasql, yy */
|
|
17619
17588
|
|
|
17620
17589
|
yy.Print = function (params) {
|
|
17621
|
-
return
|
|
17590
|
+
return Object.assign(this, params);
|
|
17622
17591
|
};
|
|
17623
17592
|
|
|
17624
|
-
/**
|
|
17625
|
-
Generate SQL string
|
|
17593
|
+
/**
|
|
17594
|
+
Generate SQL string
|
|
17626
17595
|
@this Print statement object
|
|
17627
17596
|
*/
|
|
17628
17597
|
yy.Print.prototype.toString = function () {
|
|
@@ -17635,7 +17604,7 @@ yy.Print.prototype.toString = function () {
|
|
|
17635
17604
|
Print result of select statement or expression
|
|
17636
17605
|
@param {string} databaseid Database identificator
|
|
17637
17606
|
@param {object} params Query parameters
|
|
17638
|
-
@param {statement-callback} cb Callback function
|
|
17607
|
+
@param {statement-callback} cb Callback function
|
|
17639
17608
|
@this Print statement object
|
|
17640
17609
|
*/
|
|
17641
17610
|
yy.Print.prototype.execute = function (databaseid, params, cb) {
|
|
@@ -17676,7 +17645,7 @@ yy.Print.prototype.execute = function (databaseid, params, cb) {
|
|
|
17676
17645
|
*/
|
|
17677
17646
|
|
|
17678
17647
|
yy.Source = function (params) {
|
|
17679
|
-
return
|
|
17648
|
+
return Object.assign(this, params);
|
|
17680
17649
|
};
|
|
17681
17650
|
yy.Source.prototype.toString = function () {
|
|
17682
17651
|
var s = 'SOURCE';
|
|
@@ -17716,7 +17685,7 @@ yy.Source.prototype.execute = function (databaseid, params, cb) {
|
|
|
17716
17685
|
/* global alasql, yy */
|
|
17717
17686
|
|
|
17718
17687
|
yy.Require = function (params) {
|
|
17719
|
-
return
|
|
17688
|
+
return Object.assign(this, params);
|
|
17720
17689
|
};
|
|
17721
17690
|
yy.Require.prototype.toString = function () {
|
|
17722
17691
|
var s = 'REQUIRE';
|
|
@@ -17788,7 +17757,7 @@ yy.Require.prototype.execute = function (databaseid, params, cb) {
|
|
|
17788
17757
|
*/
|
|
17789
17758
|
|
|
17790
17759
|
yy.Assert = function (params) {
|
|
17791
|
-
return
|
|
17760
|
+
return Object.assign(this, params);
|
|
17792
17761
|
};
|
|
17793
17762
|
yy.Source.prototype.toString = function () {
|
|
17794
17763
|
var s = 'ASSERT';
|
|
@@ -17865,29 +17834,46 @@ var IDB = (alasql.engines.INDEXEDDB = function () {
|
|
|
17865
17834
|
'';
|
|
17866
17835
|
});
|
|
17867
17836
|
|
|
17868
|
-
|
|
17869
|
-
|
|
17870
|
-
|
|
17871
|
-
|
|
17872
|
-
|
|
17873
|
-
|
|
17874
|
-
|
|
17875
|
-
|
|
17876
|
-
|
|
17877
|
-
|
|
17878
|
-
|
|
17879
|
-
|
|
17880
|
-
|
|
17881
|
-
|
|
17882
|
-
|
|
17883
|
-
|
|
17884
|
-
var event = {target: {result: result}};
|
|
17885
|
-
request.onsuccess(event);
|
|
17886
|
-
}, 0);
|
|
17887
|
-
return request;
|
|
17888
|
-
};
|
|
17889
|
-
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;
|
|
17890
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
|
+
});
|
|
17891
17877
|
}
|
|
17892
17878
|
|
|
17893
17879
|
//
|
|
@@ -17895,333 +17881,235 @@ if (utils.hasIndexedDB) {
|
|
|
17895
17881
|
// work only in chrome
|
|
17896
17882
|
//
|
|
17897
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');
|
|
17898
17892
|
|
|
17899
|
-
var request = IDB.getDatabaseNames();
|
|
17900
|
-
request.onsuccess = function (event) {
|
|
17901
|
-
var dblist = event.target.result;
|
|
17902
|
-
if (IDB.getDatabaseNamesNotSupported) {
|
|
17903
|
-
throw new Error('SHOW DATABASE is not supported in this browser');
|
|
17904
|
-
}
|
|
17905
|
-
var res = [];
|
|
17906
|
-
if (like) {
|
|
17907
|
-
var relike = new RegExp(like.value.replace(/\%/g, '.*'), 'g');
|
|
17908
|
-
}
|
|
17909
17893
|
for (var i = 0; i < dblist.length; i++) {
|
|
17910
|
-
if (!like || dblist[i].match(relike)) {
|
|
17911
|
-
res.push({databaseid: dblist[i]});
|
|
17894
|
+
if (!like || dblist[i].name.match(relike)) {
|
|
17895
|
+
res.push({databaseid: dblist[i].name});
|
|
17912
17896
|
}
|
|
17913
17897
|
}
|
|
17898
|
+
|
|
17914
17899
|
cb(res);
|
|
17915
|
-
};
|
|
17900
|
+
});
|
|
17916
17901
|
};
|
|
17917
17902
|
|
|
17918
|
-
IDB.createDatabase = function (ixdbid, args, ifnotexists, dbid, cb) {
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
request2.onsuccess = function (event) {
|
|
17924
|
-
event.target.result.close();
|
|
17925
|
-
if (cb) cb(1);
|
|
17926
|
-
};
|
|
17927
|
-
} else {
|
|
17928
|
-
var request1 = indexedDB.open(ixdbid, 1);
|
|
17929
|
-
request1.onupgradeneeded = function (e) {
|
|
17930
|
-
|
|
17931
|
-
e.target.transaction.abort();
|
|
17932
|
-
};
|
|
17933
|
-
request1.onsuccess = function (e) {
|
|
17934
|
-
|
|
17935
|
-
if (ifnotexists) {
|
|
17936
|
-
if (cb) cb(0);
|
|
17937
|
-
} else {
|
|
17938
|
-
throw new Error(
|
|
17939
|
-
'IndexedDB: Cannot create new database "' + ixdbid + '" because it already exists'
|
|
17940
|
-
);
|
|
17941
|
-
}
|
|
17942
|
-
};
|
|
17943
|
-
}
|
|
17944
|
-
|
|
17945
|
-
};
|
|
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
|
+
});
|
|
17946
17908
|
|
|
17947
|
-
|
|
17948
|
-
var indexedDB = utils.global.indexedDB;
|
|
17949
|
-
if (IDB.getDatabaseNamesNotSupported) {
|
|
17950
|
-
// Hack for Firefox
|
|
17909
|
+
if (found) {
|
|
17951
17910
|
if (ifnotexists) {
|
|
17952
|
-
|
|
17953
|
-
var dbExists = true;
|
|
17954
|
-
var request2 = indexedDB.open(ixdbid);
|
|
17955
|
-
|
|
17956
|
-
request2.onupgradeneeded = function (e) {
|
|
17957
|
-
|
|
17958
|
-
dbExists = false;
|
|
17959
|
-
// e.target.transaction.abort();
|
|
17960
|
-
// cb(0);
|
|
17961
|
-
};
|
|
17962
|
-
request2.onsuccess = function (event) {
|
|
17963
|
-
|
|
17964
|
-
event.target.result.close();
|
|
17965
|
-
if (dbExists) {
|
|
17966
|
-
if (cb) cb(0);
|
|
17967
|
-
} else {
|
|
17968
|
-
if (cb) cb(1);
|
|
17969
|
-
}
|
|
17970
|
-
};
|
|
17911
|
+
cb && cb(0);
|
|
17971
17912
|
} else {
|
|
17972
|
-
|
|
17973
|
-
|
|
17974
|
-
|
|
17975
|
-
|
|
17976
|
-
};
|
|
17977
|
-
request1.onabort = function (event) {
|
|
17978
|
-
if (cb) cb(1);
|
|
17979
|
-
};
|
|
17980
|
-
request1.onsuccess = function (event) {
|
|
17981
|
-
event.target.result.close();
|
|
17982
|
-
throw new Error(
|
|
17983
|
-
'IndexedDB: Cannot create new database "' + ixdbid + '" because it already exists'
|
|
17984
|
-
);
|
|
17985
|
-
// cb(0);
|
|
17986
|
-
};
|
|
17913
|
+
const err = new Error(
|
|
17914
|
+
`IndexedDB: Cannot create new database "${ixdbid}" because it already exists`
|
|
17915
|
+
);
|
|
17916
|
+
if (cb) cb(null, err);
|
|
17987
17917
|
}
|
|
17988
17918
|
} else {
|
|
17989
|
-
|
|
17990
|
-
|
|
17991
|
-
|
|
17992
|
-
|
|
17993
|
-
if (ifnotexists) {
|
|
17994
|
-
if (cb) cb(0);
|
|
17995
|
-
return;
|
|
17996
|
-
} else {
|
|
17997
|
-
throw new Error(
|
|
17998
|
-
'IndexedDB: Cannot create new database "' + ixdbid + '" because it already exists'
|
|
17999
|
-
);
|
|
18000
|
-
}
|
|
18001
|
-
}
|
|
18002
|
-
|
|
18003
|
-
var request2 = indexedDB.open(ixdbid, 1);
|
|
18004
|
-
request2.onsuccess = function (event) {
|
|
18005
|
-
event.target.result.close();
|
|
18006
|
-
if (cb) cb(1);
|
|
18007
|
-
};
|
|
17919
|
+
const request = indexedDB.open(ixdbid, 1);
|
|
17920
|
+
request.onsuccess = () => {
|
|
17921
|
+
request.result.close();
|
|
17922
|
+
cb(1);
|
|
18008
17923
|
};
|
|
18009
17924
|
}
|
|
18010
17925
|
};
|
|
18011
17926
|
|
|
18012
|
-
IDB.dropDatabase = function (ixdbid, ifexists, cb) {
|
|
18013
|
-
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
if (!dblist.contains(ixdbid)) {
|
|
18018
|
-
if (ifexists) {
|
|
18019
|
-
if (cb) cb(0);
|
|
18020
|
-
return;
|
|
18021
|
-
} else {
|
|
18022
|
-
throw new Error(
|
|
18023
|
-
'IndexedDB: Cannot drop new database "' + ixdbid + '" because it does not exist'
|
|
18024
|
-
);
|
|
18025
|
-
}
|
|
18026
|
-
}
|
|
18027
|
-
var request2 = indexedDB.deleteDatabase(ixdbid);
|
|
18028
|
-
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
|
+
});
|
|
18029
17932
|
|
|
17933
|
+
if (found) {
|
|
17934
|
+
const request = indexedDB.deleteDatabase(ixdbid);
|
|
17935
|
+
request.onsuccess = () => {
|
|
18030
17936
|
if (cb) cb(1);
|
|
18031
17937
|
};
|
|
18032
|
-
}
|
|
18033
|
-
|
|
18034
|
-
|
|
18035
|
-
|
|
18036
|
-
|
|
18037
|
-
|
|
18038
|
-
|
|
18039
|
-
|
|
18040
|
-
|
|
18041
|
-
request1.onsuccess = function (event) {
|
|
18042
|
-
var dblist = event.target.result;
|
|
18043
|
-
if (!dblist.contains(ixdbid)) {
|
|
18044
|
-
throw new Error(
|
|
18045
|
-
'IndexedDB: Cannot attach database "' + ixdbid + '" because it does not exist'
|
|
18046
|
-
);
|
|
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
|
+
);
|
|
18047
17947
|
}
|
|
18048
|
-
|
|
18049
|
-
request2.onsuccess = function (event) {
|
|
18050
|
-
var ixdb = event.target.result;
|
|
18051
|
-
var db = new alasql.Database(dbid || ixdbid);
|
|
18052
|
-
db.engineid = 'INDEXEDDB';
|
|
18053
|
-
db.ixdbid = ixdbid;
|
|
18054
|
-
db.tables = [];
|
|
18055
|
-
var tblist = ixdb.objectStoreNames;
|
|
18056
|
-
for (var i = 0; i < tblist.length; i++) {
|
|
18057
|
-
db.tables[tblist[i]] = {};
|
|
18058
|
-
}
|
|
18059
|
-
|
|
18060
|
-
event.target.result.close();
|
|
18061
|
-
if (cb) cb(1);
|
|
18062
|
-
};
|
|
18063
|
-
};
|
|
17948
|
+
}
|
|
18064
17949
|
};
|
|
18065
17950
|
|
|
18066
|
-
IDB.
|
|
18067
|
-
|
|
18068
|
-
|
|
18069
|
-
|
|
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
|
+
});
|
|
18070
17956
|
|
|
18071
|
-
|
|
18072
|
-
|
|
18073
|
-
|
|
18074
|
-
|
|
18075
|
-
|
|
18076
|
-
|
|
18077
|
-
|
|
18078
|
-
}
|
|
18079
|
-
var request2 = indexedDB.open(ixdbid);
|
|
18080
|
-
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
|
+
}
|
|
18081
17964
|
|
|
18082
|
-
|
|
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();
|
|
18083
17970
|
};
|
|
18084
|
-
|
|
18085
|
-
var version = event_.target.result.version;
|
|
18086
|
-
event_.target.result.close();
|
|
17971
|
+
});
|
|
18087
17972
|
|
|
18088
|
-
|
|
18089
|
-
|
|
18090
|
-
|
|
17973
|
+
const db = new alasql.Database(dbid || ixdbid);
|
|
17974
|
+
db.engineid = 'INDEXEDDB';
|
|
17975
|
+
db.ixdbid = ixdbid;
|
|
17976
|
+
db.tables = [];
|
|
18091
17977
|
|
|
18092
|
-
|
|
17978
|
+
for (var i = 0; i < stores.length; i++) {
|
|
17979
|
+
db.tables[stores[i]] = {};
|
|
17980
|
+
}
|
|
18093
17981
|
|
|
18094
|
-
|
|
18095
|
-
|
|
17982
|
+
if (cb) cb(1);
|
|
17983
|
+
};
|
|
18096
17984
|
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
|
|
18100
|
-
|
|
18101
|
-
|
|
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
|
+
});
|
|
18102
17991
|
|
|
18103
|
-
|
|
18104
|
-
|
|
18105
|
-
|
|
18106
|
-
|
|
18107
|
-
|
|
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
|
+
}
|
|
18108
17999
|
|
|
18109
|
-
|
|
18110
|
-
|
|
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
|
+
);
|
|
18111
18016
|
};
|
|
18112
18017
|
};
|
|
18113
18018
|
|
|
18114
|
-
IDB.dropTable = function (databaseid, tableid, ifexists, cb) {
|
|
18115
|
-
|
|
18116
|
-
|
|
18117
|
-
|
|
18118
|
-
|
|
18119
|
-
|
|
18120
|
-
var dblist = event.target.result;
|
|
18121
|
-
|
|
18122
|
-
if (!dblist.contains(ixdbid)) {
|
|
18123
|
-
throw new Error(
|
|
18124
|
-
'IndexedDB: Cannot drop table in database "' + ixdbid + '" because it does not exist'
|
|
18125
|
-
);
|
|
18126
|
-
}
|
|
18127
|
-
|
|
18128
|
-
var request2 = indexedDB.open(ixdbid);
|
|
18129
|
-
request2.onversionchange = function (event) {
|
|
18130
|
-
event.target.result.close();
|
|
18131
|
-
};
|
|
18132
|
-
|
|
18133
|
-
request2.onsuccess = function (event) {
|
|
18134
|
-
var version = event.target.result.version;
|
|
18135
|
-
event.target.result.close();
|
|
18136
|
-
|
|
18137
|
-
var request3 = indexedDB.open(ixdbid, version + 1);
|
|
18138
|
-
request3.onupgradeneeded = function (event) {
|
|
18139
|
-
var ixdb = event.target.result;
|
|
18140
|
-
if (ixdb.objectStoreNames.contains(tableid)) {
|
|
18141
|
-
ixdb.deleteObjectStore(tableid);
|
|
18142
|
-
delete alasql.databases[databaseid].tables[tableid];
|
|
18143
|
-
} else {
|
|
18144
|
-
if (!ifexists) {
|
|
18145
|
-
throw new Error(
|
|
18146
|
-
'IndexedDB: Cannot drop table "' + tableid + '" because it does not exist'
|
|
18147
|
-
);
|
|
18148
|
-
}
|
|
18149
|
-
}
|
|
18150
|
-
// var store = ixdb.createObjectStore(tableid);
|
|
18151
|
-
|
|
18152
|
-
};
|
|
18153
|
-
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
|
+
});
|
|
18154
18025
|
|
|
18155
|
-
|
|
18156
|
-
|
|
18157
|
-
|
|
18158
|
-
|
|
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
|
+
}
|
|
18159
18033
|
|
|
18160
|
-
|
|
18161
|
-
};
|
|
18162
|
-
request3.onblocked = function (event) {
|
|
18163
|
-
throw new Error(
|
|
18164
|
-
'Cannot drop table "' + tableid + '" because database "' + databaseid + '" is blocked'
|
|
18165
|
-
);
|
|
18034
|
+
const request = indexedDB.open(ixdbid, found.version + 1);
|
|
18166
18035
|
|
|
18167
|
-
|
|
18168
|
-
|
|
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
|
+
);
|
|
18169
18061
|
};
|
|
18170
18062
|
};
|
|
18171
18063
|
|
|
18172
18064
|
IDB.intoTable = function (databaseid, tableid, value, columns, cb) {
|
|
18065
|
+
const ixdbid = alasql.databases[databaseid].ixdbid;
|
|
18066
|
+
const request = indexedDB.open(ixdbid);
|
|
18173
18067
|
|
|
18174
|
-
|
|
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
|
+
};
|
|
18175
18075
|
|
|
18176
|
-
|
|
18177
|
-
|
|
18178
|
-
var request1 = indexedDB.open(ixdbid);
|
|
18179
|
-
request1.onsuccess = function (event) {
|
|
18180
|
-
var ixdb = event.target.result;
|
|
18076
|
+
request.onsuccess = () => {
|
|
18077
|
+
var ixdb = request.result;
|
|
18181
18078
|
var tx = ixdb.transaction([tableid], 'readwrite');
|
|
18182
18079
|
var tb = tx.objectStore(tableid);
|
|
18183
|
-
|
|
18184
18080
|
for (var i = 0, ilen = value.length; i < ilen; i++) {
|
|
18185
18081
|
tb.add(value[i]);
|
|
18186
18082
|
}
|
|
18187
18083
|
tx.oncomplete = function () {
|
|
18188
18084
|
ixdb.close();
|
|
18189
|
-
|
|
18190
18085
|
if (cb) cb(ilen);
|
|
18191
18086
|
};
|
|
18192
18087
|
};
|
|
18193
|
-
|
|
18194
18088
|
};
|
|
18195
18089
|
|
|
18196
18090
|
IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
|
|
18091
|
+
const ixdbid = alasql.databases[databaseid].ixdbid;
|
|
18092
|
+
const request = indexedDB.open(ixdbid);
|
|
18197
18093
|
|
|
18198
|
-
|
|
18199
|
-
|
|
18200
|
-
|
|
18201
|
-
|
|
18202
|
-
|
|
18203
|
-
|
|
18204
|
-
|
|
18205
|
-
|
|
18206
|
-
var tx = ixdb.transaction([tableid]);
|
|
18207
|
-
var store = tx.objectStore(tableid);
|
|
18208
|
-
var cur = store.openCursor();
|
|
18209
|
-
|
|
18210
|
-
cur.onblocked = function (event) {
|
|
18211
|
-
|
|
18212
|
-
};
|
|
18213
|
-
cur.onerror = function (event) {
|
|
18214
|
-
|
|
18215
|
-
};
|
|
18216
|
-
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
|
+
};
|
|
18217
18101
|
|
|
18218
|
-
|
|
18102
|
+
request.onsuccess = () => {
|
|
18103
|
+
const res = [];
|
|
18104
|
+
const ixdb = request.result;
|
|
18105
|
+
const cur = ixdb.transaction([tableid]).objectStore(tableid).openCursor();
|
|
18219
18106
|
|
|
18107
|
+
cur.onsuccess = () => {
|
|
18108
|
+
const cursor = cur.result;
|
|
18220
18109
|
if (cursor) {
|
|
18221
18110
|
res.push(cursor.value);
|
|
18222
18111
|
cursor.continue();
|
|
18223
18112
|
} else {
|
|
18224
|
-
|
|
18225
18113
|
ixdb.close();
|
|
18226
18114
|
if (cb) cb(res, idx, query);
|
|
18227
18115
|
}
|
|
@@ -18230,39 +18118,23 @@ IDB.fromTable = function (databaseid, tableid, cb, idx, query) {
|
|
|
18230
18118
|
};
|
|
18231
18119
|
|
|
18232
18120
|
IDB.deleteFromTable = function (databaseid, tableid, wherefn, params, cb) {
|
|
18121
|
+
const ixdbid = alasql.databases[databaseid].ixdbid;
|
|
18122
|
+
const request = indexedDB.open(ixdbid);
|
|
18233
18123
|
|
|
18234
|
-
|
|
18235
|
-
|
|
18236
|
-
|
|
18237
|
-
var request = indexedDB.open(ixdbid);
|
|
18238
|
-
request.onsuccess = function (event) {
|
|
18239
|
-
var res = [];
|
|
18240
|
-
var ixdb = event.target.result;
|
|
18241
|
-
|
|
18242
|
-
var tx = ixdb.transaction([tableid], 'readwrite');
|
|
18243
|
-
var store = tx.objectStore(tableid);
|
|
18244
|
-
var cur = store.openCursor();
|
|
18245
|
-
var num = 0;
|
|
18246
|
-
|
|
18247
|
-
cur.onblocked = function (event) {
|
|
18248
|
-
|
|
18249
|
-
};
|
|
18250
|
-
cur.onerror = function (event) {
|
|
18251
|
-
|
|
18252
|
-
};
|
|
18253
|
-
cur.onsuccess = function (event) {
|
|
18254
|
-
|
|
18255
|
-
var cursor = event.target.result;
|
|
18124
|
+
request.onsuccess = () => {
|
|
18125
|
+
const ixdb = request.result;
|
|
18126
|
+
const cur = ixdb.transaction([tableid], 'readwrite').objectStore(tableid).openCursor();
|
|
18256
18127
|
|
|
18128
|
+
let num = 0;
|
|
18129
|
+
cur.onsuccess = () => {
|
|
18130
|
+
var cursor = cur.result;
|
|
18257
18131
|
if (cursor) {
|
|
18258
|
-
if (!wherefn || wherefn(cursor.value, params)) {
|
|
18259
|
-
|
|
18132
|
+
if (!wherefn || wherefn(cursor.value, params, alasql)) {
|
|
18260
18133
|
cursor.delete();
|
|
18261
18134
|
num++;
|
|
18262
18135
|
}
|
|
18263
18136
|
cursor.continue();
|
|
18264
18137
|
} else {
|
|
18265
|
-
|
|
18266
18138
|
ixdb.close();
|
|
18267
18139
|
if (cb) cb(num);
|
|
18268
18140
|
}
|
|
@@ -18271,42 +18143,24 @@ IDB.deleteFromTable = function (databaseid, tableid, wherefn, params, cb) {
|
|
|
18271
18143
|
};
|
|
18272
18144
|
|
|
18273
18145
|
IDB.updateTable = function (databaseid, tableid, assignfn, wherefn, params, cb) {
|
|
18274
|
-
|
|
18275
|
-
|
|
18276
|
-
|
|
18277
|
-
|
|
18278
|
-
|
|
18279
|
-
|
|
18280
|
-
|
|
18281
|
-
|
|
18282
|
-
|
|
18283
|
-
var tx = ixdb.transaction([tableid], 'readwrite');
|
|
18284
|
-
var store = tx.objectStore(tableid);
|
|
18285
|
-
var cur = store.openCursor();
|
|
18286
|
-
var num = 0;
|
|
18287
|
-
|
|
18288
|
-
cur.onblocked = function (event) {
|
|
18289
|
-
|
|
18290
|
-
};
|
|
18291
|
-
cur.onerror = function (event) {
|
|
18292
|
-
|
|
18293
|
-
};
|
|
18294
|
-
cur.onsuccess = function (event) {
|
|
18295
|
-
|
|
18296
|
-
var cursor = event.target.result;
|
|
18297
|
-
|
|
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;
|
|
18298
18155
|
if (cursor) {
|
|
18299
18156
|
if (!wherefn || wherefn(cursor.value, params)) {
|
|
18300
|
-
|
|
18301
18157
|
var r = cursor.value;
|
|
18302
18158
|
assignfn(r, params);
|
|
18303
|
-
|
|
18304
18159
|
cursor.update(r);
|
|
18305
18160
|
num++;
|
|
18306
18161
|
}
|
|
18307
18162
|
cursor.continue();
|
|
18308
18163
|
} else {
|
|
18309
|
-
|
|
18310
18164
|
ixdb.close();
|
|
18311
18165
|
if (cb) cb(num);
|
|
18312
18166
|
}
|