Skip to content

How to select all IDs and values from a table? #4072

Answered by Dhghomon
HaoYang670 asked this question in Q&A
Discussion options

You must be logged in to vote

You could use meta::id to pull out the id and then pull that out and collect it into a HashMap. Here's a quick example that might help:

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use surrealdb::engine::remote::ws::Ws;
use surrealdb::opt::auth::Root;
use surrealdb::{Error, Surreal};

#[derive(Serialize, Deserialize, Debug, Clone)]
struct User {
    id: String,
    name: String,
}

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

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

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

    let stuff = db
        …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@HaoYang670
Comment options

Answer selected by Dhghomon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants