You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The examples don't make reference to this at all, but reading through the pg docs, there is a convenience utility on pool called query that is described here: https://node-postgres.com/apis/pool#poolquery
Often we only need to run a single query on the database, so as convenience the pool has a method to run a query on the first available idle client and return its result.
If used with pg-copy-stream, the result of the query will be a promise, not a stream.
I looked at it with a debugger on, and it looks like a pending promise... I tried to await it, and it didn't come back, even with SELECT 1 as the query.
Here's some code that can repro this:
const pool = new pg.Pool({....etc })
const stream = pool.query(copyFrom(query))
stream.setEncoding('utf-8') // stream.setEncoding is not a function
I'm not sure if this is a bug necessarily, but maybe a note somewhere in the readme would save some struggling from future devs.
The text was updated successfully, but these errors were encountered:
In fact, this pool.query issue has already been discussed in the past. cf #144 (comment)
the pool.query shorthand cannot be used with pg-query-stream because it does not handle the Submittable interface that client.query has.
my strategy was to document the async/await example explicitely using client.query but you are right that a supplementary note seems necessary to avoid this pitfall.
could you send a PR on a README modification to add the note/warning that you would have like to find and that would have avoided the issue for you ?
The examples don't make reference to this at all, but reading through the pg docs, there is a convenience utility on pool called
query
that is described here: https://node-postgres.com/apis/pool#poolqueryIf used with pg-copy-stream, the result of the query will be a promise, not a stream.
I looked at it with a debugger on, and it looks like a pending promise... I tried to await it, and it didn't come back, even with
SELECT 1
as the query.Here's some code that can repro this:
I'm not sure if this is a bug necessarily, but maybe a note somewhere in the readme would save some struggling from future devs.
The text was updated successfully, but these errors were encountered: