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 Rust wrapper for the official SQLite WebAssembly build with OPFS support
Unmodified sqlite.org WASM · Zero external files · Plug-and-play · Chrome & Firefox
⚡ Designed for Rust developers who want a zero-config SQLite experience in the browser.
✨ Features
| Icon | Feature | Description |
|---|---|---|
| 🚀 | Zero-cost abstractions | Lock-free worker management with OnceLock and atomics |
| 🔒 | 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: https://sqlite-wasm.adorno-dev.workers.dev/
No installation needed · Opens directly in your browser
📦 Installation
Add to your Cargo.toml:
[dependencies] sqlite-wasm = "0.1.3"
🔨 Building
trunk build --release
🏗️ Architecture
┌────────────────────────────┐
│ Your App │
│ (Rust/JS) │
└────────────┬───────────────┘
│
┌────────────▼───────────────┐
│ sqlite-wasm │
│ ┌──────────────────────┐ │
│ │ Worker Manager │ │ Singleton, auto-managed
│ └──────────────────────┘ │
│ ┌──────────────────────┐ │
│ │ Embedded Assets │ │ include_bytes! (Blob/Data URLs)
│ └──────────────────────┘ │
│ ┌──────────────────────┐ │
│ │ OPFS Storage │ │ Persistent storage
│ └──────────────────────┘ │
└────────────┬───────────────┘
│
┌────────────▼───────────────┐
│ Official SQLite WASM Worker│
│ (JavaScript) │
└────────────────────────────┘
📋 API REFERENCE
autostart_embedded() → Initializes worker with embedded files
autostart(path) → Legacy: initializes with external file
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
====================================================================
🦀 Rust Usage
Add to your Cargo.toml:
[dependencies] sqlite-wasm = "0.1.3"
In your Rust code:
use sqlite_wasm::{autostart_embedded, open, exec, query, close};
#[wasm_bindgen(start)] pub async fn start() -> Result<(), JsValue> { // 1. Initialize worker with embedded files autostart_embedded().await?;
// 2. Open database
open("myapp.sqlite3").await?;
// 3. Create table
exec("CREATE TABLE IF NOT EXISTS users (id INTEGER, name TEXT)", vec![]).await?;
// 4. Insert data
exec("INSERT INTO users VALUES (1, 'Alice')", vec![]).await?;
// 5. Query data
let users = query("SELECT * FROM users", vec![]).await?;
// 6. Close database
close().await?;
Ok(())
}
🌐 JavaScript Usage
import init, { autostart_embedded, open, exec, query, close } from '/sqlite-wasm.js';
async function start() { await init();
// 1. Initialize worker with embedded files
await autostart_embedded();
// 2. Open database
await open('myapp.sqlite3');
// 3. Create table
await exec('CREATE TABLE users (id INTEGER, name TEXT)', []);
// 4. Insert data
await exec('INSERT INTO users VALUES (1, "Alice")', []);
// 5. Query data
const result = await query('SELECT * FROM users', []);
console.log('Users:', result.resultRows);
// 6. Close database
await close();
}
start();
🌍 Browser Requirements
- WebAssembly support
- Web Workers
- OPFS (Origin Private File System)
- COOP/COEP headers (Cross-Origin Isolation)
Works in Chrome, Firefox, and other modern browsers.
🧪 How It Works
- Embedding: The official SQLite WASM files are embedded at compile time using include_bytes!
- URL creation: Files become Blob URLs (Chrome) or Data URLs (Firefox)
- Worker wrapper: Intercepts importScripts and fetch
- File mapping: Original filenames map to embedded URLs
- Zero external files: Everything runs from memory
🙏 Credits
This project uses the official SQLite WebAssembly build provided by sqlite.org, without modifications.
This library is a thin Rust wrapper and integration layer designed to make SQLite easier to use in WebAssembly environments.
SQLite is developed by the SQLite authors and released into the public domain.
All credit for the database engine goes to the SQLite project.
This project is not affiliated with or endorsed by the SQLite project.
SQLite is a trademark of the SQLite Consortium.
⚖️ License
MIT © adorno-dev (https://github.com/adorno-dev)
Built with 🦀 and ❤️
Made in Rust · Runs in Browser · Powered by the official SQLite WASM (sqlite.org)