Skip to content

Commit

Permalink
examples/basic: query_unpaged -> query_iter
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Aug 28, 2024
1 parent cf26d88 commit 5e78c02
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::Result;
use futures::TryStreamExt;
use scylla::frame::response::result::Row;
use scylla::macros::FromRow;
use scylla::transport::session::Session;
use scylla::SessionBuilder;
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,20 +67,20 @@ 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", &[])
.await?;
let rows = result.rows.unwrap();
for row in rows {
let mut iter = session
.query_iter("SELECT a, b, c FROM examples_ks.basic", &[])
.await?
.into_typed::<Row>();
while let Some(row) = iter.try_next().await? {
let a = row.columns[0].as_ref().unwrap().as_int().unwrap();
let b = row.columns[1].as_ref().unwrap().as_int().unwrap();
let c = row.columns[2].as_ref().unwrap().as_text().unwrap();
Expand Down

0 comments on commit 5e78c02

Please sign in to comment.