node-postgres:done() - undefined不是函数

时间:2015-08-04 17:25:48

标签: node.js postgresql node-postgres

我使用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});
    });
});

知道造成这种情况的原因是什么?

1 个答案:

答案 0 :(得分:0)

解决方案正在升级到4.4.1。