基本上,我试图在nodejs中使用POST返回查询的数据。我能够返回数据,但是它不返回查询的值。相反,它不需要发送数据。如何从查询中获取值并将其以json格式发送?
router.post('/status', function(req, httpres, next){
const spf_id = req.body.Spf_id;
console.log("This is id",req.body.Status)
pool.query("SELECT s.spf_id ,s.status_id , m.status_id ,l.status_id , su.status_id ,c.status_id FROM sales as s INNER JOIN manager as m ON m.spf_id = s.spf_id INNER JOIN logistics as l ON l.spf_id = s.spf_id INNER JOIN support as su ON su.spf_id = s.spf_id INNER JOIN collection as c ON c.spf_id = s.spf_id WHERE s.spf_id = '"+spf_id+"'")
.subscribe(
data => {
console.log("this is status",data.rows[0])
return httpres.send(data);;
//return httpres.status(200).send({ "Body" : Status_id['status'] })...
//Multiple objects have to be returned
}, err => {
httpres.send('error',err);
})
});
返回的内容:
它返回6个字段,这正是我所需要的。但是这些字段中的值是错误的。
Object { command: "SELECT", rowCount: 0, oid: null, rows: [], fields: (6) […], _parsers: (6) […], rowAsArray: false }