Answer the question
In order to leave comments, you need to log in
How to execute sql query using async/await in node 7?
Let's say I'm using node-mysql from npm to run sql queries. With the advent of node 7 and its support for async / await, I would like to understand how you can apply this to execute sql queries? The task as a whole is to write a wrapper class for node-mysql, so that later you can do something like: let data = new MySqlWrapper().select(query);
well, as a result, in data we have the result of the query.
Tell me how you can implement this in this example (it does not work, we have undefined in res):
(async () => {
let getData = async ()=> {
db.query(`select * from users`,null,(err,data) =>{
console.log('ok');
return data;
});
};
var res = await getData();
//нужно чтобы в res пришли данные запроса
})();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question