Skip to content

Commit

Permalink
docs: update uuid/timeuuid info
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Jan 25, 2024
1 parent 0db6583 commit 1958216
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/source/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion docs/source/data-types/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Database types and their Rust equivalents:
* `Counter` <----> `value::Counter`
* `Blob` <----> `Vec<u8>`
* `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<Utc>`, `time::OffsetDateTime`
Expand All @@ -45,6 +46,7 @@ Database types and their Rust equivalents:
blob
inet
uuid
timeuuid
date
time
timestamp
Expand Down
30 changes: 30 additions & 0 deletions docs/source/data-types/timeuuid.md
Original file line number Diff line number Diff line change
@@ -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<dyn Error>> {
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(())
# }
```
8 changes: 4 additions & 4 deletions docs/source/data-types/uuid.md
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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?;
Expand Down

0 comments on commit 1958216

Please sign in to comment.