• Start

Languages

/

Rust

/

Methods

unset

The .unset() method for the SurrealDB Rust SDK removes a parameter from the connection.

Removes a parameter from this connection.

Method Syntax
db.unset(key)
use surrealdb::Surreal;
use surrealdb::engine::remote::ws::Ws;
use surrealdb::opt::auth::Root;
use surrealdb_types::SurrealValue;

#[derive(Debug, SurrealValue)]
struct Name {
    first: String,
    last: String,
}

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

    db.signin(Root {
        username: "root".to_string(),
        password: "secret".to_string(),
    })
    .await?;

    db.use_ns("main").use_db("main").await?;

    // Assign the variable on the connection
    db.set(
        "name",
        Name {
            first: "Tobie".to_string(),
            last: "Morgan Hitchcock".to_string(),
        },
    )
    .await?;
    dbg!(db.query("$name").await?);

    db.unset("name").await?;
    // Aaaand now it's gone
    dbg!(db.query("$name").await?);
    Ok(())
}

Was this page helpful?