Expand description
§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:
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);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.
Re-exports§
pub use reqwest;
Modules§
- migration
- Upgrade from 0.3 to 0.4
Structs§
- Append
Admission Result - Rows accepted by a bulk local-admission operation.
- Append
Batch Failure Event - Diagnostic event emitted after a rejected or ambiguous append batch.
- Append
Circuit Breaker Options - Continue-mode circuit breaker settings.
- Append
Delivery Report - Aggregate settlement information since the previous delivery barrier. Counts do not identify individual input records. Use application-owned business keys to reconcile rows before replaying them.
- Append
Dropped Rows - Local drop counters grouped by admission failure reason.
- Append
Error Details - Structured failure details returned by the table append API.
- Append
Last Failure - The most recent remote append failure observed by the stream.
- Append
RowError - A validation error for one row in an append request.
- Append
Rows Result - The result of a committed table append.
- Append
Stream - A cloneable, bounded producer handle for asynchronous table appends. Dropping every handle drains admitted rows in the background while the Tokio runtime remains alive. Use shutdown() to observe settlement before exiting.
- Append
Stream Builder - Configures a bounded, concurrent table append stream.
- Append
Stream Stats - A point-in-time snapshot of append stream counters and state.
- Catalog
- Reads database, schema, table, and view definitions.
- Catalog
Column - Catalog
Column Index - Additional column index. Supports type “search” and analyzer “log”.
- Catalog
Database - Catalog
Distinct - Catalog
Document - Complete tenant catalog. Apply replaces the entire selected subtree.
Typed definitions reject unknown fields; use
Catalog::rawfor newer definitions. - Catalog
Options - Preview, concurrency preconditions, and explicit data-loss authorization.
- Catalog
Resource - A selected subtree. Names are unescaped identifiers. Apply replaces the whole definition; it is not a patch. Mutations never retry automatically.
- Catalog
Result - Normalized states compared in one transaction; None means absent.
- Catalog
Schema - Catalog
Snapshot - Catalog
Table - A complete table definition. Omitted collections are empty and omitted optional fields are cleared. Storage is accepted only at creation.
- Catalog
View - Client
- An async client for queries, table writes, and catalog operations.
- Client
Builder - Builds a ScopeDB client with an optional API key and custom HTTP client.
- Error
- A failure with a message, optional HTTP diagnostics, and operation details.
- Field
Schema - Result
Set - Schema
- Statement
- A query with optional execution limits. Use
Self::executeto wait for its result, orSelf::submitto retain a handle for progress and cancellation. - Statement
Error Details - Structured failure returned for a failed statement.
- Statement
Estimated Progress - Statement
Handle - Tracks one submitted query. Keep the handle to inspect progress, wait for results, or request cancellation.
- Statement
Progress - Statement
Status Cancelled - Statement
Status Failed - Statement
Status Finished - Statement
Status Pending - Statement
Status Running - Table
- A table selected for writes or catalog reads.
- Write
Error Details - Details of an interrupted write. An unknown outcome may have committed and must not be automatically replayed.
Enums§
- Append
Batch Failure Action - Action taken after a batch failure listener is invoked.
- Append
Circuit State - The state of the continue-mode availability circuit breaker.
- Append
Delivery Outcome - The aggregate result of a delivery barrier.
- Append
Failure Policy - Determines what an append stream does after one HTTP batch fails.
- Append
State - The commit outcome used by table append responses and client-side write interruptions.
- Append
Stream State - The lifecycle state of an append stream.
- Append
TrySend Error - A synchronous local-admission failure from
AppendStream::try_send. - Data
Type - Error
Kind - ErrorKind is all kinds of Error of ScopeDB client.
- Statement
Status - Value
- A typed result cell. Equality compares encoded array, object, any, and binary values as strings; floats use Rust’s usual equality, including NaN != NaN.
- Write
Error Reason - The client-side reason an in-flight write was interrupted.
Type Aliases§
- Result
Object - One typed result row keyed by its ScopeQL output column name.