alasql: Promise not working in browser
The method .promise
on the alasql object is not present when running in a browser.
Recreate: make a .html
document with the following content:
<script src="http://cdn.jsdelivr.net/alasql/0.2/alasql.min.js"></script>
<script>
alasql.promise('SELECT 123 as abc ')
.then(function(res){
console.log('all OK');
}).catch(function(err){
console.log('not good');
});
</script>
this gives an Uncaught TypeError: undefined is not a function
on the line with alasql.promise('SELECT 123 as abc ')
. I have tried to include the promise polyfill from https://github.com/taylorhakes/promise-polyfill/blob/master/Promise.min.js but it did not solve the issue.
The same code gives an all OK
in node:
alasql = require('alasql');
alasql.promise('SELECT 123 as abc ')
.then(function(res){
console.log('all OK');
}).catch(function(err){
console.log('not good');
});
// all OK
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 18 (10 by maintainers)
I included the following fragment before the promise call and it worked. Thanks:
if(typeof Promise === ‘function’) { alasql.promise = function(sql, params) { return new Promise(function(resolve, reject){ alasql(sql, params, function(data,err) { if(err) { reject(err); } else { resolve(data); } }); }); }; }
Alonso M.
On Mon, Jul 25, 2016 at 4:21 PM -0500, “Mathias Rangel Wulff” <notifications@github.commailto:notifications@github.com> wrote:
Questions:
You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/agershun/alasql/issues/426#issuecomment-235089282, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATrcmGvzQGByhCUh3EYxAF1zoMMGHwe-ks5qZSjbgaJpZM4GC9Bk.
Yes. [edit] Just downloaded AlaSQL v0.2.4-develop-1241 just to make sure i’m using the latest version. And it works.