Last active
September 29, 2015 19:15
-
-
Save evansiroky/543f672cf8390f9c1515 to your computer and use it in GitHub Desktop.
dbStreamer csv insert example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var csv = require('csv'), | |
dbStreamer = require('db-streamer'), | |
fs = require('fs'); | |
var input = fs.createReadStream(filename); | |
var parser = csv.parse({ | |
columns: true, | |
relax: true | |
}); | |
var sequelizeConfig = 'postgres://streamer:streamer@localhost:5432/streamer-test', | |
inserterConfig = { | |
dbConnString: sequelizeConfig, | |
tableName: 'test_table', | |
columns: ['a', 'b', 'c', 'createdAt', 'updatedAt'] | |
}; | |
var inserter = dbStreamer.getInserter(inserterConfig); | |
inserter.connect(function(err) { | |
parser.on('readable', function () { | |
while(line = parser.read()) { | |
inserter.push(line); | |
} | |
}); | |
parser.on('end', function (count) { | |
inserter.setEndHandler(callback); | |
inserter.end(); | |
}); | |
input.pipe(parser); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment