gpt4 book ai didi

javascript - 当我的查询结果 rowCount 为 0 时,如何检查 Node js 中的响应抛出错误

转载 作者:行者123 更新时间:2023-12-02 14:44:37 24 4
gpt4 key购买 nike

如果我的行数为 o,我需要在 res 上发送失败。如果我的行数是 1 我需要将资源状态发送为成功。请帮助我。当我 尝试以 json 形式打印(client.query)(结果 附图)

enter image description here

var query = client.query("select * from pp_user_profile where email_id  = '"+req.query.email_id+"' and user_password= '"+req.query.user_password+"'");

console.log(client.query);
query.on("end", function (result) {
if (result.length > 0) {
if (result)
console.log("Test:" + result);
res.write('Failed');
}
else{
console.log(result);
client.end();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Success');
res.end();
}

最佳答案

将 if...else 条件更改为这种方式。

if(result.rowCount === 1){
// your code goes here
}
else{
// your code goes here
}

关于javascript - 当我的查询结果 rowCount 为 0 时,如何检查 Node js 中的响应抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36711539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com