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 Sep 19, 2024
1 parent f41a11a commit 5a68a29
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 154 deletions.
26 changes: 12 additions & 14 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 @@ -70,22 +70,20 @@
//! 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
//! .query_unpaged("SELECT a, b FROM ks.tab", &[])
//! .await?
//! .rows;
//! let query_result = session
//! .query_unpaged("SELECT a, b FROM ks.tab", &[])
//! .await?;
//!
//! if let Some(rows) = rows_opt {
//! for row in rows.into_typed::<(i32, String)>() {
//! if let Some(rows) = query_result.maybe_rows::<(i32, String)>()? {
//! for row in rows {
//! // Parse row as int and text \
//! let (int_val, text_val): (i32, String) = row?;
//! }
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
60 changes: 29 additions & 31 deletions scylla/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,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 @@ -522,23 +522,22 @@ 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", &[])
/// .await?
/// .rows;
///
/// if let Some(rows) = rows_opt {
/// for row in rows.into_typed::<(i32, String)>() {
/// // Parse row as int and text \
/// let query_result = session
/// .query_unpaged("SELECT a, b FROM ks.tab", &[])
/// .await?;
///
/// if let Some(rows) = query_result.maybe_rows::<(i32, String)>()? {
/// for row in rows {
/// // Parse row as int and text.
/// let (int_val, text_val): (i32, String) = row?;
/// }
/// }
Expand Down Expand Up @@ -632,16 +631,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)>();
/// .into_typed::<(i32, i32)>()?;
///
/// while let Some(next_row_res) = rows_stream.next().await {
/// let (a, b): (i32, i32) = next_row_res?;
Expand Down Expand Up @@ -685,9 +684,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 @@ -789,12 +788,11 @@ 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;
/// use scylla::IntoTypedRows;
/// use futures::stream::StreamExt;
///
/// // Prepare the query for later execution
/// let prepared: PreparedStatement = session
Expand All @@ -805,7 +803,7 @@ impl GenericSession<CurrentDeserializationApi> {
/// let mut rows_stream = session
/// .execute_iter(prepared, &[])
/// .await?
/// .into_typed::<(i32, i32)>();
/// .into_typed::<(i32, i32)>()?;
///
/// while let Some(next_row_res) = rows_stream.next().await {
/// let (a, b): (i32, i32) = next_row_res?;
Expand Down Expand Up @@ -841,9 +839,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 @@ -970,13 +968,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 @@ -1303,9 +1301,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 @@ -1631,9 +1629,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 @@ -1692,10 +1690,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 5a68a29

Please sign in to comment.