Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second argument to statement.each is never called.. #146

Open
freakynit opened this issue Dec 19, 2024 · 0 comments
Open

Second argument to statement.each is never called.. #146

freakynit opened this issue Dec 19, 2024 · 0 comments

Comments

@freakynit
Copy link

Problem Statement

statement.each takes 2 callbacks, first one gets called for each row, whereas 2nd one once all rows are over. This is also reflected by the underlying C code. But, on using it, it seems 2nd callback never gets called.

Test code:

import duckdb from 'duckdb';

// Create a new database instance and connect to it
const db = new duckdb.Database('./duckdb_file.duckdb', duckdb.OPEN_READWRITE);

db.serialize(() => {
    const stmt = db.prepare('SELECT * FROM table_1 limit ?');

    let count = 0;
    stmt.each(10000, (err, row) => {
        if (err) {
            console.error('Error:', err);
            return;
        }
        //console.log(row);
        count++;
    }, () => {
        console.log(`Query completed. count: ${count}`);
        // Finalize the statement when done
        stmt.finalize();
    });
});

// Close the database
db.close((err) => {
    if (err) {
        console.error('Error closing the database:', err);
    } else {
        console.log('Database closed.');
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant