Skip to content

Instantly share code, notes, and snippets.

@issa-tseng
Created October 29, 2019 22:06
Show Gist options
  • Save issa-tseng/02a339e54382ff44733387dd3d7b514f to your computer and use it in GitHub Desktop.
Save issa-tseng/02a339e54382ff44733387dd3d7b514f to your computer and use it in GitHub Desktop.
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