Skip to Content
kalam_link Setup

kalam_link Setup

kalam_link is the live SQL client. For a Flutter app with a local cache and offline writes, start at Kalam Sync instead.

Point it at a server that is already running. Server install, Docker, and first-user bootstrap live in the server quick start and kalam init.

Install

pubspec.yamlYAML
dependencies:kalam_link: ^0.6.0-rc.0
BASH
flutter pub add kalam_link

Initialize once

DART
import 'package:flutter/widgets.dart';import 'package:kalam_link/kalam_link.dart'; Future<void> main() async {  WidgetsFlutterBinding.ensureInitialized();  await KalamClient.init();  runApp(const MyApp());}

Do not await KalamClient.connect() before runApp(). Connect after the first frame, from a service or widget.

Connect and query

DART
final client = await KalamClient.connect(  url: 'http://localhost:2900',  authProvider: () async => Auth.basic('root', 'kalamdb123'),); final result = await client.query('SELECT CURRENT_USER()');if (!result.success) {  throw StateError('${result.error}');}print(result.rows.first);

Production apps should return Auth.jwt(...) from authProvider. See Authentication.

Rows are Map<String, KalamCellValue>. Use asString(), asInt(), asBool(), and asFile().

Live rows

DART
final tasks = client.liveTable<Map<String, KalamCellValue>>('app.tasks'); final sub = tasks.listen((rows) {  print('rows=${rows.length}');}); await sub.cancel();await client.dispose();

Use live() for a custom SELECT ... FROM ... WHERE .... Do not put ORDER BY or LIMIT in live SQL.

Raw insert/update/delete events: Realtime Subscriptions.

Next

Last updated on