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
impl KalamLinkClient
Sourcepub async fn login(
&self,
user: &str,
password: &str,
) -> Result<LoginResponse, KalamLinkError>
pub async fn login( &self, user: &str, password: &str, ) -> Result<LoginResponse, KalamLinkError>
Login with user and password to obtain a JWT token.
Sourcepub async fn refresh_access_token(
&self,
refresh_token: &str,
) -> Result<LoginResponse, KalamLinkError>
pub async fn refresh_access_token( &self, refresh_token: &str, ) -> Result<LoginResponse, KalamLinkError>
Refresh an access token using a refresh token.
Source§impl KalamLinkClient
impl KalamLinkClient
Sourcepub fn builder() -> KalamLinkClientBuilder
pub fn builder() -> KalamLinkClientBuilder
Create a new builder for configuring the client
Sourcepub 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>
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 stringfiles- Optional file uploads for FILE(“name”) placeholdersparams- Optional query parameters for $1, $2, … placeholdersnamespace_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?;Sourcepub 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>
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.
Sourcepub async fn live_events(
&self,
query: &str,
) -> Result<SubscriptionManager, KalamLinkError>
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.
Sourcepub async fn live_events_with_config(
&self,
config: SubscriptionConfig,
) -> Result<SubscriptionManager, KalamLinkError>
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.
Sourcepub async fn live(
&self,
query: &str,
) -> Result<LiveRowsSubscription, KalamLinkError>
pub async fn live( &self, query: &str, ) -> Result<LiveRowsSubscription, KalamLinkError>
Open a SQL query and receive materialized row snapshots.
Sourcepub async fn live_with_config(
&self,
config: SubscriptionConfig,
live_rows_config: LiveRowsConfig,
) -> Result<LiveRowsSubscription, KalamLinkError>
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.
Sourcepub async fn connect(&self) -> Result<(), KalamLinkError>
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.
Sourcepub async fn disconnect(&self)
pub async fn disconnect(&self)
Disconnect the shared WebSocket connection.
Sourcepub async fn cancel_subscription(&self, id: &str) -> Result<(), KalamLinkError>
pub async fn cancel_subscription(&self, id: &str) -> Result<(), KalamLinkError>
Cancel / unsubscribe a subscription by ID on the shared connection.
Sourcepub async fn is_connected(&self) -> bool
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.
Sourcepub async fn subscriptions(&self) -> Vec<SubscriptionInfo>
pub async fn subscriptions(&self) -> Vec<SubscriptionInfo>
List all active subscriptions on the shared connection.
Sourcepub fn event_handlers(&self) -> &EventHandlers
pub fn event_handlers(&self) -> &EventHandlers
Get the current event handlers
Sourcepub fn timeouts(&self) -> &KalamLinkTimeouts
pub fn timeouts(&self) -> &KalamLinkTimeouts
Get the configured timeouts
Sourcepub fn resolved_auth(&self) -> &ResolvedAuth
pub fn resolved_auth(&self) -> &ResolvedAuth
Return the resolved auth source (static or dynamic).
Sourcepub fn set_auth(&mut self, auth: AuthProvider)
pub fn set_auth(&mut self, auth: AuthProvider)
Replace the static authentication credentials at runtime.
Update the shared authentication source without requiring &mut self.
Sourcepub async fn fresh_auth(&self) -> Result<AuthProvider, KalamLinkError>
pub async fn fresh_auth(&self) -> Result<AuthProvider, KalamLinkError>
Resolve fresh credentials from the auth source.
Trait Implementations§
Source§impl Clone for KalamLinkClient
impl Clone for KalamLinkClient
Source§fn clone(&self) -> KalamLinkClient
fn clone(&self) -> KalamLinkClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more