Q:

Getting an array of all rows in a MySQL table that meet a criteria

I am working on a discord.js bot and so I am working in Node.Js. What I need to do is search through my MySQL table and get all rows that meet a criteria (which I can do) and then return the value in first column of all those rows meeting said criteria. I have tried multiple different methods, but my main issue is I can't return that value. I can console.log it from within my query, but I really need to return it.
function fetchOrders(status){
    textr = con.query(`SELECT * FROM orders WHERE OStatus = '${status}';`, function(err,rows) {
                if(err){
                    throw err
                }
                var text = "";
                if(rows.length<1){
                    text = "None"
                }else{
                    for(i=0;i<rows.length;i++){
                        text = text + "`" + rows[i].OID.toString() + "`, "
                    }
                }
                if(text===""){
                    text = "None"
                }
                return text;
            })
    return textr    
}

The value text is what I need (up to return text; it works perfectly), but when I return it textr is not text. If someone could tell me how to get text out of my query, I would be very grateful.

A:

Convert this function to be promise style like this
function fetchOrders(status) {
  return Promise((resolve, reject) => {
    con.query(`SELECT * FROM orders WHERE OStatus = '${status}';`, function(
      err,
      rows
    ) {
      if (err) {
        reject(err);
      }
      var text = "";
      if (rows.length < 1) {
        text = "None";
      } else {
        for (i = 0; i < rows.length; i++) {
          text = text + "`" + rows[i].OID.toString() + "`, ";
        }
      }
      if (text === "") {
        text = "None";
      }
      resolve(text);
    });
  });
}

and call it like this
fetchOrders
  .then(result => {
    console.log(result);
  })

OR
const response = await fetchOrders();

