#indexeddb #future #webassembly


A futures based crate for interacting with IndexedDB on browsers using webassembly

8 releases (5 breaking)

0.6.1 Jan 25, 2024
0.6.0 Jan 25, 2024
0.5.0 Jan 16, 2024
0.4.1 Mar 11, 2023
0.1.0 Jul 7, 2022

#119 in Asynchronous

Download history 177/week @ 2023-11-03 133/week @ 2023-11-10 202/week @ 2023-11-17 241/week @ 2023-11-24 139/week @ 2023-12-01 118/week @ 2023-12-08 367/week @ 2023-12-15 251/week @ 2023-12-22 240/week @ 2023-12-29 344/week @ 2024-01-05 226/week @ 2024-01-12 138/week @ 2024-01-19 148/week @ 2024-01-26 137/week @ 2024-02-02 106/week @ 2024-02-09 281/week @ 2024-02-16

729 downloads per month
Used in 4 crates (3 directly)


3.5K SLoC


A futures based crate for interacting with IndexedDB on browsers using webassembly.


To use idb, you need to run following command from your project root:

cargo add idb

If you don't want to use async/await syntax, you can disable the futures feature using:

cargo add idb --no-default-features

After disabling the futures feature, you can use on_success and on_error methods on requests to attach callbacks.


To create a new database, you can use Factory::open:

use idb::{Database, DatabaseEvent, Error, Factory, IndexParams, KeyPath, ObjectStoreParams};

async fn create_database() -> Result<Database, Error> {
    // Get a factory instance from global scope
    let factory = Factory::new()?;

    // Create an open request for the database
    let mut open_request = factory.open("test", Some(1)).unwrap();

    // Add an upgrade handler for database
    open_request.on_upgrade_needed(|event| {
        // Get database instance from event
        let database = event.database().unwrap();

        // Prepare object store params
        let mut store_params = ObjectStoreParams::new();

        // Create object store
        let store = database
            .create_object_store("employees", store_params)

        // Prepare index params
        let mut index_params = IndexParams::new();

        // Create index on object store
            .create_index("email", KeyPath::new_single("email"), Some(index_params))

    // `await` open request

To add data to an object store, you can use ObjectStore::add:

use idb::{Database, Error, TransactionMode};
use serde::Serialize;
use serde_wasm_bindgen::Serializer;
use wasm_bindgen::JsValue;

async fn add_data(database: &Database) -> Result<JsValue, Error> {
    // Create a read-write transaction
    let transaction = database.transaction(&["employees"], TransactionMode::ReadWrite)?;

    // Get the object store
    let store = transaction.object_store("employees").unwrap();

    // Prepare data to add
    let employee = serde_json::json!({
        "name": "John Doe",
        "email": "john@example.com",

    // Add data to object store
    let id = store

    // Commit the transaction


To get data from an object store, you can use ObjectStore::get:

use idb::{Database, Error, TransactionMode};
use serde_json::Value;
use wasm_bindgen::JsValue;

async fn get_data(database: &Database, id: JsValue) -> Result<Option<Value>, Error> {
    // Create a read-only transaction
    let transaction = database
        .transaction(&["employees"], TransactionMode::ReadOnly)

    // Get the object store
    let store = transaction.object_store("employees").unwrap();

    // Get the stored data
    let stored_employee: Option<JsValue> = store.get(id)?.await?;

    // Deserialize the stored data
    let stored_employee: Option<Value> = stored_employee
        .map(|stored_employee| serde_wasm_bindgen::from_value(stored_employee).unwrap());

    // Wait for the transaction to complete (alternatively, you can also commit the transaction)


For more examples on using other functionality, see the tests directory.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~193K SLoC