Skip to content

Commit

Permalink
docs: added docs for vector type
Browse files Browse the repository at this point in the history
  • Loading branch information
smoczy123 committed Jan 22, 2025
1 parent 2ea279a commit db320e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/source/data-types/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Database types and their Rust equivalents:
* `Map` <----> `std::collections::HashMap<K, V>`
* `Tuple` <----> Rust tuples
* `UDT (User defined type)` <----> Custom user structs with macros
* `Vector` <----> `Vec<T>`


```{eval-rst}
Expand All @@ -56,5 +57,6 @@ Database types and their Rust equivalents:
collections
tuple
udt
vector
```
26 changes: 26 additions & 0 deletions docs/source/data-types/vector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Vector
`Vector` is represented as `Vec<T>`

```rust
# extern crate scylla;
# extern crate futures;
# use scylla::Session;
# use std::error::Error;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
use futures::TryStreamExt;

// Insert a vector of ints into the table
let my_vector: Vec<i32> = vec![1, 2, 3, 4, 5];
session
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_vector,))
.await?;

// Read a list of ints from the table
let mut stream = session.query_iter("SELECT a FROM keyspace.table", &[])
.await?
.rows_stream::<(Vec<i32>,)>()?;
while let Some((vector_value,)) = stream.try_next().await? {
println!("{:?}", vector);
}
# Ok(())
# }

0 comments on commit db320e6

Please sign in to comment.