/index.ts Secret
Created
February 11, 2021 08:59
Node.js code for inserting & retrieving a date with oracledb
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
// ------------------------------- NODE MODULES ------------------------------- | |
import { BIND_OUT } from "oracledb"; | |
// ------------------------------ CUSTOM MODULES ------------------------------ | |
import oracledb, { Connection } from "oracledb"; | |
// -------------------------------- VARIABLES --------------------------------- | |
const ora_sdtz = "Europe/London"; | |
// const ora_sdtz = "UTC"; | |
// ----------------------------- FILE DEFINITION ------------------------------ | |
interface MyDateOut { | |
DATE_ID: number; | |
MY_DATE: Date; | |
} | |
const main = async (): Promise<void> => { | |
try { | |
await oracledb.createPool({ | |
connectionString: "10.20.14.109:1527/SYMA.atradiusnet.com", | |
password: "orabup0", | |
user: "ORABUP0", | |
poolAlias: "ORADB-TEST", | |
poolIncrement: 1, | |
queueTimeout: 60000, | |
stmtCacheSize: 0, | |
_enableStats: true, | |
}); | |
const connection = (await oracledb.getConnection( | |
"ORADB-TEST" | |
)) as Connection; | |
await connection.execute(`alter session set time_zone='${ora_sdtz}'`); | |
await insertDateProcedure(connection); | |
await connection.close(); | |
} catch (err) { | |
console.error(err); | |
} | |
}; | |
const insertDateProcedure = async (connection: Connection) => { | |
const myDateIn = new Date("2021-07-10T12:00:00.000Z"); | |
console.log(`MyDateIn Javascript Object: ${myDateIn.toISOString()}`); | |
const sql = `BEGIN | |
pr_date_test(p_in_date => :myDateIn, p_out_date => :myDateOut); | |
END;`; | |
const bindParams = { | |
myDateIn, | |
myDateOut: { dir: BIND_OUT, type: "O_DATE_TEST" }, | |
}; | |
interface OutBinds { | |
myDateOut: MyDateOut; | |
} | |
const outBinds = (await connection.execute<OutBinds>(sql, bindParams)) | |
.outBinds; | |
console.log(outBinds?.myDateOut); | |
connection.commit(); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment