Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SurrealDB with RocksDB backend in Rust embedded client with local database storage

  • SurrealDB

  • kv-rocksdb

  • RocksDB

  • We can also use local database files (just like in sqlite).

  • This version does not need an external database server either.

  • The compilation time is longer as we also compile the database backend, but this can be used as an embedded, but already persistan database.

  • No need for authentication here either.

[package]
name = "embedded-rocksdb"
version = "0.1.0"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"] }
surrealdb = { version = "2.0", features = ["kv-rocksdb"] }
tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] }
  • This will create a folder called tempdb in the root of the crate. You could also give a path there to some other folder.
use surrealdb::engine::local::RocksDb;
use surrealdb::Surreal;

#[tokio::main]
async fn main() -> surrealdb::Result<()> {
    let db = Surreal::new::<RocksDb>("tempdb").await?;

    db.use_ns("namespace").use_db("database").await?;

    Ok(())
}