brianc / node-pg-cursor

Query cursor extension for node-postgres
78 stars 30 forks source link

Redshift: anyone knows? #45

Open unlucio opened 6 years ago

unlucio commented 6 years ago

Hello, I was trying to use this against a redshift instance with the following test script:

const { Pool } = require('pg');
const config = require('./src/lib/config');
const credentials = config.get('warehousedb');

const pool = new Pool({
    user: credentials.user,
    host: credentials.host,
    database: credentials.name,
    password: credentials.pass,
    port: credentials.port
});

function consumeCursor(cursor, cb, done) {
    console.log('consumeCursor invocation');
    cursor.read(100, (error, rows) => {
        if (error) {
            done(error);
            return;
        }

        if (rows.length < 1 ) {
            console.log('Cursor is empty, all done!');
            done();
            return;
        }

        cb(rows);
        consumeCursor(cursor, cb, done);
    });
}

const query = 'select * from <table_name> LIMIT 1000';

pool.connect().then(function(client) {
    console.log('creating cursor');
    const cursor = client.query(new Cursor(query));

    function done(error) {
        if (error) {
            console.error('Cursor boom: ', error);
        }

        console.log('done!');
        cursor.close(() => client.release());
    }

    function push(result = []) {
        console.log('Got results: ', result.length);
    }

    consumeCursor(cursor, push, done);
});

and behold of the result:

creating cursor
consumeCursor invocation
Got results:  1000
consumeCursor invocation
Cursor is empty, all done!
done!

So here's what's confusing me:

I haven't got any time yet to read node-pg-cursor yet so I def might be miss-understanding something, so apologie for something I might have missed.

unlucio commented 6 years ago

ok, seems like this might be the answer to my questions https://github.com/brianc/node-pg-cursor/blob/master/index.js#L138 :/ 🤷‍♂️

unlucio commented 5 years ago

I assume no one else is interested in a redshift support?

mikl commented 5 years ago

@unlucio did you see #14? PR #44 might solve your problem.

ysfdev commented 5 years ago

Hi,

It's any of the maintainers planning to merge PR #44? I also tested locally and the new changes from #44 seems to fix the Streaming issues.