Skip to content

Commit

Permalink
examples/basic: query_unpaged -> query_[single_page/iter]
Browse files Browse the repository at this point in the history
In cases when we iterate over rows result, we make use of query_iter.
In other case, where we want to showcase the `Rows` structure,
we make use of `query_single_page`.
  • Loading branch information
muzarski committed Aug 28, 2024
1 parent cb8c123 commit f940879
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::Result;
use futures::TryStreamExt;
use scylla::macros::FromRow;
use scylla::transport::session::Session;
use scylla::transport::PagingState;
use scylla::SessionBuilder;
use std::env;

Expand Down Expand Up @@ -49,11 +51,11 @@ async fn main() -> Result<()> {
.await?;

// Rows can be parsed as tuples
let result = session
.query_unpaged("SELECT a, b, c FROM examples_ks.basic", &[])
.await?;
let mut iter = result.rows_typed::<(i32, i32, String)>()?;
while let Some((a, b, c)) = iter.next().transpose()? {
let mut iter = session
.query_iter("SELECT a, b, c FROM examples_ks.basic", &[])
.await?
.into_typed::<(i32, i32, String)>();
while let Some((a, b, c)) = iter.try_next().await? {
println!("a, b, c: {}, {}, {}", a, b, c);
}

Expand All @@ -65,17 +67,21 @@ async fn main() -> Result<()> {
_c: String,
}

let result = session
.query_unpaged("SELECT a, b, c FROM examples_ks.basic", &[])
.await?;
let mut iter = result.rows_typed::<RowData>()?;
while let Some(row_data) = iter.next().transpose()? {
let mut iter = session
.query_iter("SELECT a, b, c FROM examples_ks.basic", &[])
.await?
.into_typed::<RowData>();
while let Some(row_data) = iter.try_next().await? {
println!("row_data: {:?}", row_data);
}

// Or simply as untyped rows
let result = session
.query_unpaged("SELECT a, b, c FROM examples_ks.basic", &[])
let (result, _paging_state) = session
.query_single_page(
"SELECT a, b, c FROM examples_ks.basic",
&[],
PagingState::start(),
)
.await?;
let rows = result.rows.unwrap();
for row in rows {
Expand Down

0 comments on commit f940879

Please sign in to comment.