Dev Helpers
← Back

Read large integers exactly

Read large integers exactly 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(
  (() => {
    const stmt = db.prepare("SELECT 9007199254740993 AS n");
    stmt.setReadBigInts(true);
    return stmt.get().n.toString();
  })(),
);

Sample output

9007199254740993