【发布时间】:2017-04-15 14:48:39
【问题描述】:
更新
我遇到的实际问题是在我decrypt 之后将值放回响应中。我只需要知道如何在操作后将值放回response。
背景
在我的angular2 应用程序的node 一侧,我正准备将response 从api 调用发送到postgres 数据库。我需要decryptresponse 中的值之一。在文档中它显示像这样处理response,
if (err) {
console.error(err);
res.status(500).send();
return done(); // always close connection
} else {
if (result.rowCount > 0) {
decrypt(result.rows[0].myvalue);
let user = result.rows[0];
res.send(user);
return done(); // always close connection
}
问题
我无法弄清楚如何在响应中的一个值被发回之前对其进行操作。在这种情况下decrypt(user.myvalue);或解密之前放入userdecrypt(result.rows[0].myValue);
示例
如果您console.log(user.myvalue);,则会显示加密的myvalue。在response 结束之前,我需要解密myvalue。我可以这样decrypt它,
解密(result.rows[0].ssn);
问题
我如何使用decrypt(result.myvalue); decrypt 这个decrypt(result.myvalue); 以便在response decrypted 中发回用户object?
说实话,我对这种外观的工作原理感到困惑。
if (result.rowCount > 0) { // if greater than 0? Should it not always be greater than 0:
let user = result.rows[0];
回复很好。我可以在node 端毫无问题地访问数据。我只是不明白它在存储它时是如何循环的。因为result.rows[0]; 在我看来只是一个职位?我猜它只是将整个响应存储在那个位置[0];??
所以这会输出myvalue
console.log(result.rows[0].myValue);
所以我只需要decrypt 该值并将其放回原处。
【问题讨论】:
标签: node.js postgresql http angular node-postgres