Skip to content

Instantly share code, notes, and snippets.

@evansiroky
Last active September 29, 2015 19:15
Show Gist options
  • Save evansiroky/543f672cf8390f9c1515 to your computer and use it in GitHub Desktop.
Save evansiroky/543f672cf8390f9c1515 to your computer and use it in GitHub Desktop.
dbStreamer csv insert example
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