我正在使用pg-pool
. 但是,我在将查询结果发送到前端时遇到了麻烦。我以为我可以res.send
像往常一样使用,但它不被识别(我也尝试过return
)。这是我的功能:
exports.featList = function (req, res) {
pool.connect(function(err, client, done) {
if (err) {
return console.error('error fetching client from pool', err);
}
client.query('SELECT * FROM book WHERE featured=true', function (err,res) {
var json = JSON.stringify(res.rows);
return json;
client.release();
});
});