Dev Helpers
← Back

Read the first matching row

Read the first matching row using Node.js.

Open this example in the interactive library

Source code

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));

Sample output

[Object: null prototype] { name: 'test' }