Created
June 20, 2013 11:43
-
-
Save yalamber/5822091 to your computer and use it in GitHub Desktop.
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
function export_connect_csv(user_id, file_location){ | |
mysqlPool.getConnection(function(err, connection){ | |
var csv_row = "Email,First Name,Last Name,Status,Created\n"; | |
function processRow (row) { | |
var csv_row = row.email+','+row.first_name+','+row.last_name+','+row.status+','+row.created+"\n"; | |
fs.appendFile(file_location, csv_row, function (err) { | |
if(err){ | |
throw err; | |
} | |
}); | |
} | |
fs.appendFile(file_location, csv_row, function (err) { | |
if(err){ | |
throw err; | |
} | |
var query = connection.query('SELECT * FROM contacts where user_id = "'+user_id+'"'); | |
query | |
.on('error', function(err) { | |
//handle error | |
}) | |
.on('fields', function(fields) { | |
}) | |
.on('result', function(row) { | |
processRow(row); | |
}) | |
.on('end', function() { | |
//email now | |
console.log('done'); | |
}); | |
}); | |
}); | |
} | |
var exportContacts = function(req, res){ | |
var user_id = req.params.user_id || 0; | |
export_connect_csv(user_id); | |
res.json({}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment