Skip to content

Commit

Permalink
Merge pull request #1061 from wprzytula/paging-api-hardening
Browse files Browse the repository at this point in the history
Query paging API: hardening, robustness, explicitness
  • Loading branch information
wprzytula authored Aug 27, 2024
2 parents 78286c3 + a1286de commit 5752af4
Show file tree
Hide file tree
Showing 91 changed files with 1,537 additions and 983 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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 result = session.query_unpaged("SELECT a, b, c FROM ks.t", &[]).await?;
let mut iter = result.rows_typed::<(i32, i32, String)>()?;
while let Some((a, b, c)) = iter.next().transpose()? {
println!("a, b, c: {}, {}, {}", a, b, c);
Expand Down
4 changes: 2 additions & 2 deletions docs/source/data-types/blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use scylla::IntoTypedRows;
// We can insert it by reference to not move the whole blob
let to_insert: Vec<u8> = vec![1, 2, 3, 4, 5];
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&to_insert,))
.await?;

// Read blobs from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Vec<u8>,)>()?;
while let Some((blob_value,)) = iter.next().transpose()? {
println!("{:?}", blob_value);
Expand Down
24 changes: 12 additions & 12 deletions docs/source/data-types/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use scylla::IntoTypedRows;
// Insert a list of ints into the table
let my_list: Vec<i32> = vec![1, 2, 3, 4, 5];
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_list,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_list,))
.await?;

// Read a list of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Vec<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
Expand All @@ -39,11 +39,11 @@ use scylla::IntoTypedRows;
// Insert a set of ints into the table
let my_set: Vec<i32> = vec![1, 2, 3, 4, 5];
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.await?;

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Vec<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
Expand All @@ -63,11 +63,11 @@ use std::collections::HashSet;
// Insert a set of ints into the table
let my_set: HashSet<i32> = vec![1, 2, 3, 4, 5].into_iter().collect();
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.await?;

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(HashSet<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
Expand All @@ -87,11 +87,11 @@ use std::collections::BTreeSet;
// Insert a set of ints into the table
let my_set: BTreeSet<i32> = vec![1, 2, 3, 4, 5].into_iter().collect();
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (&my_set,))
.await?;

// Read a set of ints from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(BTreeSet<i32>,)>()?;
while let Some((list_value,)) = iter.next().transpose()? {
println!("{:?}", list_value);
Expand All @@ -116,11 +116,11 @@ let mut my_map: HashMap<String, i32> = HashMap::new();
my_map.insert("abcd".to_string(), 16);

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

// Read a map from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(HashMap<String, i32>,)>()?;
while let Some((map_value,)) = iter.next().transpose()? {
println!("{:?}", map_value);
Expand All @@ -142,11 +142,11 @@ let mut my_map: BTreeMap<String, i32> = BTreeMap::new();
my_map.insert("abcd".to_string(), 16);

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

// Read a map from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(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 @@ -11,7 +11,7 @@ use scylla::IntoTypedRows;
use scylla::frame::value::Counter;

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

// Insert date into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read raw Date from the table
if let Some(rows) = session
.query("SELECT a FROM keyspace.table", &[])
.query_unpaged("SELECT a FROM keyspace.table", &[])
.await?
.rows
{
Expand Down Expand Up @@ -63,11 +63,11 @@ let to_insert = NaiveDate::from_ymd_opt(2021, 3, 24).unwrap();

// Insert date into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read NaiveDate from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(NaiveDate,)>()?;
while let Some((date_value,)) = iter.next().transpose()? {
println!("{:?}", date_value);
Expand Down Expand Up @@ -97,11 +97,11 @@ let to_insert = Date::from_calendar_date(2021, Month::March, 24).unwrap();

// Insert date into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read Date from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Date,)>()?;
while let Some((date_value,)) = iter.next().transpose()? {
println!("{:?}", date_value);
Expand Down
8 changes: 4 additions & 4 deletions docs/source/data-types/decimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use std::str::FromStr;
let to_insert: CqlDecimal =
CqlDecimal::from_signed_be_bytes_and_exponent(vec![0x01, 0xE2, 0x40], 3);
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a decimal from the table
if let Some(rows) = session.query("SELECT a FROM keyspace.table", &[]).await?.rows {
if let Some(rows) = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?.rows {
for row in rows.into_typed::<(CqlDecimal,)>() {
let (decimal_value,): (CqlDecimal,) = row?;
}
Expand All @@ -48,11 +48,11 @@ use std::str::FromStr;
// Insert a decimal into the table
let to_insert: BigDecimal = BigDecimal::from_str("12345.0")?;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a decimal from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(BigDecimal,)>()?;
while let Some((decimal_value,)) = iter.next().transpose()? {
println!("{:?}", decimal_value);
Expand Down
4 changes: 2 additions & 2 deletions docs/source/data-types/duration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use scylla::frame::value::CqlDuration;
// Insert some duration into the table
let to_insert: CqlDuration = CqlDuration { months: 1, days: 2, nanoseconds: 3 };
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read duration from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(CqlDuration,)>()?;
while let Some((duration_value,)) = iter.next().transpose()? {
println!("{:?}", duration_value);
Expand Down
4 changes: 2 additions & 2 deletions docs/source/data-types/inet.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use std::net::{IpAddr, Ipv4Addr};
// Insert some ip address into the table
let to_insert: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read inet from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(IpAddr,)>()?;
while let Some((inet_value,)) = iter.next().transpose()? {
println!("{:?}", inet_value);
Expand Down
28 changes: 14 additions & 14 deletions docs/source/data-types/primitive.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use scylla::IntoTypedRows;
// Insert a bool into the table
let to_insert: bool = true;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a bool from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(bool,)>()?;
while let Some((bool_value,)) = iter.next().transpose()? {
println!("{}", bool_value);
Expand All @@ -41,11 +41,11 @@ use scylla::IntoTypedRows;
// Insert a tinyint into the table
let to_insert: i8 = 123;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a tinyint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i8,)>()?;
while let Some((tinyint_value,)) = iter.next().transpose()? {
println!("{:?}", tinyint_value);
Expand All @@ -68,11 +68,11 @@ use scylla::IntoTypedRows;
// Insert a smallint into the table
let to_insert: i16 = 12345;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a smallint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i16,)>()?;
while let Some((smallint_value,)) = iter.next().transpose()? {
println!("{}", smallint_value);
Expand All @@ -95,11 +95,11 @@ use scylla::IntoTypedRows;
// Insert an int into the table
let to_insert: i32 = 12345;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read an int from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i32,)>()?;
while let Some((int_value,)) = iter.next().transpose()? {
println!("{}", int_value);
Expand All @@ -122,11 +122,11 @@ use scylla::IntoTypedRows;
// Insert a bigint into the table
let to_insert: i64 = 12345;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a bigint from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(i64,)>()?;
while let Some((bigint_value,)) = iter.next().transpose()? {
println!("{:?}", bigint_value);
Expand All @@ -149,11 +149,11 @@ use scylla::IntoTypedRows;
// Insert a float into the table
let to_insert: f32 = 123.0;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a float from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(f32,)>()?;
while let Some((float_value,)) = iter.next().transpose()? {
println!("{:?}", float_value);
Expand All @@ -176,11 +176,11 @@ use scylla::IntoTypedRows;
// Insert a double into the table
let to_insert: f64 = 12345.0;
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read a double from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(f64,)>()?;
while let Some((double_value,)) = iter.next().transpose()? {
println!("{:?}", double_value);
Expand Down
6 changes: 3 additions & 3 deletions docs/source/data-types/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ use scylla::IntoTypedRows;
// Insert some text into the table as a &str
let to_insert_str: &str = "abcdef";
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert_str,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert_str,))
.await?;

// Insert some text into the table as a String
let to_insert_string: String = "abcdef".to_string();
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert_string,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert_string,))
.await?;

// Read ascii/text/varchar from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(String,)>()?;
while let Some((text_value,)) = iter.next().transpose()? {
println!("{}", text_value);
Expand Down
12 changes: 6 additions & 6 deletions docs/source/data-types/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ let to_insert = CqlTime(64 * 1_000_000_000);

// Insert time into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read time from the table
if let Some(rows) = session
.query("SELECT a FROM keyspace.table", &[])
.query_unpaged("SELECT a FROM keyspace.table", &[])
.await?
.rows
{
Expand Down Expand Up @@ -63,11 +63,11 @@ let to_insert = NaiveTime::from_hms_nano_opt(1, 2, 3, 456_789_012);

// Insert time into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read time from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(NaiveTime,)>()?;
while let Some((time_value,)) = iter.next().transpose()? {
println!("{:?}", time_value);
Expand Down Expand Up @@ -95,11 +95,11 @@ let to_insert = Time::from_hms_nano(1, 2, 3, 456_789_012).unwrap();

// Insert time into the table
session
.query("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
.await?;

// Read time from the table
let result = session.query("SELECT a FROM keyspace.table", &[]).await?;
let result = session.query_unpaged("SELECT a FROM keyspace.table", &[]).await?;
let mut iter = result.rows_typed::<(Time,)>()?;
while let Some((time_value,)) = iter.next().transpose()? {
println!("{:?}", time_value);
Expand Down
Loading

0 comments on commit 5752af4

Please sign in to comment.