Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
TypeORM Postgres stream not outputting anything

I'm using TypeORM=^0.2.45 and pg-query-stream=^4.2.3, but I can't seem to be getting any output from the stream:

const stream = await conn
      .getRepository(Entity)
      .createQueryBuilder("e")
      .stream();
stream.on("data", (x) => {
  console.log(123);
})
stream.on("result", (x) => {
  console.log(1234);
})

How do I get a stream to work? No output, nothing. If I do a simple getMany instead of a stream, at least I get something. The stream doesn't even execute anything; not a single log.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Got it working. Had to dig into the source code and found out you actually need to use the pg-stream-query package:

import { stringify } from "JSONStream";

function mapSync(sync) {
  return through(function write(data) {
    let mappedData;
    try {
      mappedData = sync(data);
    } catch (e) {
      return this.emit("error", e);
    }
    if (mappedData !== undefined) {
      this.emit("data", mappedData);
    }
  });
}


const stream = await conn
      .getRepository(Entity)
      .createQueryBuilder("e")
      .stream();
stream.pipe(stringify()).pipe(mapSync((data) => {
    
    data = JSON.parse(x.substring(x.indexOf("{")));
    return data;
}));

mapSync is from another library that pg-query-stream indreictly depends on.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!