Reading one database row needs a defined ordering when more than one row matches. An absent match also deserves an explicit branch.
Worked example
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 name FROM jobs WHERE id=?").get(2));Result
[Object: null prototype] { name: 'test' }Implementation notes
A single-row accessor and a full result list have different missing-result behaviour. Normalize that difference at the repository boundary.
Try it yourself
Add two matching rows and run a query with a stable sort.
Open the Node.js example →Editorial date September 11, 2025 · Published December 6, 2026