My goal is to implement an Oracle connection using Typescript ES6 Class module. I have successfully installed the @types/oracledb package and oracledb package, with the Jasmin framework used in my project.
Below is the code I have implemented:
import * as oracledb from 'oracledb';
export class ConnectionDAO{
/**
* Connection Variable Declaration
*/
conn;
/**
* Result Variable Declaration
*/
result;
/**
*
* Creates an instance of CommercialDAO.
* To Initiate Connection and Make the connection utilized by @memberof CommercialDAO
* @memberof CommercialDAO
*/
constructor() {
this.conn = oracledb.getConnection({
user: "commercial",
password: "oracle",
connectString: "localhost/COMMERCIALDB"
});
}
public getRwCnt() {
return new Promise(async function(resolve, reject) {
try {
let result = this.conn.execute('SELECT TESTCASEID FROM EXECUTE_TESTCASE');
resolve(this.result.rows.length);
} catch (err) { // catches errors in getConnection and the query
reject(err);
}
this.conn.release();
});
}
}
Error:
TypeError: this.conn.execute is not a function
The issue here is that the connection itself is not being stored in the 'this.conn' variable as expected.
I am looking for alternative solutions to achieve this without using promises and async functions. Any other suggestions on how to resolve this? Your valuable input and sample snippet would be greatly appreciated.