Log specific postgresql query using pg-promise

爱⌒轻易说出口 提交于 2019-12-06 03:29:48

is there a simple way to just print the prepared query that is executed...

A query in general - yes, see below. A Prepared Query - no, those are by definition formatted on the server-side.

const query = pgp.as.format('SELECT * FROM table WHERE id = $/id/', {id: 2});
console.log(query);
db.any(query).then(...).catch(...)

And if you want to print all queries executed by your module, without using pg-monitor, simply add event query handler when initializing the library:

const initOptions = {
  query(e) {
    console.log(e.query);
  }
};
const pgp = require('pg-promise')(initOptions);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!