SQLite
statement.iterate()
Iterates result rows without building an array up front. It is still synchronous; bound work and finish iteration before closing the connection. The synchronous API can block the event loop; the 22.16.0 module is experimental. This fixture uses an isolated in-memory database. Tested on Node.js 22.16.0. Example output (one line per entry): ["7"].
Formal Syntax & Structure
nodejs syntaxnodejs
statement.iterate([namedParameters][, ...anonymousParameters])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| namedParameters | object | Named bind values. |
| anonymousParameters | unknown[] | Positional bind values. |
Return Value
Iterator<object>
Row iterator.
Working Example
Example Snippetnodejs
import { DatabaseSync } from 'node:sqlite';const db = new DatabaseSync(':memory:');try { const q = db.prepare('SELECT 3 AS n UNION ALL SELECT 4'); let sum = 0; for (const row of q.iterate()) sum += row.n; console.log(sum);}finally { db.close();}