【发布时间】:2019-05-16 17:31:24
【问题描述】:
我正在尝试使用 Typescript ES6 类模块实现 oracle 连接。
我已经安装了 @types/oracledb 包以及 oracledb 包。使用了 Jasmin 框架。
下面是我实现的代码。
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();
});
}
}
错误:
TypeError: this.conn.execute is not a function
但是在这个代码连接中,它本身并没有被存储在 'this.conn' 变量中。
是否有避免承诺和异步功能? 有没有其他解决方案可以实现这一目标?请为您提供有价值的解决方案和建议。期待样本 sn-p。
【问题讨论】:
标签: oracle typescript protractor es6-class