node-etl icon indicating copy to clipboard operation
node-etl copied to clipboard

How to insert a csv file into mysql without headers?

Open stevenluoxiaohua opened this issue 10 years ago • 3 comments

I want insert a csv file into mysql table, this file without headers

stevenluoxiaohua avatar Aug 01 '16 07:08 stevenluoxiaohua

There is a simple example in the docs here

Here is another version:

fs.createReadStream('test,csv')
  .pipe(etl.csv())
  .pipe(etl.mysql.upsert(client,'myschema','mytable',{maxBufffer: 100000))

the etl.mysql.upsert is syntax sugar for a sub-chain of etl.mysql.script that adds incoming packet to a bulk upsert command (until maxbuffer is reached) and etl.execute which executes all incoming sql commands (the bulkupdates scripted in previous step).

It's worth noting that the etl.mysql.script fetches all the column names from the table schema and only includes fields from incoming packets that match the database fields (case sensitive)

ZJONSSON avatar Aug 01 '16 23:08 ZJONSSON

Thanks for you reply. Now, I have anther problem. the csv-write-stream is so slow when I convert a large json object (over 2,000,000 rows).

PS:This project is very valuable, thanks for share.

stevenluoxiaohua avatar Aug 02 '16 12:08 stevenluoxiaohua

You should try:

  • Increase the maxBuffer (builds larger queries)
  • Make sure that your client is the mysql pool with a nice connectionLimit for parallel upserts

ZJONSSON avatar Aug 02 '16 12:08 ZJONSSON