gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:56:00 25 4
gpt4 key购买 nike

我在使用 node-postgres 时遇到问题.

select、insert、delete都成功执行了数据库查询,但是在 Node 服务器上insert和delete触发了这个错误:

/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});
});
});

知道是什么原因造成的吗?

最佳答案

解决方案是升级到 4.4.1。

关于node.js - node-postgres: done() - undefined 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31815590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com