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
scyllaasync 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
FromScyllaRowfor a struct with named fields.
Structs§
- Scylla
Batch - A batch of CQL statements to execute atomically.
- Scylla
Config - Configuration for ScyllaDB connections.
- Scylla
Config Builder - Builder for
ScyllaConfig. - Scylla
Connection - A wrapper around a ScyllaDB session.
- Scylla
Engine - The ScyllaDB query engine.
- Scylla
Pool - A connection pool for ScyllaDB.
Enums§
- Scylla
Error - Errors that can occur during ScyllaDB operations.
- Scylla
Value - A wrapper type for CQL values that can be used in queries.
Traits§
- From
Scylla Row - Trait for types that can be constructed from a ScyllaDB row.
- ToCql
Value - Trait for types that can be converted to CQL values.
Type Aliases§
- Scylla
Result - Result type for ScyllaDB operations.