Node.js 使用客户端进行嵌套查询
我正在进行一个查询,根据查询结果,我想进行另一个查询。我的代码如下所示:Node.js 使用客户端进行嵌套查询,node.js,postgresql,Node.js,Postgresql,我正在进行一个查询,根据查询结果,我想进行另一个查询。我的代码如下所示: client.query(Q1, (err, res2) => { if (condition(res2)) { client.query(Q2), (err, res3) => { console.log(res3) } } else { console.log("Condition not fulfilled&
client.query(Q1, (err, res2) => {
if (condition(res2)) {
client.query(Q2), (err, res3) => {
console.log(res3)
}
} else {
console.log("Condition not fulfilled")
}
})
两个查询都会生效,但从不记录
res3
。我做错了什么,我该如何解决这个问题?您在client.query(Q2),(err,res3)=>{
这应该是:
client.query(Q2, (err, res3) => {
您正在执行
client.query(Q2);(…)=>{…};
。您应该执行client.query(Q2,(…)=>{…});