Error: Stream.pipe is not a function
See original GitHub issueI tried to follow along with the example provided but when i run this code i get an error, stream.pipe is not a function. Im new to pg and nodeJS so Im not exactly sure where/how to fix this issue. This is the code i’ve been trying to run. Side note: Will running pg-query-stream allow me to use the results from the query in other js functions? Thanks, any help/advice is much appreciated.
const {Pool} = require('pg')
const QueryStream = require('pg-query-stream')
const JSONStream = require('JSONStream')
const pool = new Pool({})
const q = 'SELECT * FROM public."HexLogRecord"'
pool.connect()
var stream = pool.query(new QueryStream(q))
stream.pipe(JSONStream.stringify()).pipe(process.stdout)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
TypeError: stream.pipe is not a function · Issue #90 - GitHub
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
Read more >Pipe is not a function - Stack Overflow
I have a function that returns a stream and I want to pipe that value to another function then return it in an...
Read more >Stream | Node.js v19.3.0 Documentation
pipe () method, is to limit the buffering of data to acceptable levels such that sources and destinations of differing speeds will not...
Read more >ReadableStream.pipeThrough() - Web APIs | MDN
The pipeThrough() method of the ReadableStream interface provides a chainable way of piping the current stream through a transform stream or ...
Read more >Node.js Stream Introduction. Some definition | by La Javaness IT
Note that Pipe does not propagate errors. There is two way to handle streams errors: First is by adding an on error handler...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there a reason why pool.query couldn’t handle the query stream case? I tinkered a bit and found my self basically marrying query stream and connection handling in a way that I think should be handled by the library under the hood, but now in the user space instead.
Now it would look something like this which easily makes the code pretty cluttered and rigid:
while it could as well look like this:
try{} finally{}
does not work with query streams since stream might be still running after the promise will finish.You can use the pool but you need to check out the connection as the pool thinks the entire command is complete when the original query function returns. So use
client = await pool.connect()
and then release the connection after you finish streaming the results.