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.
const stream = pool.query(copyFrom(query))
stream.on // undefined :(
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 examples don't make reference to this at all, but reading through the pg docs, there is a convenience utility on pool called
querythat 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 1as 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.