-
Notifications
You must be signed in to change notification settings - Fork 664
Async
Mathias Rangel Wulff edited this page Feb 29, 2016
·
15 revisions
Using alasql will normally be sync
var result = alasql(sql [, params])
However, AlaSQL will always run async in the following cases.
- If using AlaSQL as a WebWorker
- All operations involving IndexedDB
- INTO-functions (for example
SELECT * INTO CSV(...)
) - FROM-functions (for example
SELECT * FROM CSV(...)
)
We strongly recommend using the promise notation:
alasql.promise(sql [, params])
.then(function(data){
console.log(data);
}).catch(function(err){
console.log('Error:', err);
});
If you feel very confident that you do not need to handle errors you can run async by add a 3rd parameter to alasql with a callback function:
alasql(sql, params, function(data) {
// do something with data
});
Note that if you have no params the value must be set to []
Example:
var resSync = alasql('SELECT * FROM CSV("mydata.csv")',[],function(data){
console.log(data);
});
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo