Copyright 2018 OpenInformix
Licensed under the MIT
Informix native node.js driver
Informix native node.js driver is a high performance driver with asynchronous/synchronous interface suitable for highly scalable enterprise applications and lightweight enough for Internet of things (IoT) solutions working with Informix database.
The development activities of the driver are powered by passion, dedication and independent thinking. You may send pull request, together we grow as an open community; relevant discussion and queries are answered by community through Stack Overflow. http://stackoverflow.com/questions/tagged/informix
Installing the driver
npm install ifxnjs
The driver has prebuilt binaries for ARM, Linux x64 and Win64, and it is certified to work with Raspberry Pi; all other platforms you may perform a local build. The current version of Informix native node driver (ifxnjs@8.0.x) is being compiled with Node.js v8.9.4 LTS libraries. The driver is expected to work with all node.js version 8x.
FYI: Informix Client SDK 4.10 xC2 or above is needed for the driver to make connection to the database. Make sure Informix Client SDK is installed and its environments are set prior to running application.
Runtime Environment
The Informix node.js driver has dependency on Informix Client SDK version 4.10 xC2 or above. Make sure to set Informix Client SDK runtime environment before running the applications.
Say INFORMIXDIR is the location where you have installed Informix Client SDK.
Linux
export LD_LIBRARY_PATH=${INFORMIXDIR}/lib:${INFORMIXDIR}/lib/esql:${INFORMIXDIR}/lib/cli
Windows
SET PATH=%INFORMIXDIR%\bin;%PATH%
Build the driver from its source code
The driver source code is platform neutral; if needed you may build the driver on any platforms. If you face any difficulty feel free to reach out to us, we are happy to help you. The following URL has instruction to build it on Windows and Linux.
Connection String
var dbobj = ;var ConStr = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;";
Example
var dbobj = ; { try var result = conn; console; catch e console; if ErrIgn != 1 console; console; } { if err return console; ; ; ; ; ; ; ; console; // blocks until the query is completed and all data has been acquired var rows = conn; console; console;}; var { ; conn;} { console; dbobj; console;} { console; var conn; try conn = dbobj; catche console; return; ; try conn; catche console; console;} { // Make sure the port is IDS SQLI port. var ConnectionString = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;"; //Synchronous Execution ; //Asynchronous Execution ;} ;
API
Database
The simple api is based on instances of the Database
class. You may get an
instance in one of the following ways:
;
or by using the helper function:
var ibmdb = ;
or by creating an instance with the constructor function:
var Database = Database ibmdb = ;
.open(connectionString, [options,] callback)
Open a connection to a database.
- connectionString - The connection string for your database
- options - OPTIONAL - Object type. Can be used to avoid multiple
loading of native ODBC library for each call of
.open
. - callback -
callback (err, conn)
var ibmdb = ; ibmdb
.openSync(connectionString)
Synchronously open a connection to a database.
- connectionString - The connection string for your database
var ibmdb = connString = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" try var conn = ibmdb; conn; catch e console;
.query(sqlQuery [, bindingParameters], callback)
Issue an asynchronous SQL query to the database which is currently open.
- sqlQuery - The SQL query to be executed.
- bindingParameters - OPTIONAL - An array of values that will be bound to
any '?' characters in
sqlQuery
. - callback -
callback (err, rows, moreResultSets)
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb;
.querySync(sqlQuery [, bindingParameters])
Synchronously issue a SQL query to the database that is currently open.
- sqlQuery - The SQL query to be executed.
- bindingParameters - OPTIONAL - An array of values that will be bound to
any '?' characters in
sqlQuery
.
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb
.close(callback)
Close the currently opened database.
- callback -
callback (err)
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb;
.closeSync()
Synchronously close the currently opened database.
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" //Blocks until the connection is openvar conn = ibmdb; //Blocks until the connection is closedconn;
.prepare(sql, callback)
Prepare a statement for execution.
- sql - SQL string to prepare
- callback -
callback (err, stmt)
Returns a Statement
object via the callback
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb;
.prepareSync(sql)
Synchronously prepare a statement for execution.
- sql - SQL string to prepare
Returns a Statement
object
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb;
.beginTransaction(callback)
Begin a transaction
- callback -
callback (err)
.beginTransactionSync()
Synchronously begin a transaction
.commitTransaction(callback)
Commit a transaction
- callback -
callback (err)
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb;
.commitTransactionSync()
Synchronously commit a transaction
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb;
.rollbackTransaction(callback)
Rollback a transaction
- callback -
callback (err)
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb;
.rollbackTransactionSync()
Synchronously rollback a transaction
var ibmdb = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" ibmdb;
Pool
Rudimentary support, rework in progress......
.open(connectionString, callback)
Get a Database
instance which is already connected to connectionString
- connectionString - The connection string for your database
- callback -
callback (err, db)
var Pool = Pool pool = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" pool;
.close(callback)
Close all connections in the Pool
instance
- callback -
callback (err)
var Pool = Pool pool = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" pool;
contributors
- Javier Sagrera
- Sathyanesh Krishnan (msatyan@gmail.com)
license
Copyright (c) 2017 Sathyanesh Krishnan msatyan@gmail.com
Copyright (c) 2017 Javier Sagrera
Copyright (c) 2013 Dan VerWeire dverweire@gmail.com
Copyright (c) 2010 Lee Smith notwink@gmail.com