Skip to content

Commit

Permalink
documentation: adjust to the new traits
Browse files Browse the repository at this point in the history
Examples in the documentation are now adjusted to the new
deserialization API, and the examples there finally compile.
  • Loading branch information
piodul committed May 9, 2023
1 parent a27f11b commit 0262a31
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 114 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let uri = "127.0.0.1:9042";
let session: Session = SessionBuilder::new().known_node(uri).build().await?;

let result = session.query("SELECT a, b, c FROM ks.t", &[]).await?;
let mut iter = result.rows_typed::<(i32, i32, String)>()?;
let mut iter = result.rows::<(i32, i32, String)>()?;
while let Some((a, b, c)) = iter.next().transpose()? {
println!("a, b, c: {}, {}, {}", a, b, c);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ session

// Read blobs from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Vec<u8>,)>()?;
let mut iter = result.rows::<(Vec<u8>,)>()?;
while let Some((blob_value,)) = iter.next().transpose()? {
println!("{:?}", blob_value);
}
Expand Down
12 changes: 6 additions & 6 deletions docs/source/data-types/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ session

// Read a list of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Vec<i32>,)>()?;
let mut iter = result.rows::<(Vec<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
}
Expand All @@ -44,7 +44,7 @@ session

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Vec<i32>,)>()?;
let mut iter = result.rows::<(Vec<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
}
Expand All @@ -68,7 +68,7 @@ session

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(HashSet<i32>,)>()?;
let mut iter = result.rows::<(HashSet<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
}
Expand All @@ -92,7 +92,7 @@ session

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(BTreeSet<i32>,)>()?;
let mut iter = result.rows::<(BTreeSet<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ session

// Read a map from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(HashMap<String, i32>,)>()?;
let mut iter = result.rows::<(HashMap<String, i32>,)>()?;
while let Some((map_value,)) = iter.next().transpose()? {
println!("{:?}", map_value);
}
Expand All @@ -147,7 +147,7 @@ session

// Read a map from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(BTreeMap<String, i32>,)>()?;
let mut iter = result.rows::<(BTreeMap<String, i32>,)>()?;
while let Some((map_value,)) = iter.next().transpose()? {
println!("{:?}", map_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use scylla::frame::value::Counter;

// Read counter from the table
let result = session.query("SELECT c FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Counter,)>()?;
let mut iter = result.rows::<(Counter,)>()?;
while let Some((counter_value,)) = iter.next().transpose()? {
let counter_int_value: i64 = counter_value.0;
println!("{}", counter_int_value);
Expand Down
4 changes: 2 additions & 2 deletions docs/source/data-types/date.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ session

// Read NaiveDate from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(NaiveDate,)>()?;
let mut iter = result.rows::<(NaiveDate,)>()?;
while let Some((date_value,)) = iter.next().transpose()? {
println!("{:?}", date_value);
}
Expand Down Expand Up @@ -53,7 +53,7 @@ session

// Read raw Date from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Date,)>()?;
let mut iter = result.rows::<(Date,)>()?;
while let Some((date_value,)) = iter.next().transpose()? {
println!("{:?}", date_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/decimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ session

// Read a decimal from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(BigDecimal,)>()?;
let mut iter = result.rows::<(BigDecimal,)>()?;
while let Some((decimal_value,)) = iter.next().transpose()? {
println!("{:?}", decimal_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/duration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ session

// Read duration from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(CqlDuration,)>()?;
let mut iter = result.rows::<(CqlDuration,)>()?;
while let Some((duration_value,)) = iter.next().transpose()? {
println!("{:?}", duration_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/inet.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ session

// Read inet from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(IpAddr,)>()?;
let mut iter = result.rows::<(IpAddr,)>()?;
while let Some((inet_value,)) = iter.next().transpose()? {
println!("{:?}", inet_value);
}
Expand Down
14 changes: 7 additions & 7 deletions docs/source/data-types/primitive.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ session

// Read a bool from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(bool,)>()?;
let mut iter = result.rows::<(bool,)>()?;
while let Some((bool_value,)) = iter.next().transpose()? {
println!("{}", bool_value);
}
Expand All @@ -46,7 +46,7 @@ session

// Read a tinyint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i8,)>()?;
let mut iter = result.rows::<(i8,)>()?;
while let Some((tinyint_value,)) = iter.next().transpose()? {
println!("{:?}", tinyint_value);
}
Expand All @@ -73,7 +73,7 @@ session

// Read a smallint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i16,)>()?;
let mut iter = result.rows::<(i16,)>()?;
while let Some((smallint_value,)) = iter.next().transpose()? {
println!("{}", smallint_value);
}
Expand All @@ -100,7 +100,7 @@ session

// Read an int from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i32,)>()?;
let mut iter = result.rows::<(i32,)>()?;
while let Some((int_value,)) = iter.next().transpose()? {
println!("{}", int_value);
}
Expand All @@ -127,7 +127,7 @@ session

// Read a bigint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i64,)>()?;
let mut iter = result.rows::<(i64,)>()?;
while let Some((bigint_value,)) = iter.next().transpose()? {
println!("{:?}", bigint_value);
}
Expand All @@ -154,7 +154,7 @@ session

// Read a float from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(f32,)>()?;
let mut iter = result.rows::<(f32,)>()?;
while let Some((float_value,)) = iter.next().transpose()? {
println!("{:?}", float_value);
}
Expand All @@ -181,7 +181,7 @@ session

// Read a double from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(f64,)>()?;
let mut iter = result.rows::<(f64,)>()?;
while let Some((double_value,)) = iter.next().transpose()? {
println!("{:?}", double_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ session

// Read ascii/text/varchar from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(String,)>()?;
let mut iter = result.rows::<(String,)>()?;
while let Some((text_value,)) = iter.next().transpose()? {
println!("{}", text_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ session

// Read time from the table, no need for a wrapper here
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Duration,)>()?;
let mut iter = result.rows::<(Duration,)>()?;
while let Some((time_value,)) = iter.next().transpose()? {
println!("{:?}", time_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/timestamp.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ session

// Read timestamp from the table, no need for a wrapper here
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Duration,)>()?;
let mut iter = result.rows::<(Duration,)>()?;
while let Some((timestamp_value,)) = iter.next().transpose()? {
println!("{:?}", timestamp_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/tuple.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ session

// Read a tuple of int and string from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<((i32, String),)>()?;
let mut iter = result.rows::<((i32, String),)>()?;
while let Some((tuple_value,)) = iter.next().transpose()? {
let int_value: i32 = tuple_value.0;
let string_value: String = tuple_value.1;
Expand Down
7 changes: 4 additions & 3 deletions docs/source/data-types/udt.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ To use this type in the driver create a matching struct and derive `IntoUserType
# use std::error::Error;
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
use scylla::IntoTypedRows;
use scylla::macros::{FromUserType, IntoUserType};
use scylla::macros::{IntoUserType, DeserializeCql};
use scylla::cql_to_rust::FromCqlVal;
use scylla::types::deserialize::value::DeserializeCql;

// Define custom struct that matches User Defined Type created earlier
// wrapping field in Option will gracefully handle null field values
#[derive(Debug, IntoUserType, FromUserType)]
#[derive(Debug, IntoUserType, DeserializeCql)]
struct MyType {
int_val: i32,
text_val: Option<String>,
Expand All @@ -39,7 +40,7 @@ session

// Read MyType from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(MyType,)>()?;
let mut iter = result.rows::<(MyType,)>()?;
while let Some((my_type_value,)) = iter.next().transpose()? {
println!("{:?}", my_type_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/uuid.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ session

// Read uuid/timeuuid from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Uuid,)>()?;
let mut iter = result.rows::<(Uuid,)>()?;
while let Some((uuid_value,)) = iter.next().transpose()? {
println!("{:?}", uuid_value);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/data-types/varint.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ session

// Read a varint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(BigInt,)>()?;
let mut iter = result.rows::<(BigInt,)>()?;
while let Some((varint_value,)) = iter.next().transpose()? {
println!("{:?}", varint_value);
}
Expand Down
4 changes: 2 additions & 2 deletions docs/source/queries/paged.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ use scylla::query::Query;
let paged_query = Query::new("SELECT a, b, c FROM ks.t").with_page_size(6);
let res1 = session.query(paged_query.clone(), &[]).await?;
let res2 = session
.query_paged(paged_query.clone(), &[], res1.paging_state)
.query_paged(paged_query.clone(), &[], res1.paging_state())
.await?;
# Ok(())
# }
Expand All @@ -132,7 +132,7 @@ let paged_prepared = session
.await?;
let res1 = session.execute(&paged_prepared, &[]).await?;
let res2 = session
.execute_paged(&paged_prepared, &[], res1.paging_state)
.execute_paged(&paged_prepared, &[], res1.paging_state())
.await?;
# Ok(())
# }
Expand Down
Loading

0 comments on commit 0262a31

Please sign in to comment.