Skip to content

Commit

Permalink
docs: adding context to timeuuid using v1 feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielHe4rt committed Apr 16, 2024
1 parent 1fcadc9 commit 71d41a7
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion docs/source/data-types/timeuuid.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,51 @@ which follows Scylla/Cassandra semantics.
# 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;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {

// 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(())
# }
```


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
# extern crate scylla;
# use scylla::Session;
# use std::error::Error;
# use std::str::FromStr;
use scylla::IntoTypedRows;
use uuid::Uuid;
use scylla::frame::value::CqlTimeuuid;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {

// Insert some timeuuid into the table
let to_insert: CqlTimeuuid = CqlTimeuuid(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,)>() {
Expand Down

0 comments on commit 71d41a7

Please sign in to comment.