0
oracledb npm package
을 사용하여 node.js 백엔드 API를 만들 때 DB와의 연결을 설정합니다. 나는 console.log(result.rows)
oracledb npm 패키지를 사용할 때 얻은 결과를 반환하십시오.
아래는 내가 다른 파일에서 getDbConnection 함수를 호출 기능 코드
getDbConnection: function(query) {
var connectInfo= [EnvConfig.getConnectionHostName(), EnvConfig.getConnectionPort()]; // Array of hostname and port
var connectHost = connectInfo.join(':'); // join hostname and port with ':'
var connectionAttr = [connectHost, EnvConfig.getConnectionSID()]; // hostname:port and SID
var connectString = connectionAttr.join('/'); // creating the connection string like 'hostname:port'
console.log(connectString);
// creating a oracle connection
oracledb.getConnection(
{
user: EnvConfig.getConnectionUserName(),
password: EnvConfig.getConnectionPassword(),
connectString: connectString
},
function (err, connection) {
if(err) {
console.log(err.message);
return;
}
connection.execute(
query, function(err, result) {
if(err) {
console.log(err.message);
return;
}
console.log(result.rows); // I get result here
return result.rows; // return result on success
}
);
}
);
}
이다 할 때 결과를 얻을 수 있어요 내가 console.log(getDbConnection(query))
처럼() CONSOLE.LOG 때. 나는 결과를 정의되지 않은 것으로 얻는다. 어떻게 해결할 수 있습니까?
비상 전화는 비동기 호출의 문제라는 것을 알았지 만 해결 방법을 찾을 수 없었습니다. 고맙습니다. 내가 할 수있을 때 이것을 대답으로 표시 할 것입니다. –
다행입니다. 건배!!! – abdulbarik