Если мой rowcount необходимо отправить по res как не удалось. Если мой rowcount равен 1, мне нужно отправить статус res как успех. Пожалуйста, помогите мне. когда я попытался сделать print (client.query) своим приходом как json (результат на прикрепленном изображении)
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
}
Если я правильно понял ваше требование, то u должен иметь код следующим образом:
var query = client.query("select * from pp_user_profile where email_id = '"+req.query.email_id+"' and user_password= '"+req.query.user_password+"'");
query.on("end", function (result) {
if (result.rows.length === 0) {
client.end();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Failed');
res.end();
}
else{
client.end();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Success');
res.end();
}