Created
October 29, 2019 22:06
-
-
Save issa-tseng/02a339e54382ff44733387dd3d7b514f to your computer and use it in GitHub Desktop.
This file contains 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
require('knex')({ | |
client: 'pg', | |
connection: { host: 'localhost', user: 'jubilant', password: 'jubilant', database: 'jubilant_test' } | |
}).transaction(async (db) => { | |
await db.schema.createTable('xyz', (xyz) => { | |
xyz.increments('id'); | |
}); | |
/* attempt 1 | |
for await (const row of db.select('*').from('xyz').stream()) | |
console.log(row); | |
*/ | |
/* attempt 2 | |
const stream = db.select('*').from('xyz').stream(); | |
stream.on('data', () => {}); | |
await new Promise((resolve) => { | |
stream.on('end', () => { stream.destroy(); }); | |
stream.on('close', resolve); | |
}); | |
*/ | |
/* attempt 3 | |
const { promisify } = require('util'); | |
const { pipeline, Writable } = require('stream'); | |
await promisify(pipeline)( | |
db.select('*').from('xyz').stream(), | |
new Writable({ write(_, _2, done) { done(); } }) | |
); | |
*/ | |
await db.schema.table('xyz', (xyz) => { | |
xyz.text('name'); | |
}); | |
db.rollback(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment