Sto cercando di inserire un paio di milioni di record (con circa 6 campi/colonne) ricevendo richieste dai client 10.000 record per tentativo di inserimento di massa (utilizzando sequelize
.js e bulkCreate()
)Come eseguire lo streaming di un array JSON da NodeJS a postgres
Questo ovviamente era una cattiva idea, così ho provato a guardare in node-pg-copy-streams
Tuttavia, io non voglio avviare un cambiamento sul lato client, in cui una matrice jSON viene inviato come tale
# python
data = [
{
"column a":"a values",
"column b":"b values",
},
...
# 10,000 items
...
]
request.post(data=json.dumps(data), url=url)
Sul lato server in nodejs, come faccio a trasmettere lo request.body
ricevuto nello scheletro seguente?
.post(function(req, res){
// old sequelize code
/* table5.bulkCreate(
req.body, {raw:true}
).then(function(){
return table5.findAll();
}).then(function(result){
res.json(result.count);
});*/
// new pg-copy-streams code
pg.connect(function(err, client, done) {
var stream = client.query(copyFrom('COPY my_table FROM STDIN'));
// My question is here, how would I stream or pipe the request body ?
// ?.on('error', done);
// ?.pipe(stream).on('finish', done).on('error', done);
});
});
prega fatemi sapere come posso migliorare questa domanda, questo probabilmente è la mia prima domanda o prima domanda sempre – Sri
Attualmente sto cercando in come trasmettere una stringa o un array. – Sri
postgres copy definisce tre formati ammessi sull'input: text, csv e binary. Non sono un esperto ma i formati sono descritti qui: http://www.postgresql.org/docs/9.3/static/sql-copy.html (Ricerca per "Formati di file" titolo) – thst