Skip to content

Release v1.17.0

Latest

Choose a tag to compare

@github-actions github-actions released this 19 Nov 08:55

This release exposes SQLite's error codes and constants, and binds BigInt parameters as exact 64-bit integers.

SQLite error codes

Errors thrown by the API now include SQLite's result code, so failures can be handled without matching their message text:

try {
    db.run("INSERT INTO users (email) VALUES (?)", ["a@example.com"]);
} catch (e) {
    if (e.code === "SQLITE_CONSTRAINT_UNIQUE") {
        // the email is already taken
    }
}
  • code is the name of SQLite's extended result code, such as SQLITE_CONSTRAINT_UNIQUE.
  • errcode is the numeric code, such as 2067.
  • The Error message is unchanged.

The thrown errors are documented for each method, including Database.run, exec, each, prepare and close, and Statement.bind, step, get, getAsObject and run.

BigInt parameters

A BigInt parameter is now bound with sqlite3_bind_int64 instead of being converted to text. Values remain exact beyond Number.MAX_SAFE_INTEGER, compare as integers in SQL, and work in arithmetic. A BigInt outside the signed 64-bit range throws a RangeError.

db.run("INSERT INTO ids VALUES (?)", [BigInt("9007199254740993")]);

Reading INTEGER values as BigInt with the existing useBigInt option is unchanged.

SQLite constants

SQL.constants exposes every integer constant defined by the sqlite3.h of the SQLite version in the build:

const SQL = await initSqlJs();
SQL.constants.SQLITE_CONSTRAINT_UNIQUE; // 2067
SQL.constants.SQLITE_OPEN_READWRITE;    // 2

The constants and result-code names are generated from the SQLite header at build time, so they follow SQLite upgrades without a hand-maintained list.

Upgrade notes

  • Code that relied on BigInt parameters being stored or compared as TEXT will now see INTEGER values.
  • The new error properties are additive; the Error messages are unchanged.

CI passed on all five WebAssembly variants, the browser and worker distribution checks, and the generated documentation.

Install with npm install sql.js@1.17.0, or download a distribution below.

Full changelog: v1.16.0...v1.17.0