### Create Project Directory and Install Node-ibm_db on Windows Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Steps to create a project directory and install the node-ibm_db package using npm on Windows. This involves creating a directory and then running the npm install command. ```bash 1. mkdir nodeapp 2. cd nodeapp ``` ```bash 3. npm install ibm_db ``` -------------------------------- ### Install ibm_db with Manual Clidriver Download (Non-Windows) Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md If installation fails due to firewall blocking clidriver downloads, manually download the clidriver, set the IBM_DB_HOME environment variable, and then run `npm install ibm_db`. ```bash export IBM_DB_HOME=/home/$USER/clidriver npm install ibm_db ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/ibmdb/node-ibm_db/blob/master/NAN_TO_NAPI_MIGRATION.md Run 'npm install' in the project directory to install the updated dependencies, including 'node-addon-api' and remove 'nan'. ```bash cmd /c "cd c:\nodework\master\ibm_db && npm install" ``` -------------------------------- ### Install node-ibm_db from GitHub Repository Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Install the node-ibm_db module directly from its GitHub repository using npm. This requires Git on z/OS to be installed. ```sh # Install from GitHub repository npm install git+ssh://git@github.com/ibmdb/node-ibm_db.git ``` -------------------------------- ### Create, Insert, Select, and Drop Table (Second Example) Source: https://github.com/ibmdb/node-ibm_db/blob/master/test/data/sample2.txt A second example illustrating table creation, data insertion, selection, and deletion. ```sql create table sample1(no integer) ``` ```sql insert into sample1 values(1) ``` ```sql insert into sample1 values(2) ``` ```sql select * from sample1 ``` ```sql drop table sample1 ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Installs additional packages required for development and testing, such as async, bluebird, and moment. ```bash npm install async bluebird moment ``` -------------------------------- ### Install ibm_db in Docker Linux Container Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Commands for setting up a Docker Linux environment, including installing build tools, Python, Node.js, and then installing ibm_db with --unsafe-perm. ```bash yum install make gcc gcc-c++ kernel-devel openssl-devel bzip2-devel install python3.x install node.js npm install --unsafe-perm ibm_db ``` -------------------------------- ### Install node-ibm_db Dependencies Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Navigate into the cloned directory and run npm install to build the odbc_bindings.node file. ```bash cd node-ibm_db npm install ``` -------------------------------- ### Install node-ibm_db via npm Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Installs the node-ibm_db package from the npm registry. This is the recommended method for most users. ```bash npm install ibm_db ``` -------------------------------- ### Install node-ibm_db from GitHub Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Installs the node-ibm_db package directly from its GitHub repository. Use this if you need the latest development version. ```bash npm install git+https://git@github.com/ibmdb/node-ibm_db.git ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Installs node-gyp and other necessary npm packages for building the node-ibm_db module from source. ```bash npm install -g node-gyp npm install moment async bluebird npm install nan bindings adm-zip request targz ``` -------------------------------- ### Install ibm_db on MacOS M1/M2 Chip Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md For MacOS M1/M2 chip systems, install LLVM, set the C++ compiler, and then run npm install. ```bash brew install llvm export CXX="/opt/homebrew/opt/llvm/bin/clang++" npm install ibm_db ``` -------------------------------- ### Install node-ibm_db via npm Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Install the node-ibm_db module directly from the npm repository. This is a straightforward installation method. ```sh # Install via npm repository npm install ibm_db ``` -------------------------------- ### Enable Debugging via npm install Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Alternatively, run 'npm install --debug' in the ibm_db directory to enable debugging messages. ```bash cd ibm_db npm install --debug ``` -------------------------------- ### Install Node.js Binaries on Linux on Power Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Download and execute the Node.js binaries for Linux on Power Systems. Ensure you have the correct version for your architecture. ```bash cd /mynode ./ibm-4.4.3.0-node-v4.4.3-linux-ppc64.bin ``` -------------------------------- ### Install ibm_db with Manual Clidriver Download (Windows) Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md For Windows users facing clidriver download issues, manually download the clidriver, set the IBM_DB_HOME environment variable, and then run `npm install ibm_db`. ```batch set IBM_DB_HOME=C:\myproject\clidriver npm install ibm_db ``` -------------------------------- ### Install Node-ibm_db Module Dependencies Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Install the necessary dependencies for the node-ibm_db module after cloning the repository. This command should be run from within the cloned repository directory. ```sh npm install ``` -------------------------------- ### Extract Node.js Linux on System z Binaries Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Executes the Node.js Linux on System z binary installer to install Node.js in the specified directory. Ensure the binary file is present and executable. ```bash cd /mynode ./ibm-4.4.3.0-node-v4.4.3-linux-s390x.bin ``` -------------------------------- ### Install ibm_db in Quiet Mode Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Install the ibm_db package with reduced output using the --quiet or -q flags. ```bash npm install --quiet ibm_db ``` ```bash npm install -q ibm_db ``` -------------------------------- ### Create Another Table with IBM DB Node.js Source: https://github.com/ibmdb/node-ibm_db/blob/master/test/data/sample3.txt Example of creating a second table with different column structure. ```sql create table sample1(no integer) ``` -------------------------------- ### Create Node.js Application Directory Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Creates a new directory for your Node.js application and navigates into it. This is the first step before installing packages. ```bash mkdir nodeapp cd nodeapp ``` -------------------------------- ### Install ibm_db in Silent Mode Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Install the ibm_db package with minimal output using the --silent or -s flags. ```bash npm install --silent ibm_db ``` ```bash npm install -s ibm_db ``` -------------------------------- ### Extract Node.js AIX Binaries Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Executes the Node.js AIX binary installer to install Node.js in the specified directory. Ensure the binary file is present and executable. ```bash cd /mynode ./ibm-4.4.3.0-node-v4.4.3-aix-ppc64.bin ``` -------------------------------- ### Basic Parameter Binding Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Simple examples of binding parameters for SQL queries using arrays of values. ```javascript [18, 'string'] ``` ```javascript [3, 5, 3.8, 'string', 9.1] ``` ```javascript [18, [1, 1, 1, 'string']] ``` ```javascript [[1, 1, 1, 18], [1, 1, 1, 'string']] ``` -------------------------------- ### Install node-eio for Increased Thread Pool Size Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Install the node-eio package to increase the libeio thread pool size beyond the default of 4, which is useful for managing long-running queries concurrently. ```bash npm install eio ``` -------------------------------- ### .beginTransactionSync Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Starts a new database transaction synchronously. ```APIDOC ## .beginTransactionSync() ### Description Starts a new database transaction synchronously. ### Method Synchronous ``` -------------------------------- ### Configure Quiet/Silent Installation via npm Config Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Set npm configuration log levels to control installation output for quiet or silent modes. ```bash export npm_config_loglevel=warn => For quiet mode installation. ``` ```bash export npm_config_loglevel=silent => For silent mode installation. ``` -------------------------------- ### Build 7: InstanceMethod with Attributes Source: https://github.com/ibmdb/node-ibm_db/blob/master/NAN_TO_NAPI_MIGRATION.md Example showing how to apply the NAPI_METHOD_ATTR macro to InstanceMethod calls in C++ source files to ensure prototype methods are writable and configurable, matching NAN behavior. ```cpp // Before: InstanceMethod("execute", &ODBCStatement::Execute), // After: InstanceMethod("execute", &ODBCStatement::Execute, NAPI_METHOD_ATTR), ``` -------------------------------- ### .beginTransaction Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Starts a new database transaction asynchronously. A callback function is invoked upon completion. ```APIDOC ## .beginTransaction([callback]) ### Description Starts a new database transaction asynchronously. ### Method Asynchronous ### Parameters - **callback** (function) - Optional - A callback function to be executed upon completion. ``` -------------------------------- ### (Pool) .open(connectionString [, callback]) Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Get a Database instance which is already connected to connectionString. Supports both callback and Promise-based usage. ```APIDOC ## (Pool) .open(connectionString [, callback]) ### Description Get a `Database` instance which is already connected to `connectionString`. If a callback is not provided, a Promise will be returned. ### Parameters #### Path Parameters - **connectionString** (string) - Required - The connection string for your database - **callback** (function) - Optional - `callback (err, db)`. If callback is not provided, a Promise will be returned. ### Request Example ```javascript const Pool = require("ibm_db").Pool , pool = new Pool() , cn = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=dbuser;PWD=xxx"; pool.open(cn, function (err, db) { if (err) { return console.log(err); } console.log("Connection opened successfully."); console.log("Data = ", db.querySync("select 1 as c1 from sysibm.sysdummy1")); db.close(function (error) { // RETURN CONNECTION TO POOL if (error) { console.log("Error while closing connection,", error); return; } }); }); ``` ``` -------------------------------- ### Create, Insert, Select, and Drop Table 'sample' Source: https://github.com/ibmdb/node-ibm_db/blob/master/test/data/sample1.txt Demonstrates the lifecycle of a table named 'sample', including creation, inserting data, selecting all records, and finally dropping the table. ```sql create table sample(no integer,name varchar(10)); ``` ```sql insert into sample values(1,'pri'); ``` ```sql insert into sample values(2,'anbu'); ``` ```sql select * from sample; ``` ```sql drop table sample; ``` -------------------------------- ### Create, Insert, Select, and Drop Table 'sample1' Source: https://github.com/ibmdb/node-ibm_db/blob/master/test/data/sample1.txt Illustrates the management of a table named 'sample1', covering its creation, population with data, retrieval of all entries, and subsequent removal. ```sql create table sample1(no integer); ``` ```sql insert into sample1 values(1); ``` ```sql insert into sample1 values(2); ``` ```sql select * from sample1; ``` ```sql drop table sample1; ``` -------------------------------- ### Connect and Query with Callbacks Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Establishes a database connection using a connection string and executes a simple query using callback functions. Ensure you have the correct connection details. ```javascript var ibmdb = require("ibm_db"); var connStr = "DATABASE=;HOSTNAME=;UID=db2user;PWD=password;PORT=;PROTOCOL=TCPIP"; ibmdb.open(connStr, function (err, conn) { if (err) return console.log(err); conn.query("select 1 from sysibm.sysdummy1", function (err, data) { if (err) console.log(err); else console.log(data); conn.close(function () { console.log("done"); }); }); }); ``` -------------------------------- ### AIX Install Memory Issue Workaround Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Addresses 'Out Of Memory' errors during ibm_db installation on AIX systems. It involves increasing the data segment limit before running the npm install command. ```bash ulimit -d unlimited npm install ibm_db ``` -------------------------------- ### Create, Insert, Select, and Drop Table Source: https://github.com/ibmdb/node-ibm_db/blob/master/test/data/sample2.txt Demonstrates the full lifecycle of a table: creation, inserting data, selecting data, and finally dropping the table. ```sql create table sample(no integer,name varchar(10)) ``` ```sql insert into sample values(1,'pri') ``` ```sql insert into sample values(2,'anbu') ``` ```sql select * from sample ``` ```sql drop table sample ``` -------------------------------- ### Validate ibm_db Installation Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Steps to validate the ibm_db installation by updating connection info and running a basic test script. ```bash node node_modules\ibm_db\test\test-basic-test.js ``` -------------------------------- ### Connect and Query with Async/Await Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Demonstrates database connection, table creation, insertion, and querying using async/await syntax for modern JavaScript asynchronous programming. This is often the most readable approach. ```javascript main(); async function main() { try { let conn = await ibmdb.open(cn); await conn.query("drop table mytab").catch((e) => { console.log(e); }); await conn.query("create table mytab(c1 int, c2 varchar(10))"); await conn.query("insert into mytab values (?, ?)", [3, "ibm"]); let stmt = await conn.prepare("select * from mytab"); let result = await stmt.execute(); data = await result.fetchAll(); console.log("result = ", data); await result.close(); await stmt.close(); await conn.close(); } catch (e) { console.log(e); } } ``` -------------------------------- ### Create Backup Directory for Source Files Source: https://github.com/ibmdb/node-ibm_db/blob/master/NAN_TO_NAPI_MIGRATION.md Create a new directory to store the original source files before they are rewritten. ```bash cmd /c "mkdir c:\nodework\master\ibm_db\src_nan_backup" ``` -------------------------------- ### Install ibm_db with Specific clidriver Version Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Install the ibm_db package specifying a particular clidriver version using the -clidriver flag. ```bash npm install ibm_db -clidriver= ``` ```bash npm install ibm_db -clidriver=v11.1.4 ``` ```bash npm install ibm_db -clidriver=v11.5.6 ``` -------------------------------- ### Configure and Build node-ibm_db Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Configures and builds the node-ibm_db module using node-gyp. The --IBM_DB_HOME and --IS_DOWNLOADED flags are important for the build process. ```bash node-gyp configure build --IBM_DB_HOME=$IBM_DB_HOME --IS_DOWNLOADED=false --verbose ``` -------------------------------- ### Copy Original Source Files to Backup Source: https://github.com/ibmdb/node-ibm_db/blob/master/NAN_TO_NAPI_MIGRATION.md Copy all original .h and .cpp source files from the 'src' directory to the newly created backup directory. ```bash cmd /c "copy c:\nodework\master\ibm_db\src\odbc.h c:\nodework\master\ibm_db\src_nan_backup\" ``` ```bash cmd /c "copy c:\nodework\master\ibm_db\src\odbc.cpp c:\nodework\master\ibm_db\src_nan_backup\" ``` ```bash cmd /c "copy c:\nodework\master\ibm_db\src\odbc_connection.h c:\nodework\master\ibm_db\src_nan_backup\" ``` ```bash cmd /c "copy c:\nodework\master\ibm_db\src\odbc_connection.cpp c:\nodework\master\ibm_db\src_nan_backup\" ``` ```bash cmd /c "copy c:\nodework\master\ibm_db\src\odbc_statement.h c:\nodework\master\ibm_db\src_nan_backup\" ``` ```bash cmd /c "copy c:\nodework\master\ibm_db\src\odbc_statement.cpp c:\nodework\master\ibm_db\src_nan_backup\" ``` ```bash cmd /c "copy c:\nodework\master\ibm_db\src\odbc_result.h c:\nodework\master\ibm_db\src_nan_backup\" ``` ```bash cmd /c "copy c:\nodework\master\ibm_db\src\odbc_result.cpp c:\nodework\master\ibm_db\src_nan_backup\" ``` -------------------------------- ### Get Type Info Synchronously Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Use `getTypeInfoSync` to synchronously retrieve information about supported SQL data types. Specify `ibmdb.SQL_ALL_TYPES` to get all types, ordered by `TYPE_NAME`. ```javascript const ibmdb = require("ibm_db") , cn = "DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password"; ibmdb.open(cn, function(err, conn) { let result = conn.getTypeInfoSync(ibmdb.SQL_BIGINT); console.log("SQL_BIGINT Data Type Info = ", result); conn.closeSync(); }); ``` -------------------------------- ### Asynchronous Bind and Execute with BLOB Data Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Demonstrates how to prepare a statement, bind parameters including a BLOB file, and execute it asynchronously. Ensure the connection is properly opened and closed. The result set should be closed after fetching. ```javascript const ibmdb = require("ibm_db") , cn = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=dbuser;PWD=xxx"; ibmdb.open(cn,function(err, conn){ conn.querySync("create table mytab (id int, photo BLOB(30K))"); conn.prepare("insert into mytab (id, photo) VALUES (?, ?)", function (err, stmt) { if (err) { //could not prepare for some reason console.log(err); return conn.closeSync(); } // Create params object const img = {ParamType:"FILE", DataType: "BLOB", "Data": "smile.jpg"}; //Bind and Execute the statement asynchronously stmt.execute([ 42, img ], function (err, result) { if( err ) console.log(err) else result.closeSync(); //Close the connection stmt.close(function(err){ if(err){ console.log(err) } conn.close(function(err){}); }); }); }); }); ``` -------------------------------- ### Install ibm_db with specific CLI driver version Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Installs the ibm_db package while specifying a particular version of the IBM Data Server Driver for CLI (CLIDriver). This is useful for compatibility or specific feature requirements. ```bash npm install ibm_db -clidriver=v11.5.9 ``` -------------------------------- ### (Pool) .init(N, connStr) Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Initialize Pool with N no of active connections using supplied connection string. This is a synchronous API. ```APIDOC ## (Pool) .init(N, connStr) ### Description Initialize `Pool` with N no of active connections using supplied connection string. It is a synchronous API. ### Parameters #### Path Parameters - **N** (number) - Required - No of connections to be initialized. - **connStr** (string) - Required - The connection string for your database ### Request Example ```javascript const Pool = require("ibm_db").Pool , pool = new Pool() , cn = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=dbuser;PWD=xxx"; const ret = pool.init(5, cn); if(ret != true) { console.log(ret); return false; } pool.open(cn, function(err, db) { ... }); ``` ``` -------------------------------- ### Configure npm to use a specific CLI driver version Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Sets the npm configuration to use a specific version of the IBM Data Server Driver for CLI (CLIDriver) for subsequent installations of ibm_db. This avoids needing to specify the version on each install command. ```bash npm config set clidriver=v11.5.9 npm install ibm_db ``` -------------------------------- ### Bind Packages using DB2 CLP (z/OS) Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Alternatively, if you have another DB2 client with CLP, you can bind packages using the `db2 bind` command. This example shows binding against a DB2 for z/OS server. ```bash db2 bind .../sqllib/bnd/@ddcsmvs.lst action replace grant public sqlerror continue messages msg.txt ``` -------------------------------- ### (Pool) .openSync(connectionString) Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Get a Database connection synchronously which is already connected to connectionString. ```APIDOC ## (Pool) .openSync(connectionString) ### Description Get a `Database` connection synchronously which is already connected to `connectionString`. ### Parameters #### Path Parameters - **connectionString** (string) - Required - The connection string for your database ### Request Example ```javascript const Pool = require("ibm_db").Pool , pool = new Pool() , cn = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=dbuser;PWD=xxx"; try { const conn = pool.openSync(cn); } catch(error) { console.log("Unable to open connection,", error); return; } console.log("Connection opened successfully."); console.log("Data = ", conn.querySync("select 1 as c1 from sysibm.sysdummy1")); const err = conn.closeSync(); // RETURN DB CONNECTION TO POOL. if (err) { console.log("Error while closing connection,", err); return; } ``` ``` -------------------------------- ### CLOB Data Binding Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Examples for binding CLOB data, either directly from a variable or from a file. ```javascript [38, {ParamType:"INPUT", DataType: "CLOB", "Data": var1}] - here var1 contains full CLOB data to be inserted. ``` ```javascript [38, {ParamType:"FILE", DataType: "CLOB", "Data": filename}] - here filename is the name of file which has large character data. ``` -------------------------------- ### .createDbSync Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Synchronously creates a database with the specified name and connection string. Optional configuration can be provided. ```APIDOC ## .createDbSync(dbName, connectionString, [options]) ### Description Synchronously creates a database. ### Method Synchronous ### Parameters - **dbName** (string) - Required - The name of the database to create. - **connectionString** (string) - Required - The connection string for the database. - **options** (object) - Optional - Additional configuration options. ``` -------------------------------- ### .open Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Opens a database connection asynchronously using the provided connection string and optional configuration. A callback function is executed upon completion. ```APIDOC ## .open(connectionString [, options] [, callback]) ### Description Opens a database connection asynchronously. ### Method Asynchronous ### Parameters - **connectionString** (string) - Required - The connection string for the database. - **options** (object) - Optional - Additional configuration options. - **callback** (function) - Optional - A callback function to be executed upon completion. ``` -------------------------------- ### Synchronous Prepare, Execute, and Fetch Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Shows how to synchronously prepare a statement, execute it with parameters, fetch all results in array mode, and close the statement and connection. This method is useful for simpler, sequential operations. ```javascript const ibmdb = require("ibm_db") , cn = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=dbuser;PWD=xxx"; ibmdb.open(cn,function(err, conn){ const stmt = conn.prepareSync("select empname from emptable where empid = ?"); //Bind and Execute the statment asynchronously const result = stmt.executeSync([142]); const data = result.fetchAllSync({fetchMode:3}); // Fetch data in Array mode. console.log(data); result.closeSync(); stmt.closeSync(); //Close the connection conn.close(function(err){}); }); ``` -------------------------------- ### Clone node-ibm_db Repository Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Clones the node-ibm_db repository from GitHub. This is the first step for manual installation or contributing to the project. ```bash mkdir nodeapp cd nodeapp git clone https://github.com/ibmdb/node-ibm_db/ ``` -------------------------------- ### Update Configuration and Run Tests Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Updates the connection string in config.json and runs the test suite. Ensure config.json is correctly configured with your database credentials. ```bash cd node_modules/ibm_db/test/ vi config.json => Update connection string in this file. node run-tests.js ``` -------------------------------- ### Get ibm_db Instance using Helper Function Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Obtains an instance of the ibm_db module using a helper function. ```javascript var ibmdb = require("ibm_db")(); ``` -------------------------------- ### Clone node-ibm_db Repository Source: https://github.com/ibmdb/node-ibm_db/blob/master/INSTALL.md Clone the node-ibm_db GitHub repository using Git on z/OS. This is the first step for manual installation. ```sh git clone git://github.com/ibmdb/node-ibm_db cd node-ibm_db ``` -------------------------------- ### .open(connectionString, options, callback) Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Opens a connection to a database using a provided connection string and optional parameters. It can return a Promise or use a callback function. ```APIDOC ## .open(connectionString [, options] [, callback]) ### Description Open a connection to a database. ### Parameters * **connectionString** - The connection string for your database. * For distributed platforms, the connection string is typically defined as: `DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=passwd` * For z/OS, the ODBC driver makes both local and remote connections using DSN, UID and PWD. The connection string is typically defined as: `DSN=dbname;UID=username;PWD=passwd`. * Selecting default schema is also supported using `CURRENTSCHEMA=schemaname;` (or CurrentSchema) * **options** - _OPTIONAL_ - Object type. Can be used to avoid multiple loading of native ODBC library for each call of `.open`. Also, can be used to pass connectTimeout value and systemNaming(true/false) for i5/OS server. * **callback** - _OPTIONAL_ - `callback (err, conn)`. If callback is not provided, a Promise will be returned. ### Request Example ```javascript const ibmdb = require("ibm_db") , connStr = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=passwd"; ibmdb.open(connStr, function (err, conn) { if (err) { console.log(err); return; } conn.query("select 1 from sysibm.sysdummy1", function (err1, rows) { if (err1) console.log(err1); else console.log(rows); conn.close(function(err2) { if(err2) console.log(err2); }); }); }); ``` ### Secure Database Connection using SSL/TSL * **connectionString** - Example for secure connection: ```javascript connStr = "DATABASE=database;HOSTNAME=hostname;PORT=port;Security=SSL;SSLServerCertificate=;PROTOCOL=TCPIP;UID=username;PWD=passwd"; ``` > Note the two extra keywords **Security** and **SSLServerCertificate** used in connection string. `SSLServerCertificate` should point to the SSL Certificate from server or an CA signed certificate. Also, `PORT` must be `SSL` port and not the TCP/IP port. Make sure Db2 server is configured to accept connection on SSL port else `ibm_db` will throw SQL30081N error. > Value of `SSLServerCertificate` keyword must be full path of a certificate file generated for client authentication. It normally has `*.arm` or `*.cert` or `*.pem` extension. `ibm_db` do not support `*.jks` format file as it is not a certificate file but a Java KeyStore file, extract certificate from it using keytool and then use the cert file. > `ibm_db` supports only ODBC/CLI Driver keywords in connection string: https://www.ibm.com/docs/en/db2/11.5?topic=odbc-cliodbc-configuration-keywords > Do not use keywords like `sslConnection=true` in connection string as it is a JDBC connection keyword and ibm_db ignores it. Corresponding ibm_db connection keyword for `sslConnection` is `Security` hence, use `Security=SSL;` in connection string instead. * To connect to dashDB in IBM Cloud, use below connection string: ```javascript connStr = "DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=passwd;Security=SSL"; ``` > We just need to add **Security=SSL** in connection string to have a secure connection against Db2 server in IBM Cloud. **Note:** You can also create a KeyStore DB using GSKit command line tool and use it in connection string along with other keywords as documented in [DB2 Infocenter](http://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.admin.sec.doc/doc/t0053518.html). ``` -------------------------------- ### Initialize Connection Pool Asynchronously with Async/Await Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Initializes the connection pool using async/await syntax, allowing for cleaner asynchronous code flow. It then opens a connection and executes a query. ```javascript try { await pool.initAsync(1, cn); let conn = await pool.open(cn); let data = await conn.query("select 1 from sysibm.sysdummy1"); console.log("data = ", data); } catch(err) {console.log(err);} ``` -------------------------------- ### Chunked LOB Insert Binding Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Examples for chunked LOB inserts, using either an array of buffers or a readable stream. ```javascript [1, {DataType:"BLOB", Data:[chunk1, chunk2, chunk3]}] - chunked LOB insert using array of Buffers. ``` ```javascript [1, {DataType:"BLOB", Data:readableStream, Length:totalSize}] - chunked LOB insert using Readable stream (async only). ``` -------------------------------- ### Open Database Connection and Query Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Establishes a connection to the database using a connection string and executes a simple query. Handles potential errors during connection and query execution, and closes the connection afterward. ```javascript const ibmdb = require("ibm_db") , connStr = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=passwd"; ibmdb.open(connStr, function (err, conn) { if (err) { console.log(err); return; } conn.query("select 1 from sysibm.sysdummy1", function (err1, rows) { if (err1) console.log(err1); else console.log(rows); conn.close(function(err2) { if(err2) console.log(err2); }); }); }); ``` -------------------------------- ### Verify Binary Dependencies Source: https://github.com/ibmdb/node-ibm_db/blob/master/NAN_TO_NAPI_MIGRATION.md This command uses the `dumpbin` utility to list the dynamic link libraries that the `odbc_bindings.node` file depends on. This verifies that the module is correctly linked against the IBM CLI library and the Windows ODBC Driver Manager. ```bash dumpbin /DEPENDENTS build\Release\odbc_bindings.node ``` -------------------------------- ### DCO Sign-off Comment Example Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md When contributing, include a DCO sign-off as a comment in your pull request, following the specified format. ```text DCO Signed-off-by: Random J Developer ``` -------------------------------- ### Load ibm_db Module and Verify Exports Source: https://github.com/ibmdb/node-ibm_db/blob/master/NAN_TO_NAPI_MIGRATION.md This command loads the ibm_db module and logs its exports to verify that the module is loaded correctly and the full API surface is available. Ensure the IBM_DB_HOME environment variable is set to the CLI driver path. ```bash cmd /c "cd c:\nodework\master\ibm_db && set PATH=C:\nodework\clidriver\bin;%PATH% && set IBM_DB_HOME=C:\nodework\clidriver && node -e \"var ibmdb=require('./'); console.log('Module loaded OK'); console.log('ibmdb keys:', Object.keys(ibmdb).join(', ')); console.log('openSync exists:', typeof ibmdb.openSync);\"" ``` -------------------------------- ### (ODBCStatement) .paramDataSync() Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Synchronously calls SQLParamData() to get the next parameter for which a data value is needed. Used for data-at-execution parameters. ```APIDOC ## (ODBCStatement) .paramDataSync() ### Description Synchronously calls `SQLParamData()` to get the next parameter for which a data value is needed. ### Method Synchronous ### Returns An object with: - **needsData** (boolean) - `true` if `SQL_NEED_DATA` was returned. - **paramIndex** (number | null) - The index/token of the parameter that needs data. ### Request Example ```javascript const ibmdb = require("ibm_db"); const cn = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=dbuser;PWD=xxx"; ibmdb.open(cn, function(err, db) { const stmt = db.conn.createStatementSync(); // ... after binding and executing ... const result = stmt.paramDataSync(); if (result.needsData) { console.log("Need data for parameter:", result.paramIndex); // Call putDataSync() to send the data... } stmt.closeSync(); db.closeSync(); }); ``` ``` -------------------------------- ### Build Command for ibm_db Source: https://github.com/ibmdb/node-ibm_db/blob/master/NAN_TO_NAPI_MIGRATION.md Executes the Node-API build process for the ibm_db module and redirects output to a log file. Use this command to compile the native addon. ```bash cmd /c "cd c:\nodework\master\ibm_db && npx node-gyp rebuild > build_log.txt 2>&1" ``` ```bash cmd /c "type c:\nodework\master\ibm_db\build_log.txt" ``` -------------------------------- ### Get ibm_db Instance using Constructor Source: https://github.com/ibmdb/node-ibm_db/blob/master/README.md Obtains an instance of the ibm_db module by creating a new instance of the Database class. ```javascript var Database = require("ibm_db").Database, ibmdb = new Database(); ``` -------------------------------- ### SSL Connection String with Keystore and Password Source: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md Use this connection string format when you have a KeyStore DB created with GSKit using a password, or if you have a *.kdb file and know its password. ```javascript connStr = "DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=dbuser;PWD=db2pwd;" + "Security=SSL;SslClientKeystoredb=C:/client.kdb;SSLClientKeystoreDBPassword=kdbpasswd;"; ```