Skip to content

A JavaScript (Node.js) library for communicating with Db2 for IBM i, with support for queries, procedures, and much more. Uses traditional callback-style syntax

License

Notifications You must be signed in to change notification settings

RudraRudra123/nodejs-idb-connector

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js iDB Connector

The Node.js iDB Connector is a Node.js DB2 driver open source project from IBM.

NPM

Installation

    npm i idb-connector

Then you can require in your code, as shown below.

    const db = require('idb-connector');

Quick Example

Example 1: Fetching data using the exec() API

    const {dbconn, dbstmt} = require('idb-connector');
    const sSql = 'SELECT STATE FROM QIWS.QCUSTCDT';
    const connection = new dbconn();
    connection.conn("*LOCAL");
    const statement = new dbstmt(connection);

    statement.exec(sSql, (x) => {
      console.log("%s", JSON.stringify(x));
      statement.close();
      connection.disconn();
      connection.close();
    });

Example 2: Fetching data using the fetchAll() API

    const {dbconn, dbstmt} = require('idb-connector');
    const sSql = 'SELECT STATE FROM QIWS.QCUSTCDT';
    const connection = new dbconn();
    connection.conn("*LOCAL");
    const statement = new dbstmt(connection);

    statement.prepare(sSql, () => {
      statement.execute(() => {
        statement.fetchAll((x) => { 
          console.log("%s", JSON.stringify(x));
          statement.close();
        });
      });
    });

Example 3: Call stored procedures

    const idb = require('idb-connector'),
      {dbconn, dbstmt, IN, OUT, CHAR, CLOB} = idb;
    const sql = "CALL QXMLSERV.iPLUG512K(?,?,?,?)";
    const connection = new dbconn();
    connection.conn("*LOCAL");
    const statement = new dbstmt(connection);

    const ipc = "*NA";
    const ctl = "*here";
    const xmlIn = "<xmlservice><sh>system 'wrksbs'</sh></xmlservice>";
    const xmlOut = "";
    
    statement.prepare(sql, () => {
      statement.bindParam([
        [ipc, IN, CHAR],
        [ctl, IN, CHAR],
        [xmlIn, IN, CLOB],
        [xmlOut, OUT, CLOB]
      ], () => {
        statement.execute((out) => { // 'out' is an array of output params
          for(let i = 0; i < out.length; i++)
            console.log(out[i]);
          statement.close();
          connection.disconn();
          connection.close();
        });
      });
    });

API Reference

DB2 for i Access APIs

Change Log

View CHANGELOG.md file.

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@github.com:IBM/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.

About

A JavaScript (Node.js) library for communicating with Db2 for IBM i, with support for queries, procedures, and much more. Uses traditional callback-style syntax

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • C++ 52.2%
  • JavaScript 47.4%
  • Python 0.4%