Registry / database / fts5sqljs

fts5sqljs

JSON →
library1.12.6jsnpmunverified

SQLite compiled to JavaScript via Emscripten, enabling full SQL database operations in browsers and Node.js. Version 1.12.6 uses WebAssembly by default (falls back to asm.js), with a release cadence of several updates per year. Unlike native bindings (e.g., sqlite3), it does not require compilation and works purely in-memory, supporting import/export of SQLite database files as Uint8Array. Key differentiators: browser-native execution, no native dependencies, support for prepared statements, user-defined functions, and extension loading. Active development with ongoing maintenance.

npm install fts5sqljs
INSTALL
IMPORT
SIG · FTS5SQLJS
F
fts5sqljs
databasejavascriptv1.12.6
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
import initSqlJs from 'sql.js'
const initSqlJs = require('sql.js')
Default export is an async initializer function. Use ES module syntax for better tree-shaking.
Database
import initSqlJs from 'sql.js'; const SQL = await initSqlJs(); const db = new SQL.Database();
import { Database } from 'sql.js'
Database is not a named export; access it via the initialized SQL object.
Statement
import initSqlJs from 'sql.js'; const SQL = await initSqlJs(); const stmt = db.prepare('SELECT ?');
import { Statement } from 'sql.js'
Statement is returned from db.prepare(), not directly imported.

Create an in-memory SQLite database, run DDL and DML, and query results using prepared statements.

import initSqlJs from '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, "Alice")'); const stmt = db.prepare('SELECT * FROM test'); while (stmt.step()) { const row = stmt.getAsObject(); console.log(row); } stmt.free(); db.close();
Debug
Known issues
gotchaThe Database constructor accepts an optional Uint8Array to load an existing SQLite file, but the array must be a buffer copy; database mutations are in-memory only and not persisted unless exported.
fix
Use db.export() to get a Uint8Array and save it manually (e.g., to localStorage or a file).
affects: >=1.0.0
gotchaPrepared statements (Statement objects) must be freed manually via stmt.free() to prevent memory leaks.
fix
Call stmt.free() after finished or use db.run() for one-off queries.
affects: >=1.0.0
breakingVersion 1.0 switched from callback-based init to async initSqlJs(). Old code using initSqlJs(callback) will not work.
fix
Use await initSqlJs() or .then() pattern.
affects: <1.0.0
Errors
Common errors & fixes
Cannot find module 'sql.js'
Forgetting to install the package or using wrong import path.
fix
Run npm install sql.js and use import initSqlJs from 'sql.js'.
TypeError: SQL.Database is not a constructor
Using SQL.Database before initSqlJs() has resolved.
fix
Ensure you await initSqlJs() before accessing SQL.Database.
Unable to locate the wasm file
The locateFile option is missing or points to the wrong URL when using WebAssembly in a browser.
fix
Set locateFile: file => '/path/to/sql-wasm.wasm' or host the .wasm file.
Upgrade
Version history
1.12.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
9
Resources
fts5sqljs — npm install fts5sqljs · libregistry