Code Monkey home page Code Monkey logo

nodejs-idb-connector-2's Introduction

Node.js iDB Connector for IBM i

The Node.js iDB Connector is an IBM i Node.js Db2 driver open source project from IBM

NPM

Node-API v3 Badge

Installation

    npm i idb-connector

NOTE This package only installs on IBM i systems.

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(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(`Result is : ${JSON.stringify(x)}`);
          statement.close();
        });
      });
    });

Example 3: Call stored procedures

    const {dbconn, dbstmt} = require('idb-connector');

    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.bindParameters([ipc, ctl, xmlIn, xmlOut], () => {
        statement.execute((out) => {
          for (let i = 0; i < out.length; i += 1) {
            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 [email protected]:IBM/nodejs-idb-connector.git
    cd nodejs-idb-connector
    npm install --build-from-source

Build Dependencies

Note: sqlcli header files, GCC, and Python are required to compile the code.

    yum install sqlcli-devel
    yum group install 'Development tools' 
    yum install python2

Release

   git clone [email protected]:IBM/nodejs-idb-connector.git
   cd nodejs-idb-connector
   npm install
   ./node_modules/.bin/node-pre-gyp rebuild --production
   ./node_modules/.bin/node-pre-gyp package

Create a new github release and attach the generated tar file in the build directory to the github release.

After the release is created the publish action will automatically publish to npm.

License

MIT

Contributing

Please read the contribution guidelines.

nodejs-idb-connector-2's People

Contributors

dmabupt avatar abmusse avatar kadler avatar aaronbartell avatar markdirish avatar dependabot[bot] avatar jasonclake avatar kant avatar sgrezza avatar staplwaldo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.