简体   繁体   English

node js如何查看查询是否使用pg成功执行?

[英]node js how can I see if the query executes successfully with pg?

It is possible in pg that I can see if this query can return true or false that I know If the query executed successfully or not:在 pg 中我可以看到这个查询是否可以返回我知道的 true 或 false 查询是否成功执行:

const TrueOrFalse = await db.query('INSERT INTO users (email,password) VALUES ($1, $2);', [email, password]);

This is from the documentation:这是来自文档:

try {
  const res = await client.query(text, values)
  console.log(res.rows[0])
  // { name: 'brianc', email: 'brian.m.carlson@gmail.com' }
} catch (err) {
  console.log(err.stack)
}

So yes, it succeeded if it didn't throw an exception.所以是的,如果它没有抛出异常,它就会成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM