docs: clarification on minimal example with full error handling
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js, postgresql
- Lĩnh vực
- databases, documentation
Hướng nghiên cứu
Bắt đầu bằng việc xem lại các phần tài liệu hiện có bao quát Client, Pool, connect, query, end và error events. So sánh các phần đó với hai ví dụ tối thiểu trong issue; tài liệu được hoàn thiện khi giải thích rõ hành vi liên quan đến việc xử lý lỗi và những đánh đổi khi sử dụng Client hoặc Pool cho một truy vấn duy nhất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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!
- Ngôn ngữ chính
- JavaScript
- Star
- 13.2k
- Fork
- 1.4k
- Merge trung bình
- 6 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 6
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của brianc/node-postgres
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
brianc/node-postgres#3770 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
brianc/node-postgres#3716 · 1 bình luận ·
-
# remove bring your own promise Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
brianc/node-postgres#3631 · 1 bình luận ·
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 62/100
brianc/node-postgres#2857 ·
-
can't view docs for old versions Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
brianc/node-postgres#2433 ·
Tất cả issue của brianc/node-postgres
Issue tương tự
-
Update HugeIcons library Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
antfu-collective/icones#398 ·
-
ECmail.com Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
wesbos/burner-email-providers#554 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
radiantearth/stac-browser#1023 ·
-
HMR stops working Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
components-web-app/docs#92 ·