SQL parameter binding
A database driver sends SQL and receives result rows. Parameter binding keeps supplied values separate from the query text. It also makes the intended value positions explicit. SQLite uses `?` placeholders in this example; PostgreSQL through pg commonly uses `$1`, `$2` and a values array. A placeholder is for a value, not a table name or an ORDER BY column. Choose dynamic identifiers from an allowlist of fixed SQL fragments. In the actual in-memory SQLite fixture, a primary key identifies each book and a prepared statement selects one row by title. The synchronous DatabaseSync API blocks the calling JavaScript thread during operations; do not infer async PostgreSQL performance from this example. Do not concatenate external strings into SQL or use binding as a substitute for authorization. Even a safe query must restrict results to records the caller may see. Evidence: Actual local SQLite 3.49.1 via experimental node:sqlite. Source: https://nodejs.org/download/release/v22.16.0/docs/api/sqlite.html
Formal Syntax & Structure
See example for the scoped contractWorking Example
import {DatabaseSync} from 'node:sqlite';const db = new DatabaseSync(':memory:');try { db.exec('CREATE TABLE book(id INTEGER PRIMARY KEY, title TEXT NOT NULL)'); const insert=db.prepare('INSERT INTO book VALUES (?,?)'); insert.run(1,"Reader's Guide"); insert.run(2,'Rivers'); const find=db.prepare('SELECT id FROM book WHERE title = ?'); console.log(find.get("Reader's Guide").id); console.log(find.get('Missing') === undefined);} finally {db.close();}