我使用node-postgres的查询功能有问题。
选择、插入和删除都成功执行了数据库查询,但是插入和删除在节点服务器上触发了这个错误:
/vagrant/catalog/database/db.js:11
done();
^
TypeError: undefined is not a function
at null.callback (/vagrant/catalog/database/db.js:11:17)
at p.handleReadyForQuery (/vagrant/catalog/node_modules/pg/lib/query.js:78:10)
at null.<anonymous> (/vagrant/catalog/node_modules/pg/lib/client.js:111:24)
at emit (events.js:117:20)
at Socket.<anonymous> (/vagrant/catalog/node_modules/pg/lib/connection.js:47:12)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
这是查询功能:
var pg = require('pg');
var connectionString = 'postgres://vagrant:vagrant@localhost:5432/catalog';
module.exports = {
query: function(text, values, callback) {
pg.connect(connectionString, function(err, client, done) {
client.query(text, values, function(err, result) {
if (err) throw err;
done();
callback(err, result);
});
});
}
};
端点正在调用它,例如:
app.delete(api + '/games/:id', function(req, res) {
query('DELETE FROM videogame WHERE id=$1', [req.params.id], function(err, result) {
if (err) throw err;
return res.json({'success': true});
});
});
知道是什么原因造成的吗?