node.js - 错误:在 BoundPool.end 上多次调用池结束
问题描述
当我尝试使用 pg-promise 从 PostgreSQL 获取数据时,它会抛出一个错误
错误:在 Database.pool.end.cb (/workspace/node_modules/pg-promise/lib) 的 BoundPool.end (/workspace/node_modules/pg-pool/index.js:381:19) 上多次调用池结束/database.js:133:31)
app.get("/route/:id", async (req: any, res: any) => {
const key = req.params.id;
let status: number;
let response: any = {};
console.log(key);
await db.any('SELECT * FROM "schema"."my_table" WHERE key = $1', [key])
.then(data => {
status = 200;
response = {
'status': 'success',
'data': JSON.stringify(data)
}
})
.catch(error => {
status = 406;
response = {
'status': 'failed',
'error': error.message,
'errorCode': error.code
}
})
.finally(db.$pool.end);
res.status(status).send(response);
});
我应该什么时候结束连接池?响应成功时会自动结束吗?
解决方案
推荐阅读
- flutter - 在 Canvas 上渲染 Flutter 小部件 - CustomPainter
- html - MacOS 仅问题隐藏 Office 365 / Outlook 2016 的 HTML 电子邮件
- postscript - 未应用 Postscript 剪切路径
- powershell - AzureAD 应用程序需要哪些权限才能从 AzureAdPreview 模块 (Powershell) 运行命令 Add-AzureADServicePrincipalPolicy?
- javascript - 拆分和解析xml数据
- java - jUnit 不会抛出预期的异常
- postman - 使用 Postman POST 到 Sentry
- amazon-web-services - API 网关未返回正确的模板
- entity-framework - 多对多 - 实体框架核心 Where 子句
- java - 使用 Jackson 将 CSV 转换为 JSON - 如何删除嵌入在 CSV 列标题中的换行符