Skip to main content

Crate scriva

Crate scriva 

Source
Expand description

ScrivaDB Rust client — async gRPC wrapper over proto/scriva.proto.

All methods are async and require a Tokio runtime.

§Quick start

use scriva::{ScrivaDB, FilterInput, FilterOp, FindOptions};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let mut db = ScrivaDB::connect("localhost", 5433, "dev-key").await?;

    db.create_collection("users").await?;

    let id = db.insert("users", serde_json::json!({"name": "Alice", "age": 30})).await?;
    let record = db.find_by_id("users", id).await?;
    println!("{:?}", record);

    let admins = db.find("users", FindOptions {
        filter: Some(FilterInput::field("role", FilterOp::Eq, "admin")),
        ..Default::default()
    }).await?;
    println!("{} admins", admins.len());

    db.drop_collection("users").await?;
    Ok(())
}

Structs§

AggregateGroup
One group’s result from ScrivaDB::aggregate.
AggregateOptions
Options for ScrivaDB::aggregate.
CasResult
Result of a compare-and-swap update (ScrivaDB::update_if_rev).
CollectionStats
Collection statistics returned by stats.
FindOptions
Options for the find methods.
OrderBy
One sort key and its direction, for the multi-field ordering of a find.
Record
A record returned by the server.
ScrivaDB
Async gRPC client for ScrivaDB.
UpdateResult
Result of a keyed update (ScrivaDB::update_by_key).
WatchEvent
A change event delivered by the watch stream.

Enums§

AggregateOp
A numeric aggregation to compute per group over a request’s field.
FilterInput
A composable filter for find and watch queries.
FilterOp
Comparison operator for a FilterInput::Field.
ScrivaDbError
Errors returned by ScrivaDB RPC methods.
WatchOp
The operation type in a WatchEvent.

Type Aliases§

Error
Transport / setup errors from ScrivaDB::connect, ScrivaDB::connect_tls and the file-writing snapshot helper. RPC methods return ScrivaDbError.