SQLite

statement.run()

Executes a statement and returns change metadata. An affected-row count of zero can represent an optimistic concurrency conflict. 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 0"].

Formal Syntax & Structure

nodejs syntaxnodejs
statement.run([namedParameters][, ...anonymousParameters])

Parameters & Attributes

NameTypeDescription
namedParametersobjectNamed bind values.
anonymousParametersunknown[]Positional bind values.

Return Value

object

Changes and last inserted row ID.

Working Example

Example Snippetnodejs
import { DatabaseSync } from 'node:sqlite';const db = new DatabaseSync(':memory:');try {    db.exec('CREATE TABLE item(id INTEGER PRIMARY KEY, stock INTEGER); INSERT INTO item VALUES (1,2)');    const q = db.prepare('UPDATE item SET stock=stock-1 WHERE id=? AND stock>0');    console.log(q.run(1).changes, q.run(9).changes);}finally {    db.close();}
Node.js Reference