Dart / Flutter SDK
kalam_link is the official KalamDB client for Dart and Flutter. It wraps the
compiled Rust core via Flutter Rust Bridge v2, giving you native-speed queries
and live subscriptions with a simple Dart API.
Status: This SDK is in beta and may still change between releases.
What you can do
kalam_link currently focuses on the core app-client workflows:
- Execute SQL over HTTP (
query) - Open any
SELECTquery live over WebSocket (liveEvents) - Consume reconciled materialized live rows (
live,liveTable) - Authenticate with JWT, user/password bootstrap, or anonymous access (
authProvider,login,refreshToken,refreshAuth) - Observe connection lifecycle (
connectionHandlers) - Inspect active subscriptions (
getSubscriptions) - Control the shared WebSocket explicitly (
isConnected,disconnectWebSocket,reconnectWebSocket)
The current Dart SDK does not expose Topic consumer / ACK worker APIs.
Installation
Add to your pubspec.yaml:
dependencies:kalam_link: ^0.5.0-beta.1Then run:
flutter pub get# ordart pub getInitialization
Call KalamClient.init() once at app startup before creating any clients:
void main() async { WidgetsFlutterBinding.ensureInitialized(); await KalamClient.init(); runApp(const MyApp());}Quick start
import 'package:kalam_link/kalam_link.dart'; Future<void> run() async { final client = await KalamClient.connect( url: 'https://db.example.com', authProvider: () async { final token = await myApp.getOrRefreshJwt(); return Auth.jwt(token); }, logLevel: Level.debug, logListener: (entry) => debugPrint(entry.toString()), ); final result = await client.query('SELECT id, email FROM users LIMIT 10'); for (final row in result.rows) { print('${row['id']?.asString()} ${row['email']?.asString()}'); } // Low-level live events final stream = client.liveEvents("SELECT * FROM support.messages WHERE room = 'main'"); await for (final event in stream) { switch (event) { case InsertEvent(:final row): print('New message: $row'); default: break; } } // Materialized live rows final rowsStream = client.liveTable<Map<String, KalamCellValue>>('app.tasks'); await for (final rows in rowsStream) { print('rows=${rows.length}'); break; } await client.dispose();}For liveEvents() and materialized live-query APIs, keep the SQL strict: SELECT ... FROM ... WHERE .... Do not include ORDER BY or LIMIT inside the live SQL.
Recommended reading order
- Setup & Quick Start
- Authentication
- Auth-Aware Client
- Querying & DML
- Realtime Subscriptions
- Client Lifecycle
- Types & Models
- Server Setup & Diagnostics Boundary
Supported platforms
This package is a Flutter FFI plugin (via Flutter Rust Bridge) and is configured for:
- Android, iOS
- macOS, Windows, Linux
Notes
- Call
KalamClient.init()exactly once at startup. - Prefer
authProviderfor expiring tokens. - Cancel live streams by cancelling your
StreamSubscription. - Use
liveEvents()for realtime SQL change streams. - Prefer
live()orliveTable()when your UI wants the latest reconciled row list. - Use
getSubscriptions()andSeqIdif you need resume-aware client bookkeeping. - Native Dart subscriptions use MessagePack by default on the shared Rust transport.
Connection options
| Parameter | Type | Default | Description |
|---|---|---|---|
url | String | required | Server URL |
authProvider | AuthProvider | Auth.none() | Async callback for fresh credentials (recommended) |
disableCompression | bool | false | Disable WS compression — dev only |
wsLazyConnect | bool | true | Defer WebSocket connect until the first live stream |
timeout | Duration | 30s | HTTP request timeout |
maxRetries | int | 3 | Retry count for idempotent queries |
connectionHandlers | ConnectionHandlers? | — | Lifecycle event callbacks |
keepaliveInterval | Duration? | server default | WS keepalive ping interval |
logLevel | Level? | Level.warning | SDK logging threshold (logger package level) |
logListener | LogListener? | — | Redirect SDK logs to your own logger/sink |
authProviderMaxAttempts | int | 3 | Retry attempts for transient auth callback failures |
authProviderInitialBackoff | Duration | 250ms | Initial auth retry backoff |
authProviderMaxBackoff | Duration | 2s | Maximum auth retry backoff |
SDK logging
The Dart SDK uses Level from package:logger/logger.dart for log severity.
import 'package:logger/logger.dart' show Level; final client = await KalamClient.connect( url: 'http://localhost:2900', authProvider: () async => Auth.jwt(await getJwt()), logLevel: Level.debug, logListener: (entry) { debugPrint('[${entry.tag}] ${entry.message}'); },);When logListener is not set, the SDK falls back to print(...), which is visible in Flutter/Android consoles.