alasql 2.0.7 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alasql-echo.js~7d0ef547 (Added test for OUTER JOIN with missing ids) +18 -0
- package/dist/alasql-prolog.js~7d0ef547 (Added test for OUTER JOIN with missing ids) +40 -0
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql-worker.js~7d0ef547 (Added test for OUTER JOIN with missing ids) +245 -0
- package/dist/alasql-worker.min.js +1 -1
- package/dist/alasql-worker.min.js~7d0ef547 (Added test for OUTER JOIN with missing ids) +2 -0
- package/dist/alasql.d.ts~7d0ef547 (Added test for OUTER JOIN with missing ids) +84 -0
- package/dist/alasql.fs.js +62 -26
- package/dist/alasql.fs.js~7d0ef547 (Added test for OUTER JOIN with missing ids) +19776 -0
- package/dist/alasql.js +62 -26
- package/dist/alasql.js~7d0ef547 (Added test for OUTER JOIN with missing ids) +19771 -0
- package/dist/alasql.min.js +2 -2
- package/dist/alasql.min.js~7d0ef547 (Added test for OUTER JOIN with missing ids) +16 -0
- package/package.json +1 -1
- package/yarn-error.log +0 -4440
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Plugin sample
|
|
2
|
+
|
|
3
|
+
var yy = alasql.yy;
|
|
4
|
+
|
|
5
|
+
yy.Echo = function (params) { return yy.extend(this, params); }
|
|
6
|
+
yy.Echo.prototype.toString = function() {
|
|
7
|
+
var s = 'TEST '+this.expr.toString();
|
|
8
|
+
return s;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
yy.Echo.prototype.execute = function (databaseid, params, cb) {
|
|
12
|
+
// var self = this;
|
|
13
|
+
// console.log(76336,this.expr.toJS());
|
|
14
|
+
var fn = new Function('params, alasql','return '+this.expr.toJS());
|
|
15
|
+
var res = fn(params, alasql);
|
|
16
|
+
if(cb) res = cb(res);
|
|
17
|
+
return res;
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Prolog plugin
|
|
2
|
+
|
|
3
|
+
var yy = alasql.yy;
|
|
4
|
+
|
|
5
|
+
yy.Term = function (params) { return yy.extend(this, params); }
|
|
6
|
+
yy.Term.prototype.toString = function() {
|
|
7
|
+
var s = this.termid;
|
|
8
|
+
if(this.args && this.args.length > 0) {
|
|
9
|
+
s += '('+this.args.map(function(arg){
|
|
10
|
+
return arg.toString();
|
|
11
|
+
})+')';
|
|
12
|
+
}
|
|
13
|
+
return s;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
yy.AddRule = function (params) { return yy.extend(this, params); }
|
|
17
|
+
yy.AddRule.prototype.toString = function() {
|
|
18
|
+
var s = '';
|
|
19
|
+
if(this.left) s += this.left.toString();
|
|
20
|
+
s += ':-';
|
|
21
|
+
s += this.right.map(function(r){return r.toString()}).join(',');
|
|
22
|
+
return s;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
yy.AddRule.prototype.execute = function (databaseid, params, cb) {
|
|
26
|
+
// var self = this;
|
|
27
|
+
// console.log(this.expr.toJS());
|
|
28
|
+
// var fn = new Function('params, alasql','return '+this.expr.toJS());
|
|
29
|
+
// var res = fn(params, alasql);
|
|
30
|
+
var res = 1;
|
|
31
|
+
var objects = alasql.databases[databaseid].objects;
|
|
32
|
+
var rule = {};
|
|
33
|
+
if(!this.left) {
|
|
34
|
+
this.right.forEach(function(term){
|
|
35
|
+
rule.$class = term.termid;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if(cb) res = cb(res);
|
|
39
|
+
return res;
|
|
40
|
+
};
|
package/dist/alasql-worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.0
|
|
1
|
+
//! AlaSQL v2.1.0-develop-2f9d1182undefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.0
|
|
4
|
+
@version 2.1.0-develop-2f9d1182undefined
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
//! AlaSQL v0.4.11-develop-977878caundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
|
+
/*
|
|
3
|
+
@module alasql
|
|
4
|
+
@version 0.4.11-develop-977878caundefined
|
|
5
|
+
|
|
6
|
+
AlaSQL - JavaScript SQL database
|
|
7
|
+
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
8
|
+
|
|
9
|
+
@license
|
|
10
|
+
The MIT License (MIT)
|
|
11
|
+
|
|
12
|
+
Copyright 2014-2016 Andrey Gershun (agershun@gmail.com) & Mathias Rangel Wulff (m@rawu.dk)
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
//
|
|
35
|
+
// AlaSQL Workker
|
|
36
|
+
// Date: 13.04.2014
|
|
37
|
+
// (c) 2014-2015, Andrey Gershun
|
|
38
|
+
//
|
|
39
|
+
*/
|
|
40
|
+
(function (root, factory) {
|
|
41
|
+
if (typeof define === 'function' && define.amd) {
|
|
42
|
+
define([], factory);
|
|
43
|
+
} else if (typeof exports === 'object') {
|
|
44
|
+
module.exports = factory();
|
|
45
|
+
} else {
|
|
46
|
+
root.alasql = factory();
|
|
47
|
+
}
|
|
48
|
+
}(this, function () {
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
Main procedure for worker
|
|
52
|
+
@function
|
|
53
|
+
@param {string} sql SQL statement
|
|
54
|
+
@param {object} params List of parameters (can be omitted)
|
|
55
|
+
@param {callback} cb Callback function
|
|
56
|
+
@return {object} Query result
|
|
57
|
+
*/
|
|
58
|
+
function alasql(sql,params,cb){
|
|
59
|
+
|
|
60
|
+
params = params||[];
|
|
61
|
+
|
|
62
|
+
// Avoid setting params if not needed even with callback
|
|
63
|
+
if(typeof params === 'function'){
|
|
64
|
+
scope = cb;
|
|
65
|
+
cb = params;
|
|
66
|
+
params = [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if(typeof params !== 'object'){
|
|
70
|
+
params = [params];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Increase last request id
|
|
74
|
+
var id = alasql.lastid++;
|
|
75
|
+
// Save callback
|
|
76
|
+
alasql.buffer[id] = cb;
|
|
77
|
+
// Send a message to worker
|
|
78
|
+
alasql.webworker.postMessage({id:id,sql:sql,params:params});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
alasql.options = {};
|
|
83
|
+
alasql.options.progress = function(){};
|
|
84
|
+
|
|
85
|
+
isArray = function(obj){
|
|
86
|
+
return "[object Array]"===Object.prototype.toString.call(obj);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
alasql.promise = function() {
|
|
90
|
+
throw new Error('Please include a Promise/A+ library');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// From src/18promise.js
|
|
94
|
+
if(typeof Promise !== "undefined"){
|
|
95
|
+
var promiseExec = function(sql, params, counterStep, counterTotal){
|
|
96
|
+
return new Promise(function(resolve, reject){
|
|
97
|
+
alasql(sql, params, function(data,err) {
|
|
98
|
+
if(err) {
|
|
99
|
+
reject(err);
|
|
100
|
+
} else {
|
|
101
|
+
if (counterStep && counterTotal && alasql.options.progress !== false) {
|
|
102
|
+
alasql.options.progress(counterStep, counterTotal);
|
|
103
|
+
}
|
|
104
|
+
resolve(data);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var promiseAll = function(sqlParamsArray){
|
|
111
|
+
if(sqlParamsArray.length<1){
|
|
112
|
+
return ;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
var active, sql, params;
|
|
116
|
+
|
|
117
|
+
var execArray = [];
|
|
118
|
+
|
|
119
|
+
for (var i = 0; i < sqlParamsArray.length; i++) {
|
|
120
|
+
active = sqlParamsArray[i];
|
|
121
|
+
|
|
122
|
+
if(typeof active === 'string'){
|
|
123
|
+
active = [active];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if(!isArray(active) || active.length<1 || 2<active.length){
|
|
127
|
+
throw new Error('Error in .promise parameter');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
sql = active[0];
|
|
131
|
+
params = active[1]||undefined;
|
|
132
|
+
|
|
133
|
+
execArray.push(promiseExec(sql, params, i, sqlParamsArray.length));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return Promise.all(execArray);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
alasql.promise = function(sql, params) {
|
|
140
|
+
if(typeof Promise === "undefined"){
|
|
141
|
+
throw new Error('Please include a Promise/A+ library');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if(typeof sql === 'string'){
|
|
145
|
+
return promiseExec(sql, params);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if(!isArray(sql) || sql.length<1 || typeof params !== "undefined"){
|
|
149
|
+
throw new Error('Error in .promise parameters');
|
|
150
|
+
}
|
|
151
|
+
return promiseAll(sql);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
alasql = alasql || false;
|
|
158
|
+
|
|
159
|
+
if (!alasql) {
|
|
160
|
+
throw new Error('alasql was not found');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
alasql.worker = function() {
|
|
164
|
+
throw new Error('Can find webworker in this enviroment');
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
if (typeof Worker !== 'undefined') {
|
|
168
|
+
alasql.worker = function(path, paths, cb) {
|
|
169
|
+
// var path;
|
|
170
|
+
if (path === true) {
|
|
171
|
+
path = undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (typeof path === 'undefined') {
|
|
175
|
+
var sc = document.getElementsByTagName('script');
|
|
176
|
+
for (var i = 0; i < sc.length; i++) {
|
|
177
|
+
if (sc[i].src.substr(-16).toLowerCase() === 'alasql-worker.js') {
|
|
178
|
+
path = sc[i].src.substr(0, sc[i].src.length - 16) + 'alasql.js';
|
|
179
|
+
break;
|
|
180
|
+
} else if (sc[i].src.substr(-20).toLowerCase() === 'alasql-worker.min.js') {
|
|
181
|
+
path = sc[i].src.substr(0, sc[i].src.length - 20) + 'alasql.min.js';
|
|
182
|
+
break;
|
|
183
|
+
} else if (sc[i].src.substr(-9).toLowerCase() === 'alasql.js') {
|
|
184
|
+
path = sc[i].src;
|
|
185
|
+
break;
|
|
186
|
+
} else if (sc[i].src.substr(-13).toLowerCase() === 'alasql.min.js') {
|
|
187
|
+
path = sc[i].src.substr(0, sc[i].src.length - 13) + 'alasql.min.js';
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (typeof path === 'undefined') {
|
|
194
|
+
throw new Error('Path to alasql.js is not specified');
|
|
195
|
+
} else if (path !== false) {
|
|
196
|
+
var js = "importScripts('";
|
|
197
|
+
js += path;
|
|
198
|
+
js +=
|
|
199
|
+
"');self.onmessage = function(event) {" +
|
|
200
|
+
'alasql(event.data.sql,event.data.params, function(data){' +
|
|
201
|
+
'postMessage({id:event.data.id, data:data});});}';
|
|
202
|
+
|
|
203
|
+
var blob = new Blob([js], {type: 'text/plain'});
|
|
204
|
+
alasql.webworker = new Worker(URL.createObjectURL(blob));
|
|
205
|
+
|
|
206
|
+
alasql.webworker.onmessage = function(event) {
|
|
207
|
+
var id = event.data.id;
|
|
208
|
+
|
|
209
|
+
alasql.buffer[id](event.data.data);
|
|
210
|
+
delete alasql.buffer[id];
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
alasql.webworker.onerror = function(e) {
|
|
214
|
+
throw e;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
if (arguments.length > 1) {
|
|
218
|
+
var sql =
|
|
219
|
+
'REQUIRE ' +
|
|
220
|
+
paths
|
|
221
|
+
.map(function(p) {
|
|
222
|
+
return '"' + p + '"';
|
|
223
|
+
})
|
|
224
|
+
.join(',');
|
|
225
|
+
alasql(sql, [], cb);
|
|
226
|
+
}
|
|
227
|
+
} else if (path === false) {
|
|
228
|
+
delete alasql.webworker;
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
/* WebWorker */
|
|
236
|
+
/** @type {number} */
|
|
237
|
+
alasql.lastid = 0;
|
|
238
|
+
|
|
239
|
+
/** @type {object} */
|
|
240
|
+
alasql.buffer = {};
|
|
241
|
+
|
|
242
|
+
alasql.worker();
|
|
243
|
+
|
|
244
|
+
return alasql;
|
|
245
|
+
}));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
//! AlaSQL v2.0
|
|
1
|
+
//! AlaSQL v2.1.0-develop-2f9d1182undefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
2
|
!function(r,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():r.alasql=e()}(this,function(){function i(r,e,o){"function"==typeof(e=e||[])&&(scope=o,o=e,e=[]),"object"!=typeof e&&(e=[e]);var t=i.lastid++;i.buffer[t]=o,i.webworker.postMessage({id:t,sql:r,params:e})}var a;if(i.options={},i.options.progress=function(){},isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)},i.promise=function(){throw new Error("Please include a Promise/A+ library")},"undefined"!=typeof Promise&&(a=function(r,e,n,s){return new Promise(function(o,t){i(r,e,function(r,e){e?t(e):(n&&s&&!1!==i.options.progress&&i.options.progress(n,s),o(r))})})},i.promise=function(r,e){if("undefined"==typeof Promise)throw new Error("Please include a Promise/A+ library");if("string"==typeof r)return a(r,e);if(!isArray(r)||r.length<1||void 0!==e)throw new Error("Error in .promise parameters");var o=r;if(!(o.length<1)){for(var t,n,s=[],i=0;i<o.length;i++){if("string"==typeof(n=o[i])&&(n=[n]),!isArray(n)||n.length<1||2<n.length)throw new Error("Error in .promise parameter");t=n[0],n=n[1]||void 0,s.push(a(t,n,i,o.length))}return Promise.all(s)}}),i=i||!1)return i.worker=function(){throw new Error("Can find webworker in this enviroment")},"undefined"!=typeof Worker&&(i.worker=function(r,e,o){if(void 0===(r=!0===r?void 0:r))for(var t=document.getElementsByTagName("script"),n=0;n<t.length;n++){if("alasql-worker.js"===t[n].src.substr(-16).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-16)+"alasql.js";break}if("alasql-worker.min.js"===t[n].src.substr(-20).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-20)+"alasql.min.js";break}if("alasql.js"===t[n].src.substr(-9).toLowerCase()){r=t[n].src;break}if("alasql.min.js"===t[n].src.substr(-13).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-13)+"alasql.min.js";break}}if(void 0===r)throw new Error("Path to alasql.js is not specified");var s;!1!==r?(s=(s="importScripts('")+r+"');self.onmessage = function(event) {alasql(event.data.sql,event.data.params, function(data){postMessage({id:event.data.id, data:data});});}",s=new Blob([s],{type:"text/plain"}),i.webworker=new Worker(URL.createObjectURL(s)),i.webworker.onmessage=function(r){var e=r.data.id;i.buffer[e](r.data.data),delete i.buffer[e]},i.webworker.onerror=function(r){throw r},1<arguments.length&&i("REQUIRE "+e.map(function(r){return'"'+r+'"'}).join(","),[],o)):!1===r&&delete i.webworker}),i.lastid=0,i.buffer={},i.worker(),i;throw new Error("alasql was not found")});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
//! AlaSQL v0.4.11-develop-977878caundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
|
+
!function(r,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():r.alasql=e()}(this,function(){function r(e,t,o){t=t||[],"function"==typeof t&&(scope=o,o=t,t=[]),"object"!=typeof t&&(t=[t]);var n=r.lastid++;r.buffer[n]=o,r.webworker.postMessage({id:n,sql:e,params:t})}if(r.options={},r.options.progress=function(){},isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)},r.promise=function(){throw new Error("Please include a Promise/A+ library")},"undefined"!=typeof Promise){var e=function(e,t,o,n){return new Promise(function(s,i){r(e,t,function(e,t){t?i(t):(o&&n&&!1!==r.options.progress&&r.options.progress(o,n),s(e))})})},t=function(r){if(!(r.length<1)){for(var t,o,n,s=[],i=0;i<r.length;i++){if(t=r[i],"string"==typeof t&&(t=[t]),!isArray(t)||t.length<1||2<t.length)throw new Error("Error in .promise parameter");o=t[0],n=t[1]||void 0,s.push(e(o,n,i,r.length))}return Promise.all(s)}};r.promise=function(r,o){if("undefined"==typeof Promise)throw new Error("Please include a Promise/A+ library");if("string"==typeof r)return e(r,o);if(!isArray(r)||r.length<1||void 0!==o)throw new Error("Error in .promise parameters");return t(r)}}if(!(r=r||!1))throw new Error("alasql was not found");return r.worker=function(){throw new Error("Can find webworker in this enviroment")},"undefined"!=typeof Worker&&(r.worker=function(e,t,o){if(!0===e&&(e=void 0),void 0===e)for(var n=document.getElementsByTagName("script"),s=0;s<n.length;s++){if("alasql-worker.js"===n[s].src.substr(-16).toLowerCase()){e=n[s].src.substr(0,n[s].src.length-16)+"alasql.js";break}if("alasql-worker.min.js"===n[s].src.substr(-20).toLowerCase()){e=n[s].src.substr(0,n[s].src.length-20)+"alasql.min.js";break}if("alasql.js"===n[s].src.substr(-9).toLowerCase()){e=n[s].src;break}if("alasql.min.js"===n[s].src.substr(-13).toLowerCase()){e=n[s].src.substr(0,n[s].src.length-13)+"alasql.min.js";break}}if(void 0===e)throw new Error("Path to alasql.js is not specified");if(!1!==e){var i="importScripts('";i+=e,i+="');self.onmessage = function(event) {alasql(event.data.sql,event.data.params, function(data){postMessage({id:event.data.id, data:data});});}";var a=new Blob([i],{type:"text/plain"});if(r.webworker=new Worker(URL.createObjectURL(a)),r.webworker.onmessage=function(e){var t=e.data.id;r.buffer[t](e.data.data),delete r.buffer[t]},r.webworker.onerror=function(r){throw r},arguments.length>1){r("REQUIRE "+t.map(function(r){return'"'+r+'"'}).join(","),[],o)}}else if(!1===e)return void delete r.webworker}),r.lastid=0,r.buffer={},r.worker(),r});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Project: https://github.com/agershun/alasql
|
|
2
|
+
|
|
3
|
+
import * as xlsx from "xlsx";
|
|
4
|
+
|
|
5
|
+
declare namespace alaSQLSpace {
|
|
6
|
+
interface AlaSQLCallback {
|
|
7
|
+
(data?: any, err?: Error): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface AlaSQLOptions {
|
|
11
|
+
errorlog: boolean;
|
|
12
|
+
valueof: boolean;
|
|
13
|
+
dropifnotexists: boolean; // drop database in any case
|
|
14
|
+
datetimeformat: string; // how to handle DATE and DATETIME types
|
|
15
|
+
casesensitive: boolean; // table and column names are case sensitive and converted to lower-case
|
|
16
|
+
logtarget: string; // target for log. Values: 'console', 'output', 'id' of html tag
|
|
17
|
+
logprompt: boolean; // print SQL at log
|
|
18
|
+
modifier: any; // values: RECORDSET, VALUE, ROW, COLUMN, MATRIX, TEXTSTRING, INDEX
|
|
19
|
+
columnlookup: number; // how many rows to lookup to define columns
|
|
20
|
+
autovertex: boolean; // create vertex if not found
|
|
21
|
+
usedbo: boolean; // use dbo as current database (for partial T-SQL comaptibility)
|
|
22
|
+
autocommit: boolean; // the AUTOCOMMIT ON | OFF
|
|
23
|
+
cache: boolean; // use cache
|
|
24
|
+
nocount: boolean; // for SET NOCOUNT OFF
|
|
25
|
+
nan: boolean; // check for NaN and convert it to undefined
|
|
26
|
+
angularjs: boolean;
|
|
27
|
+
tsql: boolean;
|
|
28
|
+
mysql: boolean;
|
|
29
|
+
postgres: boolean;
|
|
30
|
+
oracle: boolean;
|
|
31
|
+
sqlite: boolean;
|
|
32
|
+
orientdb: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// compiled Statement
|
|
36
|
+
interface AlaSQLStatement {
|
|
37
|
+
(params?: any, cb?: AlaSQLCallback, scope?: any): any;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// abstract Syntax Tree
|
|
41
|
+
interface AlaSQLAST {
|
|
42
|
+
compile(databaseid: string): AlaSQLStatement;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/es6-promise/es6-promise.d.ts
|
|
46
|
+
interface Thenable<T> {
|
|
47
|
+
then<U>(onFulfilled?: (value: T) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
|
|
48
|
+
then<U>(onFulfilled?: (value: T) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
|
|
49
|
+
catch<U>(onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// see https://github.com/agershun/alasql/wiki/User%20Defined%20Functions
|
|
53
|
+
interface userDefinedFunction {
|
|
54
|
+
(x: any): any;
|
|
55
|
+
}
|
|
56
|
+
interface userDefinedFunctionLookUp {
|
|
57
|
+
[x: string]: userDefinedFunction;
|
|
58
|
+
}
|
|
59
|
+
// see https://github.com/agershun/alasql/wiki/User%20Defined%20Functions
|
|
60
|
+
interface userAggregator {
|
|
61
|
+
(value: any, accumulator: any, stage: number): any;
|
|
62
|
+
}
|
|
63
|
+
interface userAggregatorLookUp {
|
|
64
|
+
[x: string]: userAggregator;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface AlaSQL {
|
|
68
|
+
options: AlaSQLOptions;
|
|
69
|
+
error: Error;
|
|
70
|
+
(sql: any, params?: any, cb?: AlaSQLCallback, scope?: any): any;
|
|
71
|
+
parse(sql: any): AlaSQLAST;
|
|
72
|
+
promise(sql: any, params?: any): Thenable<any>;
|
|
73
|
+
fn: userDefinedFunctionLookUp;
|
|
74
|
+
aggr: userAggregatorLookUp;
|
|
75
|
+
autoval(tablename: string, colname: string, getNext?:boolean): number;
|
|
76
|
+
yy:{};
|
|
77
|
+
setXLSX(xlsxlib: typeof xlsx): void;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare var alasql: alaSQLSpace.AlaSQL;
|
|
82
|
+
declare module 'alasql' {
|
|
83
|
+
export = alasql;
|
|
84
|
+
}
|
package/dist/alasql.fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.0
|
|
1
|
+
//! AlaSQL v2.1.0-develop-2f9d1182undefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.0
|
|
4
|
+
@version 2.1.0-develop-2f9d1182undefined
|
|
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.0
|
|
145
|
+
alasql.version = '2.1.0-develop-2f9d1182undefined';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
Debug flag
|
|
@@ -4114,6 +4114,15 @@ var extend = (utils.extend = function extend(a, b) {
|
|
|
4114
4114
|
return a;
|
|
4115
4115
|
});
|
|
4116
4116
|
|
|
4117
|
+
/**
|
|
4118
|
+
* Extracts the primitive data
|
|
4119
|
+
*/
|
|
4120
|
+
var getValueOf = (utils.getValueOf = function (val) {
|
|
4121
|
+
return typeof val === 'object' && (val instanceof String || val instanceof Number)
|
|
4122
|
+
? val.valueOf()
|
|
4123
|
+
: val;
|
|
4124
|
+
});
|
|
4125
|
+
|
|
4117
4126
|
/**
|
|
4118
4127
|
Flat array by first row
|
|
4119
4128
|
*/
|
|
@@ -4126,7 +4135,7 @@ var flatArray = (utils.flatArray = function (a) {
|
|
|
4126
4135
|
// For recordsets
|
|
4127
4136
|
if (typeof a === 'object' && a instanceof alasql.Recordset) {
|
|
4128
4137
|
return a.data.map(function (ai) {
|
|
4129
|
-
return ai[a.columns[0].columnid];
|
|
4138
|
+
return getValueOf(ai[a.columns[0].columnid]);
|
|
4130
4139
|
});
|
|
4131
4140
|
}
|
|
4132
4141
|
// Else for other arrays
|
|
@@ -9876,7 +9885,13 @@ yy.Select.prototype.compileOrder = function (query, params) {
|
|
|
9876
9885
|
var columnid = ord.expression.columnid;
|
|
9877
9886
|
if (query.xcolumns[columnid]) {
|
|
9878
9887
|
var dbtypeid = query.xcolumns[columnid].dbtypeid;
|
|
9879
|
-
if (
|
|
9888
|
+
if (
|
|
9889
|
+
dbtypeid == 'DATE' ||
|
|
9890
|
+
dbtypeid == 'DATETIME' ||
|
|
9891
|
+
dbtypeid == 'DATETIME2' ||
|
|
9892
|
+
dbtypeid == 'STRING' ||
|
|
9893
|
+
dbtypeid == 'NUMBER'
|
|
9894
|
+
)
|
|
9880
9895
|
dg = '.valueOf()';
|
|
9881
9896
|
// TODO Add other types mapping
|
|
9882
9897
|
} else {
|
|
@@ -9888,7 +9903,13 @@ yy.Select.prototype.compileOrder = function (query, params) {
|
|
|
9888
9903
|
var columnid = params[ord.expression.param];
|
|
9889
9904
|
if (query.xcolumns[columnid]) {
|
|
9890
9905
|
var dbtypeid = query.xcolumns[columnid].dbtypeid;
|
|
9891
|
-
if (
|
|
9906
|
+
if (
|
|
9907
|
+
dbtypeid == 'DATE' ||
|
|
9908
|
+
dbtypeid == 'DATETIME' ||
|
|
9909
|
+
dbtypeid == 'DATETIME2' ||
|
|
9910
|
+
dbtypeid == 'STRING' ||
|
|
9911
|
+
dbtypeid == 'NUMBER'
|
|
9912
|
+
)
|
|
9892
9913
|
dg = '.valueOf()';
|
|
9893
9914
|
// TODO Add other types mapping
|
|
9894
9915
|
} else {
|
|
@@ -10954,10 +10975,15 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10954
10975
|
context +
|
|
10955
10976
|
'))';
|
|
10956
10977
|
s += '.indexOf(';
|
|
10957
|
-
s += leftJS() + ')>-1)';
|
|
10978
|
+
s += 'alasql.utils.getValueOf(' + leftJS() + '))>-1)';
|
|
10958
10979
|
} else if (Array.isArray(this.right)) {
|
|
10959
10980
|
// if(this.right.length == 0) return 'false';
|
|
10960
|
-
s =
|
|
10981
|
+
s =
|
|
10982
|
+
'([' +
|
|
10983
|
+
this.right.map(ref).join(',') +
|
|
10984
|
+
'].indexOf(alasql.utils.getValueOf(' +
|
|
10985
|
+
leftJS() +
|
|
10986
|
+
'))>-1)';
|
|
10961
10987
|
|
|
10962
10988
|
} else {
|
|
10963
10989
|
s = '(' + rightJS() + '.indexOf(' + leftJS() + ')>-1)';
|
|
@@ -10974,11 +11000,11 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10974
11000
|
// s += 'alasql.utils.flatArray(this.query.queriesfn['+(this.queriesidx)+'](params,null,p))';
|
|
10975
11001
|
s += 'alasql.utils.flatArray(this.queriesfn[' + this.queriesidx + '](params,null,p))';
|
|
10976
11002
|
s += '.indexOf(';
|
|
10977
|
-
s += leftJS() + ')<0)';
|
|
11003
|
+
s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
|
|
10978
11004
|
} else if (Array.isArray(this.right)) {
|
|
10979
11005
|
// if(this.right.length == 0) return 'true';
|
|
10980
11006
|
s = '([' + this.right.map(ref).join(',') + '].indexOf(';
|
|
10981
|
-
s += leftJS() + ')<0)';
|
|
11007
|
+
s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
|
|
10982
11008
|
} else {
|
|
10983
11009
|
s = '(' + rightJS() + '.indexOf(';
|
|
10984
11010
|
s += leftJS() + ')==-1)';
|
|
@@ -12352,7 +12378,7 @@ alasql.stdfn.CONVERT = function (value, args) {
|
|
|
12352
12378
|
if (/\d{8}/.test(val)) {
|
|
12353
12379
|
t = new Date(+val.substr(0, 4), +val.substr(4, 2) - 1, +val.substr(6, 2));
|
|
12354
12380
|
} else {
|
|
12355
|
-
t =
|
|
12381
|
+
t = newDate(val);
|
|
12356
12382
|
}
|
|
12357
12383
|
switch (args.style) {
|
|
12358
12384
|
case 1: // mm/dd/yy
|
|
@@ -12523,9 +12549,9 @@ alasql.stdfn.CONVERT = function (value, args) {
|
|
|
12523
12549
|
var udbtypeid = args.dbtypeid.toUpperCase();
|
|
12524
12550
|
|
|
12525
12551
|
if (args.dbtypeid == 'Date') {
|
|
12526
|
-
return
|
|
12552
|
+
return newDate(val);
|
|
12527
12553
|
} else if (udbtypeid == 'DATE') {
|
|
12528
|
-
var d =
|
|
12554
|
+
var d = newDate(val);
|
|
12529
12555
|
var s =
|
|
12530
12556
|
d.getFullYear() +
|
|
12531
12557
|
'.' +
|
|
@@ -12534,7 +12560,7 @@ alasql.stdfn.CONVERT = function (value, args) {
|
|
|
12534
12560
|
('0' + d.getDate()).substr(-2);
|
|
12535
12561
|
return s;
|
|
12536
12562
|
} else if (udbtypeid == 'DATETIME' || udbtypeid == 'DATETIME2') {
|
|
12537
|
-
var d =
|
|
12563
|
+
var d = newDate(val);
|
|
12538
12564
|
var s =
|
|
12539
12565
|
d.getFullYear() +
|
|
12540
12566
|
'.' +
|
|
@@ -13310,7 +13336,7 @@ stdfn.OBJECT_ID = function (objid) {
|
|
|
13310
13336
|
|
|
13311
13337
|
stdfn.DATE = function (d) {
|
|
13312
13338
|
if (/\d{8}/.test(d)) return new Date(+d.substr(0, 4), +d.substr(4, 2) - 1, +d.substr(6, 2));
|
|
13313
|
-
return
|
|
13339
|
+
return newDate(d);
|
|
13314
13340
|
};
|
|
13315
13341
|
|
|
13316
13342
|
stdfn.NOW = function () {
|
|
@@ -13336,37 +13362,37 @@ stdfn.GETDATE = stdfn.NOW;
|
|
|
13336
13362
|
stdfn.CURRENT_TIMESTAMP = stdfn.NOW;
|
|
13337
13363
|
|
|
13338
13364
|
stdfn.SECOND = function (d) {
|
|
13339
|
-
var d =
|
|
13365
|
+
var d = newDate(d);
|
|
13340
13366
|
return d.getSeconds();
|
|
13341
13367
|
};
|
|
13342
13368
|
|
|
13343
13369
|
stdfn.MINUTE = function (d) {
|
|
13344
|
-
var d =
|
|
13370
|
+
var d = newDate(d);
|
|
13345
13371
|
return d.getMinutes();
|
|
13346
13372
|
};
|
|
13347
13373
|
|
|
13348
13374
|
stdfn.HOUR = function (d) {
|
|
13349
|
-
var d =
|
|
13375
|
+
var d = newDate(d);
|
|
13350
13376
|
return d.getHours();
|
|
13351
13377
|
};
|
|
13352
13378
|
|
|
13353
13379
|
stdfn.DAYOFWEEK = stdfn.WEEKDAY = function (d) {
|
|
13354
|
-
var d =
|
|
13380
|
+
var d = newDate(d);
|
|
13355
13381
|
return d.getDay();
|
|
13356
13382
|
};
|
|
13357
13383
|
|
|
13358
13384
|
stdfn.DAY = stdfn.DAYOFMONTH = function (d) {
|
|
13359
|
-
var d =
|
|
13385
|
+
var d = newDate(d);
|
|
13360
13386
|
return d.getDate();
|
|
13361
13387
|
};
|
|
13362
13388
|
|
|
13363
13389
|
stdfn.MONTH = function (d) {
|
|
13364
|
-
var d =
|
|
13390
|
+
var d = newDate(d);
|
|
13365
13391
|
return d.getMonth() + 1;
|
|
13366
13392
|
};
|
|
13367
13393
|
|
|
13368
13394
|
stdfn.YEAR = function (d) {
|
|
13369
|
-
var d =
|
|
13395
|
+
var d = newDate(d);
|
|
13370
13396
|
return d.getFullYear();
|
|
13371
13397
|
};
|
|
13372
13398
|
|
|
@@ -13386,12 +13412,12 @@ var PERIODS = {
|
|
|
13386
13412
|
};
|
|
13387
13413
|
|
|
13388
13414
|
alasql.stdfn.DATEDIFF = function (period, d1, d2) {
|
|
13389
|
-
var interval =
|
|
13415
|
+
var interval = newDate(d2).getTime() - newDate(d1).getTime();
|
|
13390
13416
|
return interval / PERIODS[period.toLowerCase()];
|
|
13391
13417
|
};
|
|
13392
13418
|
|
|
13393
13419
|
alasql.stdfn.DATEADD = function (period, interval, d) {
|
|
13394
|
-
var nd =
|
|
13420
|
+
var nd = newDate(d);
|
|
13395
13421
|
var period = period.toLowerCase();
|
|
13396
13422
|
|
|
13397
13423
|
switch (period) {
|
|
@@ -13417,15 +13443,25 @@ alasql.stdfn.INTERVAL = function (interval, period) {
|
|
|
13417
13443
|
};
|
|
13418
13444
|
|
|
13419
13445
|
alasql.stdfn.DATE_ADD = alasql.stdfn.ADDDATE = function (d, interval) {
|
|
13420
|
-
var nd =
|
|
13446
|
+
var nd = newDate(d).getTime() + interval;
|
|
13421
13447
|
return new Date(nd);
|
|
13422
13448
|
};
|
|
13423
13449
|
|
|
13424
13450
|
alasql.stdfn.DATE_SUB = alasql.stdfn.SUBDATE = function (d, interval) {
|
|
13425
|
-
var nd =
|
|
13451
|
+
var nd = newDate(d).getTime() - interval;
|
|
13426
13452
|
return new Date(nd);
|
|
13427
13453
|
};
|
|
13428
13454
|
|
|
13455
|
+
var dateRegexp = /^\d{4}\.\d{2}\.\d{2} \d{2}:\d{2}:\d{2}/;
|
|
13456
|
+
function newDate(d) {
|
|
13457
|
+
if (typeof d === 'string') {
|
|
13458
|
+
if (dateRegexp.test(d)) {
|
|
13459
|
+
d = d.replace('.', '-').replace('.', '-');
|
|
13460
|
+
}
|
|
13461
|
+
}
|
|
13462
|
+
return new Date(d);
|
|
13463
|
+
}
|
|
13464
|
+
|
|
13429
13465
|
/*
|
|
13430
13466
|
//
|
|
13431
13467
|
// DROP TABLE for Alasql.js
|