I am trying to connect monetdb
with node.js
. I have a simple (20 line) c program which can query moentdb
using mapi libraries.
Can I use those libraries to build something(module/addon) for node.js
which uses these libraries and connect to monetdb
?
(using odbc is an option but it have its own disadvantages.)
Update1 :
node-ffi is pretty awesome. I was able to create a fetch table program pretty easily. (I have added my working code for example.)
So if I have 3 options
1. ODBC
2. node-ffi
3. a c program to fetch database data and listens to connection from node.js through socket
In terms of performance which is better option to implement, if I have little less time to develop a addon for node.js
var ffi = require("ffi");
var libmylibrary = ffi.Library('/usr/local/lib/libmapi.so', {
"mapi_connect":["int",["string",'int',"string","string","string","string"]],
"mapi_query":['int',["int","string"]],
"mapi_fetch_row":["int",["int"]],
"mapi_fetch_field":["string",["int","int"]]
});
var res = libmylibrary.mapi_connect("localhost", 50000,"monetdb", "monetdb", "sql", "demo");
console.log(res);
var ret=libmylibrary.mapi_query(res,"select * from table");
while(libmylibrary.mapi_fetch_row(ret)){
console.log(libmylibrary.mapi_fetch_field(ret,0));
console.log(libmylibrary.mapi_fetch_field(ret,1));
}
Update 2:
Above code is not recommended for production use...it does not use async functionality of node.js so please use it for baby steps