I'm trying to connect monetdbto node.js. I have a simple (20-line) c program that can query moentdbusing mapi libraries.
Can I use these libraries to build something (module / addon) for node.jswhich uses these libraries and connects to monetdb?
(Using odbc is an option, but has its drawbacks.)
Update1 : node -ffi is pretty cool. I was able to easily create an extraction table program. (For example, I added my working code.)
So, if I have 3 options
1. ODBC
2. node -ffi
3. C program to extract database data and listen for connection from node.js via socket
As for performance, which is the best implementation option, if I have little time to develop an 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: The
above code is not recommended for use in production ... it does not use the node.js asynchronous functions, so please use it for the child step