Skip to content

Commit

Permalink
docs: adding context to timeuuid creation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhe4rt committed Apr 26, 2024
1 parent 7c3fd37 commit d3c0907
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions docs/source/data-types/timeuuid.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Timeuuid

`Timeuuid` is represented as `value::CqlTimeuuid`.
`value::CqlTimeuuid` is a wrapper for `uuid::Uuid` (using the `v1` feature) with custom ordering logic
which follows Scylla/Cassandra semantics.
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.

```rust
# extern crate scylla;
Expand All @@ -29,6 +29,8 @@ if let Some(rows) = session.query("SELECT a FROM keyspace.table", &[]).await?.ro
# }
```

## Creating your own Timeuuid

To create your own `Timeuuid` objects from timstamp-base `uuid` v1, you need to enable the feature `v1` of `uuid` crate using:

```shell
Expand All @@ -54,7 +56,7 @@ let node_id = [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC];
// Build your Timeuuid with the current timestamp
let to_insert = CqlTimeuuid::from(Uuid::now_v1(&node_id));

session
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

Expand All @@ -66,4 +68,6 @@ if let Some(rows) = session.query("SELECT a FROM keyspace.table", &[]).await?.ro
}
# Ok(())
# }
```
```

Learn more about UUID::v1 [here](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address)).

0 comments on commit d3c0907

Please sign in to comment.