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

Support for Closing Statement Iterator #139

Open
azmy60 opened this issue Sep 5, 2024 · 0 comments
Open

Support for Closing Statement Iterator #139

azmy60 opened this issue Sep 5, 2024 · 0 comments

Comments

@azmy60
Copy link

azmy60 commented Sep 5, 2024

Currently, better-sqlite3 allows stopping an active iterator by calling return(). This ensures clean-up and halts further reads. Here's an example:

const stmt = db.prepare("SELECT * FROM organizations"); // This has 100k rows
const iter = stmt.iterate();
const row = iter.next();

if (cancelTriggered) {
  iter.return(); // Stop reading and perform clean-up
}

Since we don't yet support return(), an alternative is to manually exhaust the iterator:

if (cancelTriggered) {
  for (const _row of iter) {}
}

Would it be possible to add support for return() to simplify the process? Thanks!

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