Skip to main content

KalamLinkClient

Struct KalamLinkClient 

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

Main KalamDB client.

Use KalamLinkClientBuilder to construct instances with custom configuration.

§Examples

use kalam_client::KalamLinkClient;

let client = KalamLinkClient::builder()
    .base_url("http://localhost:3000")
    .timeout(std::time::Duration::from_secs(30))
    .build()?;

let response = client.execute_query("SELECT 1", None, None, None).await?;
println!("Result: {:?}", response);

Implementations§

Source§

impl KalamLinkClient

Source

pub async fn login( &self, user: &str, password: &str, ) -> Result<LoginResponse, KalamLinkError>

Login with user and password to obtain a JWT token.

Source

pub async fn refresh_access_token( &self, refresh_token: &str, ) -> Result<LoginResponse, KalamLinkError>

Refresh an access token using a refresh token.

Source§

impl KalamLinkClient

Source

pub fn builder() -> KalamLinkClientBuilder

Create a new builder for configuring the client

Source

pub async fn execute_query( &self, sql: &str, files: Option<Vec<(&str, &str, Vec<u8>, Option<&str>)>>, params: Option<Vec<Value>>, namespace_id: Option<&str>, ) -> Result<QueryResponse, KalamLinkError>

Execute a SQL query with optional files, parameters, and namespace context

§Arguments
  • sql - The SQL query string
  • files - Optional file uploads for FILE(“name”) placeholders
  • params - Optional query parameters for $1, $2, … placeholders
  • namespace_id - Optional namespace for unqualified table names
§Example
// Simple query
let result = client.execute_query("SELECT * FROM users", None, None, None).await?;

// Query with parameters
let params = vec![serde_json::json!(42)];
let result = client.execute_query("SELECT * FROM users WHERE id = $1", None, Some(params), None).await?;

// Query in specific namespace
let result = client.execute_query("SELECT * FROM messages", None, None, Some("chat")).await?;
Source

pub async fn execute_query_with_progress( &self, sql: &str, files: Option<Vec<(&str, &str, Vec<u8>, Option<&str>)>>, params: Option<Vec<Value>>, namespace_id: Option<&str>, progress: Option<Arc<dyn Fn(UploadProgress) + Send + Sync>>, ) -> Result<QueryResponse, KalamLinkError>

Execute a SQL query with optional files and a progress callback for uploads.

Source

pub async fn live_events( &self, query: &str, ) -> Result<SubscriptionManager, KalamLinkError>

Open a low-level live event stream.

Live streams are multiplexed over the shared WebSocket connection.

Source

pub async fn live_events_with_config( &self, config: SubscriptionConfig, ) -> Result<SubscriptionManager, KalamLinkError>

Open a low-level live event stream with advanced configuration.

When [ConnectionOptions::ws_lazy_connect] is true (the default) and no shared connection exists yet, connect() is called automatically before opening the stream.

Source

pub async fn live( &self, query: &str, ) -> Result<LiveRowsSubscription, KalamLinkError>

Open a SQL query and receive materialized row snapshots.

Source

pub async fn live_with_config( &self, config: SubscriptionConfig, live_rows_config: LiveRowsConfig, ) -> Result<LiveRowsSubscription, KalamLinkError>

Open materialized live rows with advanced low-level and materialization configuration.

Source

pub async fn connect(&self) -> Result<(), KalamLinkError>

Establish a shared WebSocket connection.

After calling this, all subsequent live_events() and live() calls will multiplex over the single connection.

Source

pub async fn disconnect(&self)

Disconnect the shared WebSocket connection.

Source

pub async fn cancel_subscription(&self, id: &str) -> Result<(), KalamLinkError>

Cancel / unsubscribe a subscription by ID on the shared connection.

Source

pub async fn is_connected(&self) -> bool

Whether the shared connection is currently ready.

During reconnect with active subscriptions, this stays false until the subscription set has recovered, not merely until the socket handshake succeeds.

Source

pub async fn subscriptions(&self) -> Vec<SubscriptionInfo>

List all active subscriptions on the shared connection.

Source

pub fn event_handlers(&self) -> &EventHandlers

Get the current event handlers

Source

pub fn timeouts(&self) -> &KalamLinkTimeouts

Get the configured timeouts

Source

pub fn resolved_auth(&self) -> &ResolvedAuth

Return the resolved auth source (static or dynamic).

Source

pub fn set_auth(&mut self, auth: AuthProvider)

Replace the static authentication credentials at runtime.

Source

pub fn update_shared_auth(&self, auth: AuthProvider)

Update the shared authentication source without requiring &mut self.

Source

pub async fn fresh_auth(&self) -> Result<AuthProvider, KalamLinkError>

Resolve fresh credentials from the auth source.

Trait Implementations§

Source§

impl Clone for KalamLinkClient

Source§

fn clone(&self) -> KalamLinkClient

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

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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