sqlite with wasm binding using indexedDB as a data store
Usage
npm i sqlite-idb
import { Sqlite, version } from "sqlite-idb";// When using Vite// import wasmUrl from 'sqlite-idb/lib/sqlite/wasm/wa-sqlite-async.wasm?url';const main = async () => { const { sql, createFunction } = await Sqlite({ idbName: "myIndexedDB", dbName: "myDb", // uncompressed: true, // Out out of IndexedDB compression locateFile: (file) => { return `https://esm.sh/sqlite-idb@${version}/lib/sqlite/wasm/${file}`; }, // When using Vite // locateFile: () => wasmUrl, }); // query1 has type Record<string, ColumnType>[] const query1 =
You can also import existing sqlite databases:
import { Sqlite } from "sqlite-idb";const main = async () => { const { sql, importDatabase } = await Sqlite(/* ... */); const response = await fetch("/db.sqlite"); if (response.ok && response.body) { await importDatabase(response.body); } console.log(await sql.rows`SELECT * FROM users`);};