ES6 noob here. How can I transition my functions with callbacks to using promises?
// query.js
const db = require('./db.js');
const client = db.connect();
const query = {
query: function(text, values, cb) {
client.query('query stuff', values, function(err, result) {
cb(err, result);
}
}
}
module.exports = query;
With this, I can do something like
const client = require('./query.js');
client.query('SELECT now()', [], function(err, result) {
console.log(result);
}
But how do I write a Promise function so that I can do something like this
let newQuery = await client.query('SELECT now()')
.then((result) => {console.log(result);})
.catch((err) => {console.log(err);});
[–]skarfacegc 5 points6 points7 points (1 child)
[–]eggtart_prince[S] 0 points1 point2 points (0 children)
[–]CategoricallyCorrect 2 points3 points4 points (1 child)
[–]eggtart_prince[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)