Skip to content

Commit

Permalink
codewide: migrate doctests to new deser API
Browse files Browse the repository at this point in the history
  • Loading branch information
wprzytula committed Nov 6, 2024
1 parent 560c6b3 commit 673b942
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 161 deletions.
26 changes: 13 additions & 13 deletions scylla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
//! `Session` is created by specifying a few known nodes and connecting to them:
//!
//! ```rust,no_run
//! use scylla::{LegacySession, SessionBuilder};
//! use scylla::{Session, SessionBuilder};
//! use std::error::Error;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//! let session: LegacySession = SessionBuilder::new()
//! let session: Session = SessionBuilder::new()
//! .known_node("127.0.0.1:9042")
//! .known_node("1.2.3.4:9876")
//! .build_legacy()
//! .build()
//! .await?;
//!
//! Ok(())
Expand All @@ -50,9 +50,9 @@
//!
//! The easiest way to specify bound values in a query is using a tuple:
//! ```rust
//! # use scylla::LegacySession;
//! # use scylla::Session;
//! # use std::error::Error;
//! # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
//! # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
//! // Insert an int and text into the table
//! session
//! .query_unpaged(
Expand All @@ -69,24 +69,24 @@
//! The easiest way to read rows returned by a query is to cast each row to a tuple of values:
//!
//! ```rust
//! # use scylla::LegacySession;
//! # use scylla::Session;
//! # use std::error::Error;
//! # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
//! use scylla::IntoTypedRows;
//! # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
//!
//! // Read rows containing an int and text
//! // Keep in mind that all results come in one response (no paging is done!),
//! // so the memory footprint and latency may be huge!
//! // To prevent that, use `Session::query_iter` or `Session::query_single_page`.
//! let rows_opt = session
//! let query_rows = session
//! .query_unpaged("SELECT a, b FROM ks.tab", &[])
//! .await?
//! .rows;
//! .into_rows_result()?;
//!
//!
//! if let Some(rows) = rows_opt {
//! for row in rows.into_typed::<(i32, String)>() {
//! if let Some(rows) = query_rows {
//! for row in rows.rows()? {
//! // Parse row as int and text \
//! let (int_val, text_val): (i32, String) = row?;
//! let (int_val, text_val): (i32, &str) = row?;
//! }
//! }
//! # Ok(())
Expand Down
12 changes: 6 additions & 6 deletions scylla/src/transport/execution_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! # extern crate scylla;
//! # use std::error::Error;
//! # async fn check_only_compiles() -> Result<(), Box<dyn Error>> {
//! use scylla::{LegacySession, SessionBuilder};
//! use scylla::{Session, SessionBuilder};
//! use scylla::statement::Consistency;
//! use scylla::transport::ExecutionProfile;
//!
Expand All @@ -27,10 +27,10 @@
//!
//! let handle = profile.into_handle();
//!
//! let session: LegacySession = SessionBuilder::new()
//! let session: Session = SessionBuilder::new()
//! .known_node("127.0.0.1:9042")
//! .default_execution_profile_handle(handle)
//! .build_legacy()
//! .build()
//! .await?;
//! # Ok(())
//! # }
Expand Down Expand Up @@ -109,7 +109,7 @@
//! # extern crate scylla;
//! # use std::error::Error;
//! # async fn check_only_compiles() -> Result<(), Box<dyn Error>> {
//! use scylla::{LegacySession, SessionBuilder};
//! use scylla::{Session, SessionBuilder};
//! use scylla::query::Query;
//! use scylla::statement::Consistency;
//! use scylla::transport::ExecutionProfile;
Expand All @@ -125,10 +125,10 @@
//! let mut handle1 = profile1.clone().into_handle();
//! let mut handle2 = profile2.clone().into_handle();
//!
//! let session: LegacySession = SessionBuilder::new()
//! let session: Session = SessionBuilder::new()
//! .known_node("127.0.0.1:9042")
//! .default_execution_profile_handle(handle1.clone())
//! .build_legacy()
//! .build()
//! .await?;
//!
//! let mut query1 = Query::from("SELECT * FROM ks.table");
Expand Down
80 changes: 44 additions & 36 deletions scylla/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ impl GenericSession<CurrentDeserializationApi> {
///
/// # Examples
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// // Insert an int and text into a table.
/// session
/// .query_unpaged(
Expand All @@ -500,24 +500,24 @@ impl GenericSession<CurrentDeserializationApi> {
/// # }
/// ```
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use scylla::IntoTypedRows;
///
/// // Read rows containing an int and text.
/// // Keep in mind that all results come in one response (no paging is done!),
/// // so the memory footprint and latency may be huge!
/// // To prevent that, use `Session::query_iter` or `Session::query_single_page`.
/// let rows_opt = session
/// .query_unpaged("SELECT a, b FROM ks.tab", &[])
/// let query_rows = session
/// .query_unpaged("SELECT a, b FROM ks.tab", &[])
/// .await?
/// .rows;
/// .into_rows_result()?;
///
/// if let Some(rows) = rows_opt {
/// for row in rows.into_typed::<(i32, String)>() {
/// // Parse row as int and text \
/// let (int_val, text_val): (i32, String) = row?;
/// if let Some(rows) = query_rows {
/// for row in rows.rows()? {
/// // Parse row as int and text.
/// let (int_val, text_val): (i32, &str) = row?;
/// }
/// }
/// # Ok(())
Expand Down Expand Up @@ -546,9 +546,9 @@ impl GenericSession<CurrentDeserializationApi> {
/// # Example
///
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use std::ops::ControlFlow;
/// use scylla::statement::PagingState;
///
Expand All @@ -560,7 +560,11 @@ impl GenericSession<CurrentDeserializationApi> {
/// .await?;
///
/// // Do something with a single page of results.
/// for row in res.rows_typed::<(i32, String)>()? {
/// for row in res
/// .into_rows_result()?
/// .unwrap()
/// .rows::<(i32, &str)>()?
/// {
/// let (a, b) = row?;
/// }
///
Expand Down Expand Up @@ -610,16 +614,16 @@ impl GenericSession<CurrentDeserializationApi> {
/// # Example
///
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use scylla::IntoTypedRows;
/// use futures::stream::StreamExt;
///
/// let mut rows_stream = session
/// .query_iter("SELECT a, b FROM ks.t", &[])
/// .await?
/// .into_typed::<(i32, i32)>();
/// .rows_stream::<(i32, i32)>()?;
///
/// while let Some(next_row_res) = rows_stream.next().await {
/// let (a, b): (i32, i32) = next_row_res?;
Expand Down Expand Up @@ -663,9 +667,9 @@ impl GenericSession<CurrentDeserializationApi> {
///
/// # Example
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use scylla::prepared_statement::PreparedStatement;
///
/// // Prepare the query for later execution
Expand Down Expand Up @@ -699,9 +703,9 @@ impl GenericSession<CurrentDeserializationApi> {
/// # Example
///
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use std::ops::ControlFlow;
/// use scylla::query::Query;
/// use scylla::statement::{PagingState, PagingStateResponse};
Expand All @@ -721,7 +725,11 @@ impl GenericSession<CurrentDeserializationApi> {
/// .await?;
///
/// // Do something with a single page of results.
/// for row in res.rows_typed::<(i32, String)>()? {
/// for row in res
/// .into_rows_result()?
/// .unwrap()
/// .rows::<(i32, &str)>()?
/// {
/// let (a, b) = row?;
/// }
///
Expand Down Expand Up @@ -767,12 +775,12 @@ impl GenericSession<CurrentDeserializationApi> {
/// # Example
///
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use futures::StreamExt as _;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use scylla::prepared_statement::PreparedStatement;
/// use scylla::IntoTypedRows;
/// use futures::stream::StreamExt;
///
/// // Prepare the query for later execution
/// let prepared: PreparedStatement = session
Expand All @@ -783,7 +791,7 @@ impl GenericSession<CurrentDeserializationApi> {
/// let mut rows_stream = session
/// .execute_iter(prepared, &[])
/// .await?
/// .into_typed::<(i32, i32)>();
/// .rows_stream::<(i32, i32)>()?;
///
/// while let Some(next_row_res) = rows_stream.next().await {
/// let (a, b): (i32, i32) = next_row_res?;
Expand Down Expand Up @@ -819,9 +827,9 @@ impl GenericSession<CurrentDeserializationApi> {
///
/// # Example
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use scylla::batch::Batch;
///
/// let mut batch: Batch = Default::default();
Expand Down Expand Up @@ -948,13 +956,13 @@ where
/// ```rust
/// # use std::error::Error;
/// # async fn check_only_compiles() -> Result<(), Box<dyn Error>> {
/// use scylla::{LegacySession, SessionConfig};
/// use scylla::{Session, SessionConfig};
/// use scylla::transport::KnownNode;
///
/// let mut config = SessionConfig::new();
/// config.known_nodes.push(KnownNode::Hostname("127.0.0.1:9042".to_string()));
///
/// let session: LegacySession = LegacySession::connect(config).await?;
/// let session: Session = Session::connect(config).await?;
/// # Ok(())
/// # }
/// ```
Expand Down Expand Up @@ -1286,9 +1294,9 @@ where
///
/// # Example
/// ```rust
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use scylla::prepared_statement::PreparedStatement;
///
/// // Prepare the query for later execution
Expand Down Expand Up @@ -1615,9 +1623,9 @@ where
/// /// # Example
/// ```rust
/// # extern crate scylla;
/// # use scylla::LegacySession;
/// # use scylla::Session;
/// # use std::error::Error;
/// # async fn check_only_compiles(session: &LegacySession) -> Result<(), Box<dyn Error>> {
/// # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
/// use scylla::batch::Batch;
///
/// // Create a batch statement with unprepared statements
Expand Down Expand Up @@ -1676,10 +1684,10 @@ where
/// * `case_sensitive` - if set to true the generated query will put keyspace name in quotes
/// # Example
/// ```rust
/// # use scylla::{LegacySession, SessionBuilder};
/// # use scylla::{Session, SessionBuilder};
/// # use scylla::transport::Compression;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let session = SessionBuilder::new().known_node("127.0.0.1:9042").build_legacy().await?;
/// # let session = SessionBuilder::new().known_node("127.0.0.1:9042").build().await?;
/// session
/// .query_unpaged("INSERT INTO my_keyspace.tab (a) VALUES ('test1')", &[])
/// .await?;
Expand Down
Loading

0 comments on commit 673b942

Please sign in to comment.