Node.js iDB Connector
The Node.js iDB Connector is a Node.js DB2 driver open source project from IBM.
Installation
npm i idb-connector
Then you can require in your code, as shown below.
var db = require('idb-connector');
Quick Example
Example 1: Fectching data using the exec() API
var db = require('idb-connector');
var sSql = 'SELECT STATE FROM QIWS.QCUSTCDT';
var dbconn = new db.dbconn();
dbconn.conn("*LOCAL");
var stmt = new db.dbstmt(dbconn);
stmt.exec(sSql, (x) => {
console.log("%s", JSON.stringify(x));
stmt.close();
dbconn.disconn();
dbconn.close();
});
Example 2: Fectching data using the fetchAll() API
var db = require('idb-connector');
var sSql = 'SELECT STATE FROM QIWS.QCUSTCDT';
var dbconn = new db.dbconn();
dbconn.conn("*LOCAL");
var stmt = new db.dbstmt(dbconn);
stmt.prepare(sSql, () => {
stmt.executeSync(() => {
stmt.fetchAll((x) => {
console.log("%s", JSON.stringify(x));
stmt.close();
});
});
});
Example 3: Call stored procedures
var db = require('idb-connector');
var sql = "call QXMLSERV.iPLUG512K(?,?,?,?)";
var dbconn = new db.dbconn();
dbconn.conn("*LOCAL");
var stmt = new db.dbstmt(dbconn);
var ipc = "*NA";
var ctl = "*here";
var xmlIn = "<xmlservice><sh>system 'wrksbs'</sh></xmlservice>";
var xmlOut;
stmt.prepare(sql, () => {
stmt.bindParam([
[ipc, db.SQL_PARAM_INPUT, 1],
[ctl, db.SQL_PARAM_INPUT, 1],
[xmlIn, db.SQL_PARAM_INPUT, 0],
[xmlOut, db.SQL_PARAM_OUTPUT, 0],
], function(){
stmt.execute((out) => {
for(var i = 0; i < out.length; i++)
console.log(out[i]);
stmt.close();
dbconn.disconn();
dbconn.close();
});
});
});
API Reference
DeveloperWorks
Build
Note that building isn't necessary for end users and is more for developers looking to compile the native Node.js extensions (C code).
git clone git@bitbucket.org:litmis/nodejs-idb-connector.git
cd nodejs-idb-connector
npm install --build-from-source
Note: Gcc and python are required to compile the code.
License
MIT. View LICENSE
file.