Firstly, I have to say that alasql is a great work.
We are designing a programming platform that can do all kinds of ETL. We choose javascript+sql as base because they fit our team capability. alasql is very strong in handling memory data as well as physical file. However, we stick to a problem in bulk import/export from/to database. Actually we can do that by other CLI before or after the node script, but it is really perfect if it can be done within the script itself. Mostly, we are dealing with MySQL and MSSQL.
If there is any other JS that can convert DB table into javascript object, appreciate you could suggest one. Thanks.
The one of possible solutions is to create custom FROM function like here:
alasql.from.DB = function(dbtype, opts, cb, idx, query) {
var res = [];
async_read_data_from_mysql_function(dbtype, opts.dbname, opts.tablename, function(data) {
res = data;
if(cb){
res = cb(res, idx, query);
}
};
return null;
};
function async_read_data_from_mysql_function(dbtype, dbname, tablename, cb) {
// put your code here
cb(read_data);
}
Then you can use it like:
SELECT * FROM DB("mysql",{dbname:"one", tablename:"two"})
Also, you can save data to MYSQL with alasql.into.DB() custom function.
alasql('SELECT * INTO DB("mysql",{dbname:"one", tablename:"two"}) FROM ?',[data]);
You can see the examples of FROM and INTO functions at src/84from.js and src/830into.js files.
Perfect !!!
馃憤