Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: adding context to timeuuid using v1 feature #980

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock.msrv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion docs/source/data-types/timeuuid.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Timeuuid

`Timeuuid` is represented as `value::CqlTimeuuid`.
`value::CqlTimeuuid` is a wrapper for `uuid::Uuid` with custom ordering logic
`value::CqlTimeuuid` is a wrapper for `uuid::Uuid` (using the `v1` feature) with custom ordering logic
danielhe4rt marked this conversation as resolved.
Show resolved Hide resolved
which follows Scylla/Cassandra semantics.

```rust
Expand All @@ -19,6 +19,41 @@ 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:
danielhe4rt marked this conversation as resolved.
Show resolved Hide resolved

```shell
cargo add uuid -F v1
```

and now you're gonna be able to use the `uuid::v1` features:

```rust
# extern crate uuid;
danielhe4rt marked this conversation as resolved.
Show resolved Hide resolved
# extern crate scylla;
# use scylla::Session;
# use std::error::Error;
# use std::str::FromStr;
use scylla::IntoTypedRows;
use scylla::frame::value::CqlTimeuuid;
use uuid::Uuid;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {

// Insert some timeuuid into the table
let to_insert = CqlTimeuuid::from(Uuid::now_v1(&[1, 2, 3, 4, 5, 6]));
wprzytula marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tracing = "0.1.25"
tracing-subscriber = { version = "0.3.14", features = ["env-filter"] }
chrono = { version = "0.4", default-features = false }
time = { version = "0.3.22" }
uuid = "1.0"
uuid = { version = "1.0", features = ["v1"]}
tower = "0.4"
stats_alloc = "0.1"
clap = { version = "3.2.4", features = ["derive"] }
Expand Down
Loading