Skip to Content
ExamplesLive Inbox

Live Inbox

Shows how to use live() for materialized row subscriptions — the same pattern used by TypeScript and Dart clients.

Source: link/sdks/rust/examples/live-inbox/

What it does

  1. Creates a temporary inbox table
  2. Opens a WebSocket and starts a live() subscription
  3. Receives the initial (empty) row set
  4. Inserts a message via SQL
  5. Receives the updated row set with the new message
  6. Cleans up the table

Run it

BASH
cd link/sdks/rustexport KALAMDB_SERVER_URL=http://localhost:2900export KALAMDB_ROOT_PASSWORD=kalamdb123cargo run -p live-inbox

Expected output:

TEXT
initial rows: 0live rows after insert: 1first row body: hello from rust sdk

Key API pieces

PieceRole
client.connect()Opens the shared WebSocket before subscriptions
SubscriptionConfigNames the subscription and sets the live SQL
SubscriptionOptions::with_last_rows(20)Rewinds up to 20 recent rows on connect
LiveRowsConfig { limit: Some(20), .. }Caps the materialized row set the client keeps
live.next()Yields the next LiveRowsEvent::Rows batch

Live SQL must stay in supported form: SELECT ... FROM ... WHERE ... (no ORDER BY or LIMIT in the subscription SQL).

Core pattern

RUST
use kalam_client::{    LiveRowsConfig, LiveRowsEvent, SubscriptionConfig, SubscriptionOptions,}; client.connect().await?; let mut config = SubscriptionConfig::new("inbox", "SELECT * FROM app.messages");config.options = Some(SubscriptionOptions::new().with_last_rows(20)); let mut live = client    .live_with_config(        config,        LiveRowsConfig {            limit: Some(20),            ..LiveRowsConfig::default()        },    )    .await?; while let Some(event) = live.next().await {    if let LiveRowsEvent::Rows { rows, .. } = event? {        println!("{} rows", rows.len());    }} live.close().await?;client.disconnect().await;

Next

Last updated on