scopedb-client 0.4.2

The official Rust client for ScopeDB
Documentation

ScopeDB SDK for Rust

Query ScopeDB and write rows from async Rust applications.

Upgrading an existing application? See Upgrade from 0.3 to 0.4, including the move from Ingest to Append.

Install

Requires Rust 1.91.0 or later and Tokio.

cargo add scopedb-client serde_json
cargo add tokio --features macros,rt-multi-thread

Run a query

Set SCOPEDB_ENDPOINT and SCOPEDB_API_KEY using the connection guide. Save this as src/main.rs and run cargo run:

use std::error::Error;

use scopedb_client::Client;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn Error>> {
    let endpoint = std::env::var("SCOPEDB_ENDPOINT")?;
    let api_key = std::env::var("SCOPEDB_API_KEY")?;
    let client = Client::builder(endpoint)
        .api_key(api_key)
        .build()?;

    let result = client.query("SELECT 1 AS ready").await?;
    println!("{:?}", result.into_objects()?);
    Ok(())
}

query() waits for the result. into_objects() returns rows keyed by column name.

Write rows

With an existing events table containing id int and name string columns:

# async fn example(client: scopedb_client::Client) -> Result<(), scopedb_client::Error> {
let stream = client.table("events")
    .append_stream()
    .build()?;
let row = serde_json::json!({"id": 1, "name": "page_view"});
stream.send(&row).await?;

let report = stream.shutdown().await?;
println!("Written: {} rows", report.committed_rows);
# Ok(())
# }

send() queues a row; shutdown() waits for pending writes and closes the stream. Use flush() to wait while keeping it open. If you already have NDJSON, use Table::append.

Find what you need

Task API reference
Read query results ResultSet
Track or cancel a query StatementHandle
Read or change table schemas Catalog
Tune batching and retries AppendStreamBuilder
Write logs or telemetry Continue after a batch fails
Set timeouts or HTTP options ClientBuilder
Inspect a failure Error

For complete programs, see the examples. For ScopeQL syntax, see the query guide.