Dev Helpers
← Back

Iterate a result set

Iterate a result set using Node.js.

Open this example in the interactive library

Source code

import { DatabaseSync } from "node:sqlite";
const db = new DatabaseSync(":memory:");
db.exec(
  "CREATE TABLE jobs(id INTEGER PRIMARY KEY, name TEXT); INSERT INTO jobs(name) VALUES ('build'), ('test')",
);
console.log([...db.prepare("SELECT id FROM jobs ORDER BY id").iterate()]);

Sample output

[
  [Object: null prototype] { id: 1 },
  [Object: null prototype] { id: 2 }
]