Skip to content

Instantly share code, notes, and snippets.

@cjpartridgeb
Created June 21, 2013 06:58
Show Gist options
  • Save cjpartridgeb/5829385 to your computer and use it in GitHub Desktop.
Save cjpartridgeb/5829385 to your computer and use it in GitHub Desktop.
for yalamber
function export_connect_csv(user_id, res){
ConnectModel.mysqlPool.getConnection(function(err, connection){
res.header('Content-Type', 'text/csv');
var csv_header_row = "Email,First Name,Last Name,Status,Created\n";
res.write(csv_header_row);
var query = connection.query('SELECT * FROM connects where user_id = ? AND deleted = 0', [user_id]);
query
.on('error', function(err) {
//handle error
})
.on('fields', function(fields) {
})
.on('result', function(row) {
var csv_row = row.email+','+row.first_name+','+row.last_name+','+row.status+','+row.created+"\n";
res.write(csv_row);
})
.on('end', function() {
res.end('', function(){
//no need to email them now! :)
console.log('done');
});
});
});
}
Connect.prototype.exportConnect = function(req, res){
var user_id = req.params.user_id || 0;
export_connect_csv(user_id, res);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment