Skip to content
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

Issue with pg-query-stream dest.on is not a function #2072

Closed
nhumrich opened this issue Jan 13, 2020 · 5 comments
Closed

Issue with pg-query-stream dest.on is not a function #2072

nhumrich opened this issue Jan 13, 2020 · 5 comments
Assignees

Comments

@nhumrich
Copy link

nhumrich commented Jan 13, 2020

Using the example code in pg-query-stream, you get an error that dest.on is not a function.

Here is my code:

const pg = require('pg')
const QueryStream = require('pg-query-stream')

let p = new pg.Pool({host: 'localhost', user: 'postgres', database: 'postgres'})
p.connect((err, client, done) => {
   if (err) throw err;
   const query = new QueryStream('SELECT * FROM generate_series(0, $1) num', [1000000])
   const stream = client.query(query)
   //release the client when the stream is finished
   stream.on('end', done)
   stream.pipe(console.log)
}

and I get the following error:

Uncaught TypeError: dest.on is not a function
    at PgQueryStream.Readable.pipe (_stream_readable.js:714:8)
    at PendingItem.callback (repl:7:10)
    at Pool._acquireClient (/home/nhumrich/project/node_modules/pg-pool/index.js:267:21)
    at /home/nhumrich/project/node_modules/pg-pool/index.js:230:21
    at Connection.<anonymous> (/home/nhumrich/project/node_modules/pg/lib/client.js:234:7)
    at Object.onceWrapper (events.js:411:26)
    at Connection.emit (events.js:316:22)
    at Connection.EventEmitter.emit (domain.js:545:15)

pg-query-stream version 3.0.0

@brianc
Copy link
Owner

brianc commented Jan 14, 2020

ah that should be an easy fix - I can take a look at it tomorrow. In the mean time, this should work:

const query = new QueryStream('bla bla')
client.query(query)
query.on('end', done)

basicaly pg.Client.query isn't returning the thing you pass it...that function is incredibly overloaded and I might have missed this case.

@brianc
Copy link
Owner

brianc commented Jan 15, 2020

got a bit stuck at work today - will look @ this tomorrow!

@brianc
Copy link
Owner

brianc commented Jan 15, 2020

You can't pipe a stream to console.log - you'll want to pipe to process.stdout or process.stderr - console.log is not a writable stream.

If it makes you feel better I've piped things to console.log many a time & got this error. 🤦‍♂

@brianc brianc closed this as completed Jan 15, 2020
@charmander

This comment has been minimized.

@AlexGalays
Copy link

That one caught me good as it's both wrong in the documentation and TS typings.

Only to then find out pg-query-stream is outdated and doesn't work anyway:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants