Better-sqlite3: Opening an Iterator, stop processing it and closing the database results in Error

Created on 5 Nov 2017  路  2Comments  路  Source: JoshuaWise/better-sqlite3

Requesting an Iterator, stop processing it and closing the database results in an error:

This database connection is busy executing a query.

Which is the correct way to abort an iteration?

question

Most helpful comment

Use iterator.return().

var stmt = db.prepare('SELECT * FROM my_table');
var iterator = stmt.iterate();
var { value } = iterator.next();
iterator.return(); // this will close the iterator
db.close();

If you use a for of loop, it will automatically call iterator.return() when you exit the loop (via a break, return, throw, etc.). These features are only supported in Node.js 6+

All 2 comments

Use iterator.return().

var stmt = db.prepare('SELECT * FROM my_table');
var iterator = stmt.iterate();
var { value } = iterator.next();
iterator.return(); // this will close the iterator
db.close();

If you use a for of loop, it will automatically call iterator.return() when you exit the loop (via a break, return, throw, etc.). These features are only supported in Node.js 6+

Thank you. I'm using Kotlin, so no JavaScript syntax at all. When an exception is thrown return isn't called in Kotlin.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DrDonkeyPunch picture DrDonkeyPunch  路  5Comments

imtbl picture imtbl  路  6Comments

focussing picture focussing  路  4Comments

Alon-L picture Alon-L  路  5Comments

Babalon921 picture Babalon921  路  3Comments