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
# Local Install: just for the project. npm install ifxnjs # Global Install: on the system for the user npm install -g 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@10.0.x) is being compiled with Node.js v10.15.1 LTS libraries. The driver is expected to work with all node.js version 10x.
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 has prebuilt native module available for ARM, Linux x64 and Win64, that mean if you are on this platforms in a normal scenario you don’t need to build the driver from its source; just follow the install step mention above and you are good to go. By any chance if you have to build the driver from the source then please follow the step. The driver source code is platform neutral; you may build it 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 ARM, Linux and Windows.
Connection
var dbobj = ;var ConStr = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;"; var conn = dbobj; // FYI: for Asynchronous open then// dbobj.open( ConStr, (err, conn) => {} ); // -- -- -- -- -- -- --// Do some DB work here// -- -- -- -- -- -- -- conn;
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 dbobj = ;
or by creating an instance with the constructor function:
var Database = Database dbobj = ;
.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 dbobj = ; dbobj
.openSync(connectionString)
Synchronously open a connection to a database.
- connectionString - The connection string for your database
var dbobj = connString = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" try var conn = dbobj; 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 dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj;
.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 dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj
.close(callback)
Close the currently opened database.
- callback -
callback (err)
var dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj;
.closeSync()
Synchronously close the currently opened database.
var dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" //Blocks until the connection is openvar conn = dbobj; //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 dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj;
.prepareSync(sql)
Synchronously prepare a statement for execution.
- sql - SQL string to prepare
Returns a Statement
object
var dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj;
.beginTransaction(callback)
Begin a transaction
- callback -
callback (err)
.beginTransactionSync()
Synchronously begin a transaction
.commitTransaction(callback)
Commit a transaction
- callback -
callback (err)
var dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj;
.commitTransactionSync()
Synchronously commit a transaction
var dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj;
.rollbackTransaction(callback)
Rollback a transaction
- callback -
callback (err)
var dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj;
.rollbackTransactionSync()
Synchronously rollback a transaction
var dbobj = cn = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxx;" dbobj;
Connection Pool
Work in progress......
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