From 19582164ba3073caf957e236c810189c6c705b12 Mon Sep 17 00:00:00 2001 From: muzarski Date: Fri, 22 Dec 2023 07:58:10 +0100 Subject: [PATCH] docs: update uuid/timeuuid info --- docs/source/SUMMARY.md | 3 ++- docs/source/data-types/data-types.md | 4 +++- docs/source/data-types/timeuuid.md | 30 ++++++++++++++++++++++++++++ docs/source/data-types/uuid.md | 8 ++++---- 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 docs/source/data-types/timeuuid.md diff --git a/docs/source/SUMMARY.md b/docs/source/SUMMARY.md index 051aca6062..63639364fa 100644 --- a/docs/source/SUMMARY.md +++ b/docs/source/SUMMARY.md @@ -39,7 +39,8 @@ - [Counter](data-types/counter.md) - [Blob](data-types/blob.md) - [Inet](data-types/inet.md) - - [Uuid, Timeuuid](data-types/uuid.md) + - [Uuid](data-types/uuid.md) + - [Timeuuid](data-types/timeuuid.md) - [Date](data-types/date.md) - [Time](data-types/time.md) - [Timestamp](data-types/timestamp.md) diff --git a/docs/source/data-types/data-types.md b/docs/source/data-types/data-types.md index 6fe7c70e07..7962e5680e 100644 --- a/docs/source/data-types/data-types.md +++ b/docs/source/data-types/data-types.md @@ -20,7 +20,8 @@ Database types and their Rust equivalents: * `Counter` <----> `value::Counter` * `Blob` <----> `Vec` * `Inet` <----> `std::net::IpAddr` -* `Uuid`, `Timeuuid` <----> `uuid::Uuid` +* `Uuid` <----> `uuid::Uuid` +* `Timeuuid` <----> `value::CqlTimeuuid` * `Date` <----> `value::CqlDate`, `chrono::NaiveDate`, `time::Date` * `Time` <----> `value::CqlTime`, `chrono::NaiveTime`, `time::Time` * `Timestamp` <----> `value::CqlTimestamp`, `chrono::DateTime`, `time::OffsetDateTime` @@ -45,6 +46,7 @@ Database types and their Rust equivalents: blob inet uuid + timeuuid date time timestamp diff --git a/docs/source/data-types/timeuuid.md b/docs/source/data-types/timeuuid.md new file mode 100644 index 0000000000..2e4679f9e8 --- /dev/null +++ b/docs/source/data-types/timeuuid.md @@ -0,0 +1,30 @@ +# Timeuuid + +`Timeuuid` is represented as `value::CqlTimeuuid`. +`value::CqlTimeuuid` is a wrapper for `uuid::Uuid` with custom ordering logic +which follows Scylla/Cassandra semantics. + +```rust +# extern crate scylla; +# use scylla::Session; +# use std::error::Error; +# use std::str::FromStr; +# async fn check_only_compiles(session: &Session) -> Result<(), Box> { +use scylla::IntoTypedRows; +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?; + } +} +# Ok(()) +# } +``` \ No newline at end of file diff --git a/docs/source/data-types/uuid.md b/docs/source/data-types/uuid.md index c3cfde2725..84ab1c2d1a 100644 --- a/docs/source/data-types/uuid.md +++ b/docs/source/data-types/uuid.md @@ -1,6 +1,6 @@ -# Uuid, Timeuuid +# Uuid -`Uuid` and `Timeuuid` are represented as `uuid::Uuid` +`Uuid` is represented as `uuid::Uuid`. ```rust # extern crate scylla; @@ -11,13 +11,13 @@ use scylla::IntoTypedRows; use uuid::Uuid; -// Insert some uuid/timeuuid into the table +// Insert some uuid into the table let to_insert: Uuid = Uuid::parse_str("8e14e760-7fa8-11eb-bc66-000000000001")?; session .query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,)) .await?; -// Read uuid/timeuuid from the table +// Read uuid from the table if let Some(rows) = session.query("SELECT a FROM keyspace.table", &[]).await?.rows { for row in rows.into_typed::<(Uuid,)>() { let (uuid_value,): (Uuid,) = row?;