Before getting started on any bigger demo, this example shows how to set up and in-memory Surreal Database in Rust.
Dependencies
examples/surrealdb/in-memory-setup/Cargo.toml
[package]
name = "in-memory-setup"
version = "0.1.0"
edition = "2021"
# 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 = "1.1", features = ["kv-mem"] }
tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] }
The code
examples/surrealdb/in-memory-setup/src/main.rs
use surrealdb::Surreal;
use surrealdb::engine::local::Mem;
#[tokio::main]
async fn main() -> surrealdb::Result<()> {
let _db = Surreal::new::<Mem>(()).await?;
Ok(())
}
Conclusion
There is not much in this example.
This will create an in-memory database so anything we add to the database will be gone when the application stops running.
If you prefer a persistent database where the data is stored on the disk, but you would still like to use the simple, embedded version, take a look at Setting up embedded SurrealDB with RocksDB backend.