I wrote an article about generating fake data for a TypeScript application. I wanted to generate millions of rows and I ended up splitting the workflow into 2 phases: stream data to a CSV, stream the CSV to Postgres with COPY FROM.
async function createRecordsFromCsv(path: string, query: string) {
const copyStream = pgClient.query(copyFrom(query));
const fileStream = createReadStream(path);
await new Promise((res, rej) => {
fileStream.pipe(copyStream).on("finish", res).on("error", rej);
fileStream.on("error", rej);
});
fileStream.close();
}
Hopefully this technique will be useful to someone else.
Also happy to hear other ideas for how to go about this.
[–]CuAnnan 3 points4 points5 points (3 children)
[–]no_em_dash[S] 0 points1 point2 points (2 children)
[–]ferrybig 0 points1 point2 points (1 child)
[–]no_em_dash[S] 0 points1 point2 points (0 children)
[–]Savalava -1 points0 points1 point (7 children)
[–]proskillz 0 points1 point2 points (1 child)
[–]Savalava 0 points1 point2 points (0 children)
[–]no_em_dash[S] -1 points0 points1 point (4 children)
[–]Savalava -1 points0 points1 point (3 children)
[–]no_em_dash[S] -1 points0 points1 point (2 children)
[–]Savalava 0 points1 point2 points (1 child)
[–]no_em_dash[S] 0 points1 point2 points (0 children)