Skip to content

Instantly share code, notes, and snippets.

@mertonium
Created September 12, 2011 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mertonium/1210513 to your computer and use it in GitHub Desktop.
Save mertonium/1210513 to your computer and use it in GitHub Desktop.
Node.js script that loads a CSV into a Couch. I used it to upload a stop_times.txt file from the Twin Cities GTFS feed.
var csv = require('csv'),
cradle = require('cradle');
var docs = [];
var successCount = 0,
failCount = 0,
curproc = 0,
throttle = 5;
var db = new(cradle.Connection)().database('msp_transit');
csv()
.fromPath(__dirname+process.argv[2], { columns: ['trip_id','arrival_time','departure_time','stop_id','stop_sequence','pickup_type','drop_off_type'] })
.on('data',function(data,index){
data.type = 'stop_time';
docs.push(data);
})
.on('end',function(count){
db.save(docs, function(err, res) {
console.error(err);
console.log(res);
console.log('Calling the view...');
db.view('app/times_by_stop', { limit : '10' }, function (err, res) {
console.log('Back from calling the view...');
console.log(err);
console.log(res);
});
});
})
.on('error',function(error){
console.log(error.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment