我正在尝试编写可重用函数以从 oracledb 获取值并在需要时分配该值。
我的示例代码如下。//getTtalRwCnt.js
'use strict';
var db_con = require('./oracleConnectPage.js');
// var db = new db_con();
var OracelQP = db_con.getOracleQP_details();
var oracledb = require('oracledb');
var tmpRwCnt;
var getTtalRwCnt = function () {
oracledb.outFormat = oracledb.ARRAY;
var query = "SELECT TESTCASEID FROM EXECUTE_TESTCASE";
oracledb.getConnection(OracelQP, function (err, connection) {
if (err) {
console.error(err.message); return;
}
connection.execute(query, function (err, result) {
if (err) {
console.error(err.message);
connection.close();
return;
}
console.log("result----->" + result.rows.length);
tmpRwCnt = result.rows.length;
return tmpRwCnt;
})
})
}
module.exports.getTtalRwCnt = getTtalRwCnt();
//spec.js
'use strict';
var rwCnt = require('../DBSample/DB/getTtalRwCnt.js');
describe('Get Total number of Rows from DB', function () {
it('Get Rw count',function(){
console.log(rwCnt.getTtalRwCnt());
});
});