-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: clarification on minimal example with full error handling #3328
Comments
Yes, in the current version of pg, both examples need
It’s perfectly fine to use |
@charmander Thanks for the response, just a quick follow-up / double confirmation. The docs say:
Are you saying the following is possible? await client.connect();
// an error could be emitted here on the client that would NOT be forwarded to either `connect` or `query`?
try {
await client.query('SELECT $1::text as message', ['Hello world!']);
// or an error could be emitted here after query but before end is called?
} finally {
await client.end();
} I assumed since we're calling
Are you saying it's possible for the |
Your “here” and “between” might not be pedantically correct (it’s more like “during” the
No. Catching errors for the entire block is fine. |
Yeah, I was oversimplifying with the before/after and here/between :D but the key thing was not realizing it was possible for some things to be emitted no matter what, I assumed there was a possible way to write the code that guaranteed they would come through as rejected promises, but that isn't the case, so an error listener is always required no matter what. And 👍 for the second part. That was everything, feel free to close this out if you want. If I get some spare time, I might try to send a tiny PR just to make that a little more explicit it in the docs if you're open to it, otherwise that clears everything up for me! |
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:Pool
example:My couple questions:
error
, or because I'm callingconnect
->query
->end
directly after each other, is it not possible for anerror
event 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 anerror
event to be emitted between say theconnect
andquery
calls, etc.Pool
even 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 toPool
overClient
make sense?Thanks for any info/help!
The text was updated successfully, but these errors were encountered: