You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the correct way of iterating over the results one at a time without having to load large dataset in memory? It's giving an error while trying to use for of:
import { Database } from "jsr:@db/[email protected]";
// Setup and insert data
const db = new Database(":memory:");
// Create simple table
db.exec(`
CREATE TABLE test (
id INTEGER PRIMARY KEY,
value TEXT
);
`);
// Insert test data
const stmt = db.prepare("INSERT INTO test (value) VALUES (?)");
stmt.run("value1");
stmt.run("value2");
stmt.run("value3");
stmt.finalize();
// Method 1: Works fine with .all()
console.log("Testing .all():");
const rows = db.prepare("SELECT * FROM test").all();
console.log(rows);
// Method 2: Will error when using for..of
console.log("\nTesting for..of:");
try {
const stmt2 = db.prepare("SELECT * FROM test where id > ?");
stmt2.bind(0);
for (const row of stmt2) {
console.log(row);
}
stmt2.finalize();
} catch (e) {
console.error("Error occurred:", e);
}
db.close();
What is the correct way of iterating over the results one at a time without having to load large dataset in memory? It's giving an error while trying to use for of:
Console log:
The text was updated successfully, but these errors were encountered: