Skip to content

Repository files navigation

Crates.io

wasm32-unknown-unknown bindings to the libsqlite3 library.

Usage

[dependencies]
sqlite-wasm-rs = { version = "0.6", features = ["wasm-bindgen"] }
[dependencies]
# Encryption is supported by SQLite3MultipleCiphers
# See <https://utelle.github.io/SQLite3MultipleCiphers>
sqlite-wasm-rs = { version = "0.6", features = ["wasm-bindgen", "sqlite3mc"] }
use sqlite_wasm_rs as ffi;

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);
    assert_eq!(unsafe { ffi::sqlite3_close(db) }, ffi::SQLITE_OK);
}

About VFS

[dependencies]
sqlite-wasm-vfs = { version = "0.3", features = ["sahpool"] }

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.

How to implement a VFS

Here is an example showing how to implement a simple in-memory VFS, see implement-a-vfs example.

cargo run -p rsqlite-vfs --example implement-a-vfs

About multithreading

Multithreading is not supported, SQLite is compiled with -DSQLITE_THREADSAFE=0.

Use without wasm-bindgen

No features are enabled by default, provide your own host functions. See JS Host or C Host example.

Use custom SQLite sources

Point SQLITE_WASM_RS_SOURCE_DIR to your sqlite3.c/.h files (sqlite3mc_amalgamation.c/.h for sqlite3mc):

SQLITE_WASM_RS_SOURCE_DIR=/path/to/sqlite cargo build --target wasm32-unknown-unknown --features bindgen

Minimum supported Rust version (MSRV)

The minimal officially supported rustc version is 1.81.0.

Extensions

Extension About
sqlite-vec A vector search SQLite extension that runs anywhere!

Contributions are welcome!

Related Project

  • 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.

Friends

  • moli - Best browser for AI Agent, written in pure Rust.

About

wasm32-unknown-unknown bindings to the libsqlite3 library.

Topics

Resources

Stars

97 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages