Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda