libsql-js icon indicating copy to clipboard operation
libsql-js copied to clipboard

Support for Closing Statement Iterator

Open azmy60 opened this issue 1 year ago • 0 comments

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!

azmy60 avatar Sep 05 '24 16:09 azmy60