Registry / database / sql.js-fts5

sql.js-fts5

JSON →
library1.4.0jsnpmunverified

sql.js is a pure JavaScript SQLite library compiled with Emscripten, allowing SQL database operations directly in the browser or Node.js without native dependencies. Current stable version is 1.11.0 (as of early 2025), with regular releases. It supports full SQLite syntax, prepared statements, transaction support, and exports database as Uint8Array. Unlike native SQLite bindings (e.g., better-sqlite3), sql.js works entirely in memory and requires loading a .wasm file. It is ideal for client-side web apps, offline tools, and scenarios where native modules cannot be used. The library is MIT licensed and community-maintained.

npm install sql.js-fts5
INSTALL
IMPORT
SIG · SQL.JS-FTS5
S
sql.js-fts5
databasejavascriptv1.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

initSqlJs
const initSqlJs = require('sql.js');
import initSqlJs from 'sql.js';
Default export is a factory function. ESM import is not supported; use CommonJS or dynamic import.
Database
const db = new SQL.Database();
const db = new Database();
Database is a property of the initialized module, not a standalone export.
Statement
const stmt = db.prepare('SELECT ?');
const stmt = new SQL.Statement(db);
Statement objects are created via Database.prepare(), not directly instantiated.

Shows asynchronous initialization, database creation, prepared statements, and query execution.

const initSqlJs = require('sql.js'); const SQL = await initSqlJs({ locateFile: file => `https://sql.js.org/dist/${file}` }); const db = new SQL.Database(); db.run('CREATE TABLE test (id int, name text)'); db.run('INSERT INTO test VALUES (?,?)', [1, 'hello']); const stmt = db.prepare('SELECT * FROM test'); while (stmt.step()) console.log(stmt.getAsObject()); db.close();
Debug
Known issues
gotchaWASM binary must be loaded separately; locateFile is required in browsers
fix
Provide locateFile in initSqlJs config pointing to the .wasm file, or copy the file from node_modules.
affects: >=1.0.0
gotchaDatabase exists only in memory; changes are lost unless explicitly exported
fix
Call db.export() to get Uint8Array, and save it to disk or localStorage.
affects: >=1.0.0
deprecatedIn-memory only, no direct file write support
fix
For file persistence, use native SQLite bindings like better-sqlite3.
affects: >=1.0.0
gotchaStatement object must be freed manually to avoid memory leaks
fix
Call stmt.free() after use, especially in long-running applications.
affects: >=1.0.0
gotchaThread-safety: not safe to share a Database across Web Workers without cloning
fix
Create separate Database instances per worker or use structured cloning.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'Database' of undefined
Using SQL.Database before initSqlJs resolves
fix
Wait for initSqlJs to complete and pass the module to an async function.
Error: cannot locate the wasm file
locateFile not configured or incorrect path
fix
Provide locateFile option in initSqlJs config pointing to the .wasm file.
Error: Database is closed
Trying to use a database after calling db.close()
fix
Do not reuse closed database; create a new instance if needed.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
18
Meta
2
OpenAI (training)
1
Resources
sql.js-fts5 — npm install sql.js-fts5 · libregistry