examples: add examples for resuming from the paging state
Query result now also contains the paging state, which can be
used to resume paging from previous queries.
@@ -40,22 +40,55 @@ async fn main() -> Result<()> {
println!("a, b, c: {}, {}, {}", a, b, c);
}
- let paged_query = Query::new("SELECT a, b, c FROM ks.t".to_owned()).with_page_size(1);
- let paging_state = session.query(paged_query, &[]).await?.paging_state;
- println!("Paging state: {:#?}", paging_state);
+ let paged_query = Query::new("SELECT a, b, c FROM ks.t".to_owned()).with_page_size(6);
+ let res1 = session.query(paged_query.clone(), &[]).await?;
+ println!(
+ "Paging state: {:#?} ({} rows)",
+ res1.paging_state,
+ res1.rows.unwrap().len()
+ );
+ let res2 = session
+ .query_paged(paged_query.clone(), &[], res1.paging_state)
+ .await?;
+ println!(
+ "Paging state: {:#?} ({} rows)",
+ res2.paging_state,
+ res2.rows.unwrap().len()
+ );
+ let res3 = session
+ .query_paged(paged_query.clone(), &[], res2.paging_state)
+ .await?;
+ println!(
+ "Paging state: {:#?} ({} rows)",
+ res3.paging_state,
+ res3.rows.unwrap().len()
+ );
let paged_prepared = session
- .prepare(Query::with_page_size(
- "SELECT a, b, c FROM ks.t".to_owned(),
- 1,
- ))
+ .prepare(Query::new("SELECT a, b, c FROM ks.t".to_owned()).with_page_size(7))
.await?;
- let paging_state_from_prepared = session.execute(&paged_prepared, &[]).await?.paging_state;
+ let res4 = session.execute(&paged_prepared, &[]).await?;
println!(
- "Paging state from the prepared statement execution: {:#?}",
- paging_state_from_prepared
+ "Paging state from the prepared statement execution: {:#?} ({} rows)",
+ res4.paging_state,
+ res4.rows.unwrap().len()
+ );
+ let res5 = session
+ .execute_paged(&paged_prepared, &[], res4.paging_state)
+ .await?;
+ println!(
+ "Paging state from the second prepared statement execution: {:#?} ({} rows)",
+ res5.paging_state,
+ res5.rows.unwrap().len()
+ );
+ let res6 = session
+ .execute_paged(&paged_prepared, &[], res5.paging_state)
+ .await?;
+ println!(
+ "Paging state from the third prepared statement execution: {:#?} ({} rows)",
+ res6.paging_state,
+ res6.rows.unwrap().len()
);
-
println!("Ok.");
Ok(())
