Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
SQLite WASM
A high-performance SQLite wrapper for WebAssembly with OPFS support
Zero-cost abstractions โข Type-safe API โข Persistent storage โข Single-threaded by design
โจ Features
| Icon | Feature | Description |
|---|---|---|
| ๐ | Zero-cost abstractions | Worker management with OnceLock and atomic counters |
| ๐ | OPFS persistence | Databases survive page reloads and browser restarts |
| ๐งต | Web Worker | Database operations run in a separate thread |
| ๐ฆ | Auto-minification | JS glue code automatically minified (Brotli/Gzip) |
| ๐ | COOP/COEP Headers | Proper headers for SharedArrayBuffer support |
| ๐ฏ | Type Safe | Strongly typed Rust API with proper error handling |
| ๐ | Async/Await | Promise-based API for JavaScript |
| โก | Atomic operations | Lock-free message passing with AtomicU32 |
๐ Test It Live
๐ Try SQLite Studio Online
No installation needed. Opens directly in your browser.
๐ฆ Installation
Add to your Cargo.toml:
[]
= "0.1"
Or via CLI:
๐ ๏ธ Build Dependencies
1. Rust WASM target
2. wasm-pack
3. minix (JS minification)
4. Compression tools
Ubuntu / Debian:
macOS:
These tools compile to wasm32, generate bindings, minify JS, and compress the final output.
๐จ Building
# Make it executable (first time only)
# Build everything
The script automatically:
- โ Compiles Rust to WASM
- โ Generates bindings
- โ Minifies JS glue code
- โ Applies Brotli/Gzip compression
- โ
Produces optimized artifacts in
pkg/
๐ฆ Rust Usage
Quick Start
use ;
pub async
API Reference
| Function | Description |
|---|---|
autostart(path) |
Initializes the SQLite worker (call once) |
open(name) |
Opens or creates a database |
exec(sql, params) |
Executes SQL without returning rows |
query(sql, params) |
Executes SELECT and returns rows |
close() |
Closes the current database |
is_open() |
Checks if a database is open |
db_id() |
Returns current database ID (debug) |
๐ JavaScript Usage
After initialization, the global wasm object is available with all methods.
Quick Start
import init from './pkg/sqlite_wasm.js';
.;
JavaScript API
| Method | Description | Example |
|---|---|---|
autostart(path) |
Initializes worker | await wasm.autostart('/sqlite.org/sqlite3-worker1.js') |
open(name) |
Opens/creates database | await wasm.open('mydb.sqlite3') |
exec(sql, params) |
Executes SQL | await wasm.exec("INSERT INTO users VALUES (?)", ["Joรฃo"]) |
query(sql, params) |
Runs SELECT | const res = await wasm.query("SELECT * FROM users", []) |
close() |
Closes database | await wasm.close() |
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโ
โ Your App โ
โ (Rust/JS) โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโ
โ sqlite-wasm โ
โ โโโโโโโโโโโโโโโ
โ โ Worker โโ โโ Singleton, auto-managed
โ โ Manager โโ
โ โโโโโโโโโโโโโโโ
โ โโโโโโโโโโโโโโโ
โ โ Message โโ โโ Atomic counters, oneshot channels
โ โ Passing โโ
โ โโโโโโโโโโโโโโโ
โ โโโโโโโโโโโโโโโ
โ โ OPFS โโ โโ Persistent, high-performance
โ โ Storage โโ
โ โโโโโโโโโโโโโโโ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโ
โ SQLite Worker โ
โ (JavaScript) โ
โโโโโโโโโโโโโโโโโโโ
โ๏ธ Performance Optimizations
[]
= "z" # Optimize for size
= true # Link time optimization
= 1 # Maximum optimization
= "abort" # Remove unwinding
= "debuginfo" # Remove debug symbols
| File | Original | Brotli | Reduction |
|---|---|---|---|
| sqlite_wasm.js | 16KB | 12KB | 25% |
| sqlite_wasm_bg.wasm | 47KB | 17KB | 64% |
| sqlite3.wasm | 835KB | 336KB | 60% |
๐ Project Structure
sqlite-wasm/
โโโ src/ # Rust source code
โ โโโ lib.rs
โ โโโ modules/
โ โโโ core/
โ โโโ worker.rs
โ โโโ database.rs
โ โโโ bindings.rs
โโโ sqlite.org/ # Official SQLite files
โโโ pkg/ # Generated WASM package
โโโ build # Build script
โโโ webserver.js # Development server
โโโ index.html # Test playground
๐ Browser Requirements
- WebAssembly support
- Web Workers
- OPFS (Origin Private File System)
- COOP/COEP headers (Cross-Origin Isolation)
Recommended: Latest Chrome, Edge, or other Chromium-based browsers.
๐ License
MIT ยฉ adorno-dev
Built with ๐ฆ and โค๏ธ for maximum performance
Made in Rust ยท Runs in Browser ยท Powered by SQLite