Closed sqllyw closed 3 years ago
IMHO because query is a method of connection object, read about "Using promisify() on class methods" in nodejs docs. Or just try to use util.promisify(con.query).bind(con)
thanks, bind(con) works! is there a way to promisify res.fetch? it has two callbacks
Read NodeJS documentation I cannot write every method for you.
const fb = require("firebird");
// fb.binding.FBResult.prototype.fetch[util.promisify.custom] = function(numberOrAll) { // try also this instead of next line - then it only need to be called once (not on each result)
res.fetch[util.promisify.custom] = function(numberOrAll) {
return new Promise((resolve, reject) => {
let rows = [];
this.fetch(numberOrAll, row => rows.push(row), (err, eof) => {
if(err) return reject(err);
resolve({
rows: rows,
eof: eof
});
});
});
};
let pFetch = util.promisify(res.fetch).bind(res);
if you always return all rows you may just promisify fetch to have no arguments and resolve with just rows.
Hi,
I am trying to promisify connection.query, code as follow but got error: UnhandledPromiseRejectionWarning: TypeError: Illegal invocation, any idea why? thanks