Okay, so i could use some help. I know my code is incorrect, whats the easiest way to go about handling this. As you can see my return is going to return an empty variable before the query has been executed.
const fetchall = function fetch(sessionid) {
let data;
connection.query(
'SELECT * FROM LOCATIONS WHERE SESSIONID = ?', [sessionid],
function(err, rows, fields) {
data = rows;
});
return data;
};
I am using express here and the code for the request looks like this.
app.post('/api/locations/fetchall', function (req, res) {
let sesionid = sessions.active();
let results = locations.fetchall(sesionid);
res.send(results);
});