SQLite
database.exec()
Runs fixed SQL statements without parameter binding. Use it for reviewed schema statements, not interpolated request values. 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): ["1"].
Formal Syntax & Structure
nodejs syntaxnodejs
database.exec(sql)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| sql | string | Fixed SQL statements. |
Return Value
undefined
Executes SQL.
Working Example
Example Snippetnodejs
import { DatabaseSync } from 'node:sqlite';const db = new DatabaseSync(':memory:');try { db.exec('CREATE TABLE book(id INTEGER PRIMARY KEY); INSERT INTO book VALUES (1);'); console.log(db.prepare('SELECT COUNT(*) AS n FROM book').get().n);}finally { db.close();}