0
好的,所以我可以使用一些帮助。我知道我的代码不正确,最简单的处理方法是什么。正如你所看到的,我的返回将在查询执行之前返回一个空变量。节点MYSQL请求,异步问题
const fetchall = function fetch(sessionid) {
let data;
connection.query(
'SELECT * FROM LOCATIONS WHERE SESSIONID = ?', [sessionid],
function(err, rows, fields) {
data = rows;
});
return data;
};
我在这里使用快递,请求的代码如下所示。
app.post('/api/locations/fetchall', function (req, res) {
let sesionid = sessions.active();
let results = locations.fetchall(sesionid);
res.send(results);
});