docs: clarification on minimal example with full error handling
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, node.js, postgresql
调研方向
首先查看现有文档中涵盖 Client、Pool、connect、query、end 和 error events 的章节。将这些章节与 issue 中的两个最小示例进行比较;当文档清楚地解释相关的错误处理行为,以及针对单个查询使用 Client 或 Pool 的权衡时,文档工作就完成了。
由索引模型根据 Issue 内容生成。
描述
The docs somewhat talk about it in pieces, but it wasn't 100% clear what a minimal code example with full error handling looks like, so I was hoping to get some clarity around that. I believe the following are both minimal examples, but I have a few questions surrounding them.
Client example:
import pg from 'pg';
const client = new pg.Client();
await client.connect();
try {
await client.query('SELECT $1::text as message', ['Hello world!']);
} finally {
await client.end();
}
Pool example:
import pg from 'pg';
const pool = new pg.Pool();
try {
await pool.query('SELECT $1::text as message', ['Hello world!']);
} finally {
await pool.end();
}
My couple questions:
- Does either example need an actual event listener for
error, or because I'm callingconnect->query->enddirectly after each other, is it not possible for anerrorevent to actually be emitted? I know in normal case errors that happen during those are rejected with the promise, but I wasn't sure if it was actually possible for anerrorevent to be emitted between say theconnectandquerycalls, etc. - Is there any advantage or disadvantage to using
Pooleven if it's only a single call and will then be torn down? The only advantage I can see is it requires one less line of code since you don't need to explicitly callconnect, but I didn't know if there was other overhead or considered an antipattern*?
* I know instantiating a bunch of pools is an antipattern, but think of a usecase more akin to lambda or something, where it's not possible to keep a pool active, so I'm basically just spinning up some code, running a single query, then spinning everything down. Does using Pool have any negatives for that use case, or does defaulting to Pool over Client make sense?
Thanks for any info/help!
- 主要语言
- JavaScript
- 星标
- 13.2k
- 派生
- 1.4k
- 平均合并
- 6 天 15 小时
- 30 天内合并 PR
- 6
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
brianc/node-postgres 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
brianc/node-postgres#3770 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
brianc/node-postgres#3716 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
brianc/node-postgres#3631 · 1 条评论 ·
-
难度 1/5 1-3 小时 新手友好度 62/100
brianc/node-postgres#2857 ·
-
难度 1/5 1 小时以内 新手友好度 68/100
brianc/node-postgres#2433 ·
查看 brianc/node-postgres 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
antfu-collective/icones#398 ·
-
ECmail.com 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
wesbos/burner-email-providers#554 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
radiantearth/stac-browser#1023 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
components-web-app/docs#92 ·