-
-
Save GregGGregGreG/581e6f05c786977e9dae80b46936ec2a to your computer and use it in GitHub Desktop.
Insert CSV using sequelize bulk insert
This file contains hidden or 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 fs = require('fs'), | |
async = require('async'), | |
csv = require('csv'); | |
var input = fs.createReadStream(filename); | |
var parser = csv.parse({ | |
columns: true, | |
relax: true | |
}); | |
var inserter = async.cargo(function(tasks, inserterCallback) { | |
model.bulkCreate(tasks).then(function() { | |
inserterCallback(); | |
} | |
); | |
}, | |
1000 | |
); | |
parser.on('readable', function () { | |
while(line = parser.read()) { | |
inserter.push(line); | |
} | |
}); | |
parser.on('end', function (count) { | |
inserter.drain = function() { | |
doneLoadingCallback(); | |
} | |
}); | |
input.pipe(parser); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment