A javascript library to run SQLite on the web.
Repo sql-js/sql.js, read from GitHub 4 h ago. sql-js has not joined Take My Repo.
This release exposes SQLite's error codes and constants, and binds BigInt parameters as exact 64-bit integers.
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.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.
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.
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.
BigInt parameters being stored or compared as TEXT will now see INTEGER values.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
This release adds SQLite's native math functions and updates SQLite to 3.54.1. Existing legacy math and string functions remain enabled by default, so existing query results are preserved.
Calling a legacy function now logs a warning. A function called for every row can produce many warnings, even for familiar names such as sqrt. Legacy functions are planned to be disabled by default in the next major release.
To try native SQLite behavior now:
const SQL = await initSqlJs({ useOldExtensionFunctions: false });
The first initialization chooses the mode for all databases from that module. For a worker, pass config: { useOldExtensionFunctions: false } on its first message.
Check your queries before opting in:
log(100) changes from the natural logarithm to 2; use ln() for the natural logarithm.NULL instead of zero. Native sign() returns an integer and works in expression indexes and generated columns.reverse, charindex, stdev, variance, and median are unavailable, including in saved views and triggers.Both modes also gain native functions including ln, log2, mod, trunc, pow, ceiling, and two-argument log.
See the migration discussion and SQLite's math function reference for details. Install with npm install sql.js@1.16.0, or download a distribution below.
Database.export() now keeps the existing database connection open, preserving update hooks, custom functions and aggregates, prepared statements/cursors, PRAGMAs, TEMP objects, attached databases and change counters. (#644)Commit or roll back an active write transaction before calling export(). Export now throws during a write transaction instead of implicitly rolling it back. Read transactions are supported. Export does not end transactions or change savepoints, including on failure.
The exported file contains only the main database. Connection-local callbacks/settings, TEMP objects and attached databases remain usable on the original connection but are not included in the exported file.
CI covers all five WebAssembly variants, browser/worker distribution checks and the new export regressions. In the recorded same-runner comparison, exporting a 577.53 MiB database took 233 ms with 21 MiB WASM memory; a 108 MiB database also exported under an enforced 64 MiB WASM cap. Performance varies by environment.
Full changelog: v1.15.1...v1.15.2
Fixes for SQL names and user-defined functions:
__proto__ in Statement.getAsObject() and Database.each() while keeping ordinary object results.__finalize cannot collide with another aggregate's internal finalizer.Regression tests reproduce all three failures on the previous implementation. Validation includes the full WebAssembly suite, distribution checks, lint, documentation generation, and the asm.js memory-growth suite.
This release adds single-file WebAssembly builds and updates SQLite from 3.49.1 to 3.54.0.
sql-wasm-inline.js and worker.sql-wasm-inline.js, with debug variants. These embed the WebAssembly binary and need no companion .wasm file or locateFile configuration.sqljs-all.zip; use the inline WebAssembly builds for single-file integration.Database.run and Database.prepare, fixing failures with SQL larger than the WebAssembly stack (#482, #639).for...of loop exits early (#457, #632).Node.js users need Node.js 18.3 or newer. WebAssembly support is required for the default and inline builds.
Full changes: v1.14.2...v1.15.0