Skip to content

Instantly share code, notes, and snippets.

@manelet
Last active December 13, 2018 14:28
Show Gist options
  • Save manelet/93c8cbb8a5dc760801fd7d8f7ccb833c to your computer and use it in GitHub Desktop.
Save manelet/93c8cbb8a5dc760801fd7d8f7ccb833c to your computer and use it in GitHub Desktop.
Streams MySQL
const { stream } = require('@apartum/mysql-wrapper')(require('./config'))
const writeStream = require('fs').createWriteStream('./src/hola.txt')
const Transform = require('stream').Transform
const transformStream = new Transform({
objectMode: true,
highWatermark: 1,
transform (chunk, encoding, done) {
chunk.es = 'ASDASDASD'
// this.push(JSON.stringify(chunk))
done(null, JSON.stringify(chunk))
}
})
async function start () {
stream('SELECT * FROM countries')
.pipe(transformStream)
.pipe(writeStream)
}
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment