Giter VIP home page Giter VIP logo

Comments (3)

ZJONSSON avatar ZJONSSON commented on September 10, 2024

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

from node-etl.

stevenluoxiaohua avatar stevenluoxiaohua commented on September 10, 2024

thanks,
It works ok, code as follows

`var pool = mysql.createPool({
host: 'localhost',
port: '3306',

database: 'gss'

});

var p = etl.mysql.execute(pool);

p.stream('select * from test')
.pipe(csvWriter({
separator: ',',
newline: '\n',
headers: undefined,
sendHeaders: false
}))
.pipe(etl.toFile('txt/text.txt'))
.promise()
.then(function () {
console.log('done')
});`

now, I try insert to database using mysql

from node-etl.

ZJONSSON avatar ZJONSSON commented on September 10, 2024

see #31 for the other question

from node-etl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.