Generate Thing in SurrealDB



examples/surrealdb/generate-thing/src/main.rs
use surrealdb::sql::{Id, Thing};

fn main() {
    let id = Thing::from(("person", Id::rand()));
    println!("id {id:?}");
    println!("id {id}");
    println!("id {}", id.to_raw());
    println!();

    // Generate a new random ULID = Universally Unique Lexicographically Sortable Identifier https://github.com/ulid/spec
    let ulid = Thing::from(("person", Id::ulid()));
    println!("ulid {ulid:?}");
    println!("ulid {ulid}");
    println!("ulid {}", ulid.to_raw());
    println!();

    let uuid = Thing::from(("person", Id::uuid()));
    println!("uuid {uuid:?}");
    println!("uuid {uuid}");
    println!("uuid {}", uuid.to_raw());
}

id Thing { tb: "person", id: String("qyi311f3aol1vj5lj9jm") }
id person:qyi311f3aol1vj5lj9jm
id person:qyi311f3aol1vj5lj9jm

ulid Thing { tb: "person", id: String("01J7JWR2N1M9DBX7S0PS29VEZ3") }
ulid person:01J7JWR2N1M9DBX7S0PS29VEZ3
ulid person:01J7JWR2N1M9DBX7S0PS29VEZ3

uuid Thing { tb: "person", id: String("0191e5cc-0aa2-7213-91e7-9e6270853975") }
uuid person:⟨0191e5cc-0aa2-7213-91e7-9e6270853975⟩
uuid person:⟨0191e5cc-0aa2-7213-91e7-9e6270853975⟩