Skip to main content

Crate prax_scylladb

Crate prax_scylladb 

Source
Expand description

§prax-scylladb

ScyllaDB database driver for Prax ORM - high-performance Cassandra-compatible database.

ScyllaDB is a drop-in replacement for Apache Cassandra that offers significantly better performance. This driver provides async support for ScyllaDB operations within the Prax ORM ecosystem.

§Features

  • High Performance: Built on the official scylla async driver
  • Connection Pooling: Automatic connection management with configurable pool sizes
  • Prepared Statements: Efficient query execution with automatic caching
  • Async/Await: Full async support with Tokio runtime
  • Type Safety: Strong typing with automatic CQL type conversions
  • Lightweight Transactions: Support for conditional updates (LWT)

§Quick Start

use prax_scylladb::{ScyllaConfig, ScyllaPool};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Configure the connection
    let config = ScyllaConfig::builder()
        .known_nodes(["127.0.0.1:9042"])
        .default_keyspace("my_keyspace")
        .build();

    // Create connection pool
    let pool = ScyllaPool::connect(config).await?;

    // Execute queries
    let result = pool
        .query("SELECT * FROM users WHERE id = ?", (user_id,))
        .await?;

    Ok(())
}

§Configuration

use prax_scylladb::ScyllaConfig;

let config = ScyllaConfig::builder()
    .known_nodes(["node1:9042", "node2:9042", "node3:9042"])
    .default_keyspace("production")
    .username("admin")
    .password("secret")
    .connection_timeout_secs(10)
    .request_timeout_secs(30)
    .build();

§Prepared Statements

For frequently executed queries, use prepared statements:

use prax_scylladb::ScyllaEngine;

async fn get_user(engine: &ScyllaEngine, id: uuid::Uuid) -> Result<Option<User>, Error> {
    engine
        .query_one("SELECT * FROM users WHERE id = ?", (id,))
        .await
}

§Batch Operations

Execute multiple statements atomically:

use prax_scylladb::ScyllaEngine;

async fn transfer_funds(
    engine: &ScyllaEngine,
    from: uuid::Uuid,
    to: uuid::Uuid,
    amount: i64,
) -> Result<(), Error> {
    engine.batch()
        .add("UPDATE accounts SET balance = balance - ? WHERE id = ?", (amount, from))
        .add("UPDATE accounts SET balance = balance + ? WHERE id = ?", (amount, to))
        .execute()
        .await
}

Modules§

prelude
Prelude module for convenient imports.

Macros§

impl_from_row
A macro to implement FromScyllaRow for a struct with named fields.

Structs§

ScyllaBatch
A batch of CQL statements to execute atomically.
ScyllaConfig
Configuration for ScyllaDB connections.
ScyllaConfigBuilder
Builder for ScyllaConfig.
ScyllaConnection
A wrapper around a ScyllaDB session.
ScyllaEngine
The ScyllaDB query engine.
ScyllaPool
A connection pool for ScyllaDB.

Enums§

ScyllaError
Errors that can occur during ScyllaDB operations.
ScyllaValue
A wrapper type for CQL values that can be used in queries.

Traits§

FromScyllaRow
Trait for types that can be constructed from a ScyllaDB row.
ToCqlValue
Trait for types that can be converted to CQL values.

Type Aliases§

ScyllaResult
Result type for ScyllaDB operations.