我一直在为NodeJS和Restify实现MySQL,并且在查询方面一切都工作得很好。但是,当我想使用通过事务更新数据的功能时,出现以下错误:错误:调用退出后无法使查询入队。
这是跟踪:
(node:10877) UnhandledPromiseRejectionWarning: Error: Cannot enqueue Query after invoking quit. at Protocol._validateEnqueue (/home/node_modules/mysql/lib/protocol/Protocol.js:215:16) at Protocol._enqueue (/home/node_modules/mysql/lib/protocol/Protocol.js:138:13) at Connection.query (/home/node_modules/mysql/lib/Connection.js:201:25) at Connection.beginTransaction (/home/node_modules/mysql/lib/Connection.js:154:15) at Promise (/home/app/mysql/repository/ClientDao.ts:56:23) at new Promise (
) at ClientDao.updateIps (/home/app/mysql/repository/ClientDao.ts:55:16) at /home/app/routes/ips/put.ts:22:31 at Generator.next (
) at fulfilled (/home/app/routes/ips/put.ts:5:58) 这是代码:
this.conn.connect(); return new Promise
((resolve, reject) => { this.conn.beginTransaction( (err) => { if(err) { reject(err); return; } this.conn.query('UPDATE client SET ips_allowed = ? WHERE id = ?', [ips, client.id], (error, results, fields) => { if(error) { return this.conn.rollback(() => reject(error)); } this.conn.commit((error) => { if(error) { return this.conn.rollback(() => reject(error)); } this.conn.end(); }); });
});
});
如果有人可以帮助我看到错误,我将非常感谢。就像我之前说过的,只有在交易中才会发生这种情况。