自周四以来,我一直被这个问题困扰,我无法弄清楚问题出在哪里。查看日志看起来 HTTP 请求在从数据库检索数据之前完成。我尝试了 async/await 的所有组合...
你们知道如何解决这个问题吗?
app.get("/getData", (req, res) => {
let data = oracledb.getConnection(
{
user: "hr",
password: "hr",
connectString: "localhost/user"
},
(err, connection) => {
if (err) {
console.error(err.message);
return;
}
queries.getData(connection, 3);
}
);
console.log('Arrives here:', data)
res.send(data)
})
const getData = (conn, id) => {
const query = `SELECT * FROM SoapDataObject WHERE id = ${id}`;
let result = conn.execute(query, (err, result)=> {
if (err) {
console.error(err.message);
doRelease(conn);
return;
}
// console.log(result.metaData);
console.log(result.rows);
doRelease(conn);
return result.rows
})
return result;
};
控制台显示:
REST API server started on: 3000
[1] Listening on port 8001
[1] WSDL available at http://localhost:8001/soapWs?wsdl
[1] Arrives here: undefined
[1] [ [ 3, '1010', 11, 11, 11, 11, 11, 2 ] ]