Repository navigation
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
}
}codeis the name of SQLite's extended result code, such asSQLITE_CONSTRAINT_UNIQUE.errcodeis the numeric code, such as2067.- The
Errormessage 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; // 2The 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
BigIntparameters being stored or compared asTEXTwill now seeINTEGERvalues. - The new error properties are additive; the
Errormessages 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