From 599a2be0ae27560a2068577b0ffd01afa296979a Mon Sep 17 00:00:00 2001 From: danielhe4rt Date: Sun, 12 May 2024 16:22:05 -0300 Subject: [PATCH] docs: adding context to timeuuid using v1 feature --- docs/source/data-types/timeuuid.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/source/data-types/timeuuid.md b/docs/source/data-types/timeuuid.md index bd84dcba5b..0f0349648f 100644 --- a/docs/source/data-types/timeuuid.md +++ b/docs/source/data-types/timeuuid.md @@ -2,7 +2,7 @@ The `Timeuuid` type is represented as `value::CqlTimeuuid`. -Also, `value::CqlTimeuuid` is a wrapper for `uuid::Uuid` with custom ordering logic which follows Scylla/Cassandra semantics. +Also, `value::CqlTimeuuid` is a wrapper for `uuid::Uuid` with custom ordering logic which follows Scylla/Cassandra semantics. ```rust # extern crate scylla; @@ -15,15 +15,18 @@ use scylla::frame::value::CqlTimeuuid; // Insert some timeuuid into the table let to_insert: CqlTimeuuid = CqlTimeuuid::from_str("8e14e760-7fa8-11eb-bc66-000000000001")?; + 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?; - } +// Read Timeuuid from the table +let result = session.query("SELECT a FROM keyspace.table", &[]).await?; + +let mut iter = result.rows_typed::<(CqlTimeuuid, )>()?; + +while let Some((timeuuid,)) = iter.next().transpose()? { + println!("Read a value from row: {}", timeuuid); } # Ok(()) # } @@ -60,11 +63,13 @@ 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?; - } +// Read Timeuuid from the table +let result = session.query("SELECT a FROM keyspace.table", &[]).await?; + +let mut iter = result.rows_typed::<(CqlTimeuuid, )>()?; + +while let Some((timeuuid,)) = iter.next().transpose()? { + println!("Read a value from row: {}", timeuuid); } # Ok(()) # }