I am using the pg-promise NodeJS module. At some point, I am updating one of my database's table. I would like to know how many rows have been updated by the query, is it possible?
Below is part of my code:
var queryText = "UPDATE public.mytable SET whatever = $1 WHERE criteria1=$2 AND criteria2=$3;",
queryParam = [
value1,
value2,
value3
];
postgres.none(queryText, queryParam)
.then((value) => {
// how can I know at this point how many rows have been updated
resolve(result);
})
.catch(err => {
// it doesn't go here when zero row has been updated
reject(err);
});
Thank you!
async
function, you can also do e.g.let result = await db.result('DELETE FROM mytable WHERE criteria1 = $1', ['foo'])
– Sayres