SurrealDB connect to server



examples/surrealdb/connect-to-server/Cargo.toml
[package]
name = "connect-to-server"
version = "0.1.0"
edition = "2021"

[dependencies]
surrealdb = "2.0"
tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] }
serde = { version = "1.0", features = ["derive"] }

examples/surrealdb/connect-to-server/src/main.rs
use surrealdb::engine::remote::ws::Ws;
use surrealdb::opt::auth::Root;
use surrealdb::{Error, Surreal};

#[tokio::main]
async fn main() -> Result<(), Error> {
    println!("Connect to server.");
    let db = Surreal::new::<Ws>("localhost:8000").await?;

    println!("Authenticating as the root user.");
    db.signin(Root {
        username: "root",
        password: "root",
    })
    .await?;

    println!("Select a specific namespace and database.");
    db.use_ns("namespace").use_db("database").await?;

    Ok(())
}