Crate scylla

Source
Expand description

Async Rust driver for the Scylla database written in Rust. Although optimized for Scylla, the driver is also compatible with Apache Cassandra®.

§Documentation book

The best source to learn about this driver is the documentation book.
This page contains mainly API documentation

§Other documentation

§Driver overview

§Connecting

All driver activity revolves around the Session
Session is created by specifying a few known nodes and connecting to them:

use scylla::{Session, SessionBuilder};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
   let session: Session = SessionBuilder::new()
        .known_node("127.0.0.1:9042")
        .known_node("1.2.3.4:9876")
        .build()
        .await?;

   Ok(())
}

Session is usually created using the SessionBuilder.
All configuration options for a Session can be specified while building.

§Making queries

After successfully connecting to the cluster we can make queries.
The driver supports multiple query types:

To specify options for a single query create the query object and configure it:

The easiest way to specify bound values in a query is using a tuple:

// Insert an int and text into the table
session
    .query_unpaged(
        "INSERT INTO ks.tab (a, b) VALUES(?, ?)",
        (2_i32, "some text")
    )
    .await?;

But the driver will accept anything implementing the trait SerializeRow.

§Receiving results

The easiest way to read rows returned by a query is to cast each row to a tuple of values:


// 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 query_rows = session
    .query_unpaged("SELECT a, b FROM ks.tab", &[])
    .await?
    .into_rows_result()?;
     
for row in query_rows.rows()? {
    // Parse row as int and text \
    let (int_val, text_val): (i32, &str) = row?;
}

See the book for more receiving methods

Re-exports§

Modules§

Macros§

Structs§

Traits§

  • A trait for values that provide sequential write access to bytes.
  • FromRowDeprecated
    This trait defines a way to convert CQL Row into some rust type

Type Aliases§

Derive Macros§

  • Derive macro for the DeserializeRow trait that generates an implementation which deserializes a row with a similar layout to the Rust struct.
  • Derive macro for the DeserializeValue trait that generates an implementation which deserializes a User Defined Type with the same layout as the Rust struct.
  • Derive macro for the FromRow trait which deserializes a row to given Rust structure.
  • #[derive(FromUserType)] allows to parse struct as a User Defined Type
  • #[derive(IntoUserType)] allows to pass struct a User Defined Type Value in queries
  • Derive macro for the SerializeRow trait which serializes given Rust structure into bind markers for a CQL statement.
  • Derive macro for the SerializeValue trait which serializes given Rust structure as a User Defined Type (UDT).
  • #[derive(ValueList)] allows to pass struct as a list of values for a query