Generate ID in SurrealDB
examples/surrealdb/generate-id/src/main.rs
use surrealdb::sql::Id; fn main() { let id = Id::rand(); // Generate a new random ID println!("id {id:?}"); println!("id {id}"); println!("id {}", id.to_raw()); println!(); let ulid = Id::ulid(); // Generate a new random ULID = Universally Unique Lexicographically Sortable Identifier https://github.com/ulid/spec println!("ulid {ulid:?}"); println!("ulid {ulid}"); println!("ulid {}", ulid.to_raw()); println!(); let uuid = Id::uuid(); // Generate a new random UUID println!("uuid {uuid:?}"); println!("uuid {uuid}"); println!("uuid {}", uuid.to_raw()); }
id String("jcgh05b5adyoh2jv15qq") id jcgh05b5adyoh2jv15qq id jcgh05b5adyoh2jv15qq ulid String("01J7JN8XSV1FJRT86XQDMEGVE3") ulid 01J7JN8XSV1FJRT86XQDMEGVE3 ulid 01J7JN8XSV1FJRT86XQDMEGVE3 uuid String("0191e554-773b-77d2-9a97-875a81b3c0b3") uuid ⟨0191e554-773b-77d2-9a97-875a81b3c0b3⟩ uuid 0191e554-773b-77d2-9a97-875a81b3c0b3