0

Im new to node JS, Im buidling a custom query system that should return information from the Mysql Database when the user type question in a natural language form.

For the DB Part I have the following code:

con.CustomQuery = function(SQL){
console.log("Custom Query");
con.query(SQL, function (err, result,fields) {
    if (err) throw err;
    console.log(result);
    var res = JSON.parse(JSON.stringify(result));
    return res;
});
}

The fields names and values are dynamic, how can I retrieve the names of the returned fields? How can I turn the result into a normal string ?

thanks

Neon67
  • 41
  • 1
  • 9
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – CertainPerformance Jan 01 '19 at 22:44
  • You'll have to put all the operations that depend on the result in the callback. If it's an object and you want to iterate over its keys/values, use `Object.entries` – CertainPerformance Jan 01 '19 at 22:46
  • Do you have a code example for this ? – Neon67 Jan 02 '19 at 14:28

0 Answers0