我使用的是TypeORM=^0.2.45和pg-query=^4.2.3,但我似乎无法从流中获得任何输出:
const stream = await conn
.getRepository(Entity)
.createQueryBuilder("e")
.stream();
stream.on("data", (x) => {
console.log(123);
})
stream.on("result", (x) => {
console.log(1234);
})我怎样才能让一条小溪工作呢?没有输出什么都没有。如果我做一个简单的getMany而不是流,至少我得到了一些东西。流甚至不执行任何东西;没有一个日志。
发布于 2022-07-16 04:40:37
开始起作用了。必须深入了解源代码,然后发现您实际上需要使用pg流查询包:
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来自另一个pg查询流令人难以置信地依赖的库。
https://stackoverflow.com/questions/72972055
复制相似问题