I've been trying for a long time, but I haven't found the right solution how to get the "result" outside the function. To then be able to use the variable in a class.
getIDfromRoom(room) {
db.getConnection().query("SELECT room.room_id FROM `room` WHERE room.roomname = '" + room.roomname + "' limit 1;",
function(err, result) {
if (err)
throw err;
});
return result;
}
For example, if I store the "result" in a static variable, it works, but I only get the word the second time I query it, because the inner function is asynchronous, and therefore returns the word "pending" the first time. I would need something like a fetch, which I specify before the function, which waits for the value of the database and then returns the value to me.