From 007c513dc5e4845df101f057452df879504e8851 Mon Sep 17 00:00:00 2001 From: danielhe4rt Date: Tue, 16 Apr 2024 12:41:11 +0200 Subject: [PATCH] docs: add context to timeuuid v1 feature --- docs/source/data-types/timeuuid.md | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/source/data-types/timeuuid.md b/docs/source/data-types/timeuuid.md index 2e4679f9e8..f22fcd0c04 100644 --- a/docs/source/data-types/timeuuid.md +++ b/docs/source/data-types/timeuuid.md @@ -1,7 +1,7 @@ # Timeuuid `Timeuuid` is represented as `value::CqlTimeuuid`. -`value::CqlTimeuuid` is a wrapper for `uuid::Uuid` with custom ordering logic +`value::CqlTimeuuid` is a wrapper for `uuid::Uuid` (using the `v1` feature) with custom ordering logic which follows Scylla/Cassandra semantics. ```rust @@ -19,6 +19,41 @@ session .query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,)) .await?; +// Read timeuuid from the table +if let Some(rows) = session.query("SELECT a FROM keyspace.table", &[]).await?.rows { + for row in rows.into_typed::<(CqlTimeuuid,)>() { + let (timeuuid_value,): (CqlTimeuuid,) = row?; + } +} +# Ok(()) +# } +``` + +To use the Timeuuid on `uuid` crate, enable the feature `v1` in your crate using: + +```shell +cargo add uuid -F v1 +``` + +and now you're gonna be able to use the `uuid::v1` features: + +```rust,ignore +# extern crate uuid; +# extern crate scylla; +# use scylla::Session; +# use std::error::Error; +# use std::str::FromStr; +use scylla::IntoTypedRows; +use scylla::frame::value::CqlTimeuuid; +use uuid::Uuid; +# async fn check_only_compiles(session: &Session) -> Result<(), Box> { + +// Insert some timeuuid into the table +let to_insert = CqlTimeuuid::from(Uuid::now_v1(&[1, 2, 3, 4, 5, 6])); +session + .query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,)) + .await?; + // Read timeuuid from the table if let Some(rows) = session.query("SELECT a FROM keyspace.table", &[]).await?.rows { for row in rows.into_typed::<(CqlTimeuuid,)>() {