Gathering detailed insights and metrics for @sqlite.org/sqlite-wasm
Gathering detailed insights and metrics for @sqlite.org/sqlite-wasm
Gathering detailed insights and metrics for @sqlite.org/sqlite-wasm
Gathering detailed insights and metrics for @sqlite.org/sqlite-wasm
SQLite Wasm conveniently wrapped as an ES Module.
npm install @sqlite.org/sqlite-wasm
3.47.0-build1
Published on 23 Oct 2024
3.46.1-build5
Published on 17 Oct 2024
3.46.1-build4
Published on 14 Oct 2024
3.46.1-build3
Published on 03 Sept 2024
3.46.1-build2
Published on 02 Sept 2024
3.46.1-build1
Published on 20 Aug 2024
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
597 Stars
153 Commits
48 Forks
12 Watching
3 Branches
17 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-15.9%
974
Compared to previous day
Last week
19%
6,809
Compared to previous week
Last month
-9.8%
26,793
Compared to previous month
Last year
260.8%
330,181
Compared to previous year
SQLite Wasm conveniently wrapped as an ES Module.
[!Warning]
This project wraps the code of SQLite Wasm with no changes, apart from added TypeScript types. Please do not file issues or feature requests regarding the underlying SQLite Wasm code here. Instead, please follow the SQLite bug filing instructions. Filing TypeScript type related issues and feature requests is fine.
1npm install @sqlite.org/sqlite-wasm
There are three ways to use SQLite Wasm:
Only the worker versions allow you to use the origin private file system (OPFS) storage back-end.
[!Warning]
For this to work, you need to set the following headers on your server:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
1import { sqlite3Worker1Promiser } from '@sqlite.org/sqlite-wasm'; 2 3const log = console.log; 4const error = console.error; 5 6const initializeSQLite = async () => { 7 try { 8 log('Loading and initializing SQLite3 module...'); 9 10 const promiser = await new Promise((resolve) => { 11 const _promiser = sqlite3Worker1Promiser({ 12 onready: () => resolve(_promiser), 13 }); 14 }); 15 16 log('Done initializing. Running demo...'); 17 18 const configResponse = await promiser('config-get', {}); 19 log('Running SQLite3 version', configResponse.result.version.libVersion); 20 21 const openResponse = await promiser('open', { 22 filename: 'file:mydb.sqlite3?vfs=opfs', 23 }); 24 const { dbId } = openResponse; 25 log( 26 'OPFS is available, created persisted database at', 27 openResponse.result.filename.replace(/^file:(.*?)\?vfs=opfs$/, '$1'), 28 ); 29 // Your SQLite code here. 30 } catch (err) { 31 if (!(err instanceof Error)) { 32 err = new Error(err.result.message); 33 } 34 error(err.name, err.message); 35 } 36}; 37 38initializeSQLite();
The promiser
object above implements the
Worker1 API.
[!Warning]
For this to work, you need to set the following headers on your server:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
1// In `main.js`.
2const worker = new Worker('worker.js', { type: 'module' });
1// In `worker.js`. 2import sqlite3InitModule from '@sqlite.org/sqlite-wasm'; 3 4const log = console.log; 5const error = console.error; 6 7const start = (sqlite3) => { 8 log('Running SQLite3 version', sqlite3.version.libVersion); 9 const db = 10 'opfs' in sqlite3 11 ? new sqlite3.oo1.OpfsDb('/mydb.sqlite3') 12 : new sqlite3.oo1.DB('/mydb.sqlite3', 'ct'); 13 log( 14 'opfs' in sqlite3 15 ? `OPFS is available, created persisted database at ${db.filename}` 16 : `OPFS is not available, created transient database ${db.filename}`, 17 ); 18 // Your SQLite code here. 19}; 20 21const initializeSQLite = async () => { 22 try { 23 log('Loading and initializing SQLite3 module...'); 24 const sqlite3 = await sqlite3InitModule({ print: log, printErr: error }); 25 log('Done initializing. Running demo...'); 26 start(sqlite3); 27 } catch (err) { 28 error('Initialization error:', err.name, err.message); 29 } 30}; 31 32initializeSQLite();
The db
object above implements the
Object Oriented API #1.
1import sqlite3InitModule from '@sqlite.org/sqlite-wasm'; 2 3const log = console.log; 4const error = console.error; 5 6const start = (sqlite3) => { 7 log('Running SQLite3 version', sqlite3.version.libVersion); 8 const db = new sqlite3.oo1.DB('/mydb.sqlite3', 'ct'); 9 // Your SQLite code here. 10}; 11 12const initializeSQLite = async () => { 13 try { 14 log('Loading and initializing SQLite3 module...'); 15 const sqlite3 = await sqlite3InitModule({ 16 print: log, 17 printErr: error, 18 }); 19 log('Done initializing. Running demo...'); 20 start(sqlite3); 21 } catch (err) { 22 error('Initialization error:', err.name, err.message); 23 } 24}; 25 26initializeSQLite();
The db
object above implements the
Object Oriented API #1.
If you are using vite, you need to add the following
config option in vite.config.js
:
1import { defineConfig } from 'vite'; 2 3export default defineConfig({ 4 server: { 5 headers: { 6 'Cross-Origin-Opener-Policy': 'same-origin', 7 'Cross-Origin-Embedder-Policy': 'require-corp', 8 }, 9 }, 10 optimizeDeps: { 11 exclude: ['@sqlite.org/sqlite-wasm'], 12 }, 13});
Check out a sample project that shows this in action.
See the demo folder for examples of how to use this in the main thread and in a worker. (Note that the worker variant requires special HTTP headers, so it can't be hosted on GitHub Pages.) An example that shows how to use this with vite is available on StackBlitz.
See the list of npm dependents for this package.
(These steps can only be executed by maintainers.)
package.json
reflecting the current
SQLite version number and add a build
identifier suffix like -build1
. The complete version number should read
something like 3.41.2-build1
.npm run build
to build the ES Module. This downloads the latest SQLite
Wasm binary and builds the ES Module.npm run deploy
to commit the changes, push to GitHub, and publish the
new version to npm.Apache 2.0.
This project is based on SQLite Wasm, which it
conveniently wraps as an ES Module and publishes to npm as
@sqlite.org/sqlite-wasm
.
No vulnerabilities found.
No security vulnerabilities found.