Skip to content

Instantly share code, notes, and snippets.

@bohdanszymanik
Last active August 29, 2023 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bohdanszymanik/f268f6c1437e3afa02d3e228a9e3ef5f to your computer and use it in GitHub Desktop.
Save bohdanszymanik/f268f6c1437e3afa02d3e228a9e3ef5f to your computer and use it in GitHub Desktop.
Typescript querying DB2
// Assumes you've installed
// * the free IBM docker db2 edition
// * ibm_db for node: https://github.com/ibmdb/node-ibm_db
// Brings back multiple records as well. Found on the net can't remember where - oh, lots of js docs here: https://github.com/ibmdb/node-ibm_db/blob/master/APIDocumentation.md
import * as db2 from 'ibm_db';
let cn: string = "DRIVER={DB2};DATABASE=testdb;HOSTNAME=127.0.0.1;UID=db2inst1;PWD=password;PORT=50000;PROTOCOL=TCPIP";
db2.open(cn, function(err: any, conn: any){
if (err) return console.log(err);
conn.query('select 1 from sysibm.sysdummy1', function (err: any, data: any) {
if (err) console.log(err);
else console.log(data);
conn.close(function () {
console.log('done');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment