Registry / database / sql-wasm

sql-wasm

JSON →
library1.1.4jsnpmunverified

SQLite compiled to WebAssembly via Emscripten, version 1.1.4. Provides a synchronous-like API for running SQL queries in both browser and Node.js environments with minimal overhead. Unlike the more common sql.js, sql-wasm requires asynchronous initialization by fetching the .wasm file from network or filesystem, and omits Web Worker support. It ships TypeScript types and aims to be a drop-in replacement with a nearly identical API. Release cadence is low; primarily a port of sql.js with active maintenance.

npm install sql-wasm
INSTALL
IMPORT
SIG · SQL-WASM
S
sql-wasm
databasejavascriptv1.1.4
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.

createSqlWasm
import createSqlWasm from 'sql-wasm'
import { createSqlWasm } from 'sql-wasm'
The default export is a factory function that returns a SQL.js-like API object. Named import will fail.
Database
import createSqlWasm from 'sql-wasm'; const sql = await createSqlWasm(); const db = new sql.Database();
import { Database } from 'sql-wasm'
Database is not exported directly; it is accessed via the returned object.

Shows asynchronous initialization, creating a database, running SQL, and querying.

import createSqlWasm from 'sql-wasm'; (async () => { const sql = await createSqlWasm({ wasmUrl: '/path/to/sqlite3.wasm' }); const db = new sql.Database(); db.run("CREATE TABLE hello (a int, b char);"); db.run("INSERT INTO hello VALUES (0, 'hello');"); const res = db.exec("SELECT * FROM hello"); console.log(res); })();
Debug
Known issues
breakingThe library requires async initialization via await createSqlWasm(). Attempting to use synchronous require() or import will result in undefined sql object.
fix
Use async/await or .then() to obtain the sql instance before creating databases.
affects: >=1.0.0
gotchawasmUrl must be provided explicitly; defaults to /sqlite3.wasm (Web) or __dirname + '/sqlite3.wasm' (Node). If the file is not served or bundled, loading fails silently.
fix
Ensure the .wasm file is accessible at the expected URL or provide a custom wasmUrl.
affects: >=1.0.0
deprecatedThe API mirrors SQL.js, but Web Worker support is explicitly omitted. Do not expect Worker-related methods or imports.
fix
For Web Worker usage, use sql.js instead.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: sql.Database is not a constructor
The sql object is not yet initialized because await was not used.
fix
Ensure the factory function is awaited: const sql = await createSqlWasm();
Failed to load wasm file. 0x…
The .wasm file could not be fetched from the default or provided URL.
fix
Set correct wasmUrl (e.g., in browser use a path like '/sqlite3.wasm' or a CDN).
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
16
Meta
2
OpenAI (training)
1
Resources
sql-wasm — npm install sql-wasm · libregistry