0

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_id FROM room WHERE roomname = '" + room.roomname + "';",
        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 werd the second time I query it, because the inner function is asynchronous, and therefore returns the werd "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. ` getIDfromRoom(room) {

   let roomname =  db.getConnection().query("SELECT room_id FROM room WHERE roomname = '" + room.roomname + "';",
        function(err, result) {
            if (err) throw err;
        });

    return roomname;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Benno
  • 1
  • 1

0 Answers0