Registry / database / sqlite-idb

sqlite-idb

JSON →
library0.0.16jsnpmunverified

sqlite-idb (v0.0.16) is a lightweight library that runs SQLite in the browser using WebAssembly and stores the database in IndexedDB for persistence. It provides a tagged template literal API for SQL queries (sql.rows, sql.first, sql.multiple) and supports custom SQL functions via createFunction. Ships TypeScript types and aims for a minimal footprint. Release cadence is irregular. Differentiator: combines SQLite's full SQL engine with IndexedDB's persistent storage without needing a server.

npm install sqlite-idb
INSTALL
IMPORT
SIG · SQLITE-IDB
S
sqlite-idb
databasejavascriptv0.0.16
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.

Sqlite
import { Sqlite } from 'sqlite-idb'
const { Sqlite } = require('sqlite-idb')
ESM only; CommonJS require() fails because module is ESM-only.
version
import { version } from 'sqlite-idb'
const version = require('sqlite-idb/package.json').version
Exported as a string constant, avoid reading package.json manually.
importDatabase
import { Sqlite } from 'sqlite-idb'; const { importDatabase } = await Sqlite({...})
import { importDatabase } from 'sqlite-idb'
importDatabase is returned from the Sqlite() factory, not a top-level export.
createFunction
import { Sqlite } from 'sqlite-idb'; const { createFunction } = await Sqlite({...})
import { createFunction } from 'sqlite-idb'
createFunction is returned from the Sqlite() factory, not a top-level export.

Creates an in-browser SQLite database persisted in IndexedDB, runs a CREATE TABLE, INSERT, SELECT, and defines a custom SQL function.

import { Sqlite, version } from 'sqlite-idb'; const main = async () => { const { sql, createFunction } = await Sqlite({ idbName: 'testDB', dbName: 'test', locateFile: (file) => `https://esm.sh/sqlite-idb@${version}/lib/sqlite/wasm/${file}` }); await sql.rows`CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)`; await sql.rows`INSERT INTO users (name) VALUES ('Alice')`; const users = await sql.rows`SELECT * FROM users`; console.log(users); createFunction('hello', (name) => `Hello, ${name}!`); const greeting = await sql.first`SELECT hello('World') as msg`; console.log(greeting.msg); }; main().catch(console.error);
Debug
Known issues
breakingCommonJS require('sqlite-idb') fails — package is ESM-only.
fix
Use ESM imports (import/import()).
affects: >=0.0.0
gotchalocateFile must point to the correct WASM URL; default may not work in all bundlers.
fix
Provide locateFile with your own URL or use Vite's ?url import.
affects: >=0.0.0
gotchaimportDatabase expects a ReadableStream, not a file path or ArrayBuffer.
fix
Pass response.body (ReadableStream) from fetch.
affects: >=0.0.0
gotchaDatabase operations are async — forgetting await will cause silent failures.
fix
Use await before every sql.* call.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: sqlite_idb_1.Sqlite is not a constructor
Using CommonJS require with ESM-only package.
fix
Use import { Sqlite } from 'sqlite-idb' and ensure your project uses ESM.
Error: Could not locate the WebAssembly file for wa-sqlite
locateFile not provided or returns incorrect path.
fix
Set locateFile to a function that returns the correct URL for the .wasm file.
TypeError: Failed to execute 'open' on 'IDBFactory': The database name cannot be empty
IdbName not provided to Sqlite options.
fix
Pass an idbName (e.g., 'myDB') in the options object.
Upgrade
Version history
0.0.16latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
Meta
1
OpenAI (training)
1
Resources
sqlite-idb — npm install sqlite-idb · libregistry