Created
January 22, 2024 14:59
-
-
Save AaronDewes/29c497164e692ddb1ad8d681b4b492d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as db2 from "ibm_db"; | |
import { $ } from "bun"; | |
const connStr = | |
"DATABASE=peopledb;HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;UID=db2admin;PWD=passwd;CURRENTSCHEMA=EMPINST;"; | |
const conn: db2.Database = await new Promise((resolve, reject) => | |
db2.open(connStr, (err, conn) => (err ? reject(err) : resolve(conn))) | |
); | |
async function performQuery<RowType = any>( | |
conn: db2.Database, | |
query: string, | |
bindings: any[] = [] | |
): Promise<RowType[]> { | |
const result: db2.ODBCResult = await new Promise((resolve, reject) => | |
conn.queryResult(query, bindings, (err, result) => | |
err ? reject(err) : resolve(result) | |
) | |
); | |
return new Promise((resolve, reject) => | |
result.fetchAll({}, (err, data) => (err ? reject(err) : resolve(data))) | |
); | |
} | |
const currentResps = await performQuery( | |
conn, | |
"SELECT PROF_UID, PROF_JOB_RESPONSIBILITIES FROM people" | |
); | |
console.log(currentResps); | |
// Now, perform a sync | |
const result = await $`D:\IBM\TDISOL\TDI\sync_all_dns.bat`; | |
if (result.exitCode !== 0) { | |
throw new Error(`Failed to sync DNS: ${result.stderr}`); | |
} | |
// And get the entries we have set now | |
const newResps = await performQuery( | |
conn, | |
"SELECT PROF_UID, PROF_JOB_RESPONSIBILITIES FROM people" | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment