wasm32-unknown-unknown bindings to the libsqlite3 library.
Due to restrictions on the target platform, the emscripten toolchain needs to be installed for compilation.
[dependencies]
sqlite-wasm-rs = "0.5"[dependencies]
# Encryption is supported by SQLite3MultipleCiphers
# See <https://utelle.github.io/SQLite3MultipleCiphers>
sqlite-wasm-rs = { version = "0.5", features = ["sqlite3mc"] }use sqlite_wasm_rs as ffi;
async fn open_db() {
// open with memory vfs
let mut db = std::ptr::null_mut();
let ret = unsafe {
ffi::sqlite3_open_v2(
c"mem.db".as_ptr().cast(),
&mut db as *mut _,
ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE,
std::ptr::null()
)
};
assert_eq!(ffi::SQLITE_OK, ret);
}[dependencies]
sqlite-wasm-vfs = "0.1"The following vfs have been implemented:
memory: as the default vfs, no additional conditions are required, store the database in memory.sahpool: ported from sqlite-wasm, store the database in opfs.relaxed-idb: store the database in blocks in indexed db.
| MemoryVFS | SyncAccessHandlePoolVFS | RelaxedIdbVFS | |
|---|---|---|---|
| Storage | RAM | OPFS | IndexedDB |
| Contexts | All | Dedicated Worker | All |
| Multiple connections | ❌ | ❌ | ❌ |
| Full durability | ✅ | ✅ | ❌ |
| Relaxed durability | ❌ | ❌ | ✅ |
| Multi-database transactions | ✅ | ✅ | ✅ |
| No COOP/COEP requirements | ✅ | ✅ | ✅ |
Here is an example showing how to use sqlite-wasm-rs to implement a simple in-memory VFS, see implement-a-vfs example.
This library is not thread-safe:
JsValueis not cross-threaded, see wasm-bindgen/wasm-bindgen#955 for details.- sqlite is compiled with
-DSQLITE_THREADSAFE=0.
We provide the ability to use prebuild libsqlite3.a, cargo provides a links field that can be used to specify which library to link to. With the help of overriding build scripts, you can overriding its configuration in your crate and link sqlite to your prebuild libsqlite3.a.
More see use-prebuild-lib example.
The minimal officially supported rustc version is 1.82.0.
| Extension | About |
|---|---|
| sqlite-vec | A vector search SQLite extension that runs anywhere! |
Contributions are welcome!
diesel: A safe, extensible ORM and Query Builder for Rust.rusqlite: Ergonomic bindings to SQLite for Rust.sqlite-wasm: SQLite Wasm conveniently wrapped as an ES Module.sqlite-web-rs: A SQLite WebAssembly backend for Diesel.wa-sqlite: WebAssembly SQLite with support for browser storage extensions.SQLite3MultipleCiphers: SQLite3 encryption extension with support for multiple ciphers.