-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to Export to csv file? #30
Comments
A very simple example would be something like: // assuming mysql client for the select
client.query('select * from users').stream()
.pipe(etl.map(function(d) {
// if we haven't sent headers, we start by doing so
if (!this.headers)
this.headers = this.push('"'+Object.keys(d).join('","')+'"\n') || true;
return '"'+Object.keys(d).map(key => d[key]).join('","')+'"\n';
})
.pipe(etl.toFile('txt/text.txt'))
.promise()
.then(...) However this does not properly escape the fields. A safer bet would be to use something like csv-write-stream which I believe you can use like this: var csvWriter = require('csv-write-stream');
client.query('select * from users').stream()
.pipe(csvWriter())
.pipe(etl.toFile('txt/text.txt'))
.promise()
.then(...) Let me know if this works or not for you |
thanks, `var pool = mysql.createPool({
}); var p = etl.mysql.execute(pool); p.stream('select * from test') now, I try insert to database using mysql |
see #31 for the other question |
`p.stream('select * from users')
.pipe(etl.stringify(0,null,true))
.pipe(etl.toFile('txt/test.txt'))
.promise()
.then(function() {
console.log('done')
})
.catch(function(e) {
console.log('error',e);
});`
I'm try like this, but how to do next?
The text was updated successfully, but these errors were encountered: