Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

An async client for queries, table writes, and catalog operations.

Start with Self::builder to configure your endpoint and API key. Clones share the underlying HTTP connection pool.

Implementations§

Source§

impl Client

Source

pub fn builder(endpoint: impl ToString) -> ClientBuilder

Starts a client builder for the common API-key authentication path.

Examples found in repository?
examples/common/mod.rs (line 43)
34pub fn client() -> Result<Client, Box<dyn std::error::Error>> {
35    let api_key = std::env::var("SCOPEDB_API_KEY")
36        .ok()
37        .filter(|value| !value.is_empty())
38        .or_else(|| {
39            std::env::var("SCOPEDB_TOKEN")
40                .ok()
41                .filter(|value| !value.is_empty())
42        });
43    let mut builder = Client::builder(endpoint());
44    if let Some(api_key) = api_key {
45        builder = builder.api_key(api_key);
46    }
47    Ok(builder.build()?)
48}
Source

pub fn new<E: IntoUrl>(endpoint: E, client: Client) -> Result<Self, Error>

Creates a ScopeDB client from an endpoint and a compatible HTTP client.

Use the HTTP types re-exported from crate::reqwest to avoid a dependency-version mismatch in applications using another reqwest major. Configure the HTTP client as described in ClientBuilder::http_client to prevent automatic write replay. The write timeout defaults to 30 seconds.

Source

pub fn statement(&self, statement: impl Into<String>) -> Statement

Examples found in repository?
examples/statement.rs (line 27)
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19    let client = common::client()?;
20
21    let result = client.query("SELECT 1 AS ready").await?;
22    let rows = result.into_objects()?;
23    println!("rows: {rows:?}");
24
25    // Keep the handle when an application needs progress, cancellation, or a
26    // durable statement ID before waiting for the result.
27    let mut handle = client.statement("SELECT 2 AS value").submit().await?;
28    let statement_id = handle.statement_id();
29    println!(
30        "statement {statement_id} submitted: {:?}",
31        handle.snapshot()
32    );
33    let status = handle.refresh().await?;
34    println!("statement {statement_id}: {status:?}");
35    let result = handle.wait().await?;
36    println!("handle rows: {:?}", result.into_objects()?);
37    Ok(())
38}
Source

pub fn statement_handle(&self, statement_id: Uuid) -> StatementHandle

Source

pub fn table(&self, table: impl Into<String>) -> Table

Examples found in repository?
examples/common/mod.rs (line 62)
50pub fn write_table(client: &Client) -> Result<Table, io::Error> {
51    let table = std::env::var("SCOPEDB_TABLE")
52        .ok()
53        .filter(|value| !value.is_empty())
54        .ok_or_else(|| {
55            io::Error::new(
56                io::ErrorKind::InvalidInput,
57                "set SCOPEDB_TABLE to a disposable table before running this write example",
58            )
59        })?;
60
61    Ok(client
62        .table(table)
63        .with_database(database())
64        .with_schema(schema()))
65}
More examples
Hide additional examples
examples/table.rs (line 22)
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19    let client = common::client()?;
20    let table_name = std::env::var("SCOPEDB_TABLE").unwrap_or_else(|_| "events".to_string());
21    let table = client
22        .table(table_name)
23        .with_database(common::database())
24        .with_schema(common::schema());
25
26    println!("identifier: {}", table.identifier());
27
28    let description = table.catalog().get().await?.definition;
29    for column in description.columns {
30        println!("{}: {:?}", column.name, column.data_type);
31    }
32
33    Ok(())
34}
Source

pub async fn query( &self, statement: impl Into<String>, ) -> Result<ResultSet, Error>

Executes a ScopeQL statement and waits for all result rows. Errors after submission retain Error::statement_id for resuming the existing execution with Self::statement_handle, not resubmitting it.

Examples found in repository?
examples/statement.rs (line 21)
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19    let client = common::client()?;
20
21    let result = client.query("SELECT 1 AS ready").await?;
22    let rows = result.into_objects()?;
23    println!("rows: {rows:?}");
24
25    // Keep the handle when an application needs progress, cancellation, or a
26    // durable statement ID before waiting for the result.
27    let mut handle = client.statement("SELECT 2 AS value").submit().await?;
28    let statement_id = handle.statement_id();
29    println!(
30        "statement {statement_id} submitted: {:?}",
31        handle.snapshot()
32    );
33    let status = handle.refresh().await?;
34    println!("statement {statement_id}: {status:?}");
35    let result = handle.wait().await?;
36    println!("handle rows: {:?}", result.into_objects()?);
37    Ok(())
38}
Source

pub fn catalog(&self) -> Catalog

Selects the complete declarative catalog or an individual resource.

Examples found in repository?
examples/catalog.rs (line 23)
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19    let client = common::client()?;
20    let database = common::database();
21    let schema = common::schema();
22
23    let catalog = client.catalog().get().await?;
24    for item in catalog.definition.databases {
25        println!(
26            "database {}: {}",
27            item.name,
28            item.comment.unwrap_or_default()
29        );
30    }
31    let snapshot = client.catalog().schema(&database, &schema).get().await?;
32    println!("schema ETag: {}", snapshot.etag);
33    for table in snapshot.definition.tables {
34        println!("table {}: {:?}", table.name, table.columns);
35    }
36    Ok(())
37}
Source

pub async fn append_rows( &self, database: &str, schema: &str, table: &str, ndjson: impl Into<String>, ) -> Result<AppendRowsResult, Error>

Appends at most 8 MiB of uncompressed newline-delimited JSON to a table.

Sends one request without automatic retries. An unknown outcome remains non-retryable through Error::is_retryable because replay may duplicate rows.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more