Dart connector
Connect, query and handle errors with the Raft DB Dart connector (dart:io only).
The Dart connector speaks the Raft DB binary protocol (specification) and offers the same operations as every other connector. Download the package from the Download page.
No TLS yet. User names, passwords and tokens travel in clear text. Use only on trusted networks.
Requirements#
Dart 3, dart:io and dart:convert only; no pub.dev packages.
Install#
Download the archive from the Download page and unpack it into a folder; it is a package (pubspec.yaml, lib/). Add it as a path dependency in your pubspec.yaml, then import package:raftdb/raftdb.dart:
dependencies:
raftdb:
path: ../raftdb-dart-connectorConnect#
import 'package:raftdb/raftdb.dart';
// addr is host:port; user + password, or token, or nothing
final db = await RaftDBClient.connect('127.0.0.1:7480', user: 'admin', password: 'pw');Query#
await db.put('u1', {'name': 'Asha', 'age': 31}); // Map or JSON text; returns "existed"
print(await db.get('u1')); // {name: Asha, age: 31}, or null
print(await db.count({'age': {r'$gte': 30}}));
final page = await db.query({'addr.city': 'c3'}, limit: 50); // Page(rows, next)
await for (final row in db.scan('SELECT id FROM documents ORDER BY id')) {
print(row['id']);
}
await db.close();Cleanup with try/finally (from example/example.dart)#
try {
await db.put('u1', {'name': 'Asha', 'age': 31});
await db.createIndex('age', true);
await db.delete('u1');
} finally {
await db.close();
}Errors#
A server error is an RaftDBException with code and message. I/O problems are a SocketException (or TimeoutException); after one of these, or after an AUTH error, the client is closed.
try {
await db.count('{"age":');
} on RaftDBException catch (e) {
print('server said ${e.code}: ${e.message}');
}Transactions and prepared statements#
The connector has no transaction call and no prepared-statement call: the protocol has none (every operation is one request and one reply, see the specification), and none of the connector's README, tests or examples uses one. Use the MySQL or MariaDB front-end with a standard driver for those: see Standard MySQL and MariaDB drivers.
Notes#
- Calls on one client are serialised internally, so concurrent
awaits (Future.wait) are safe; use one client per concurrent stream of work for parallelism. scanreturns aStream<Map>; rows are decoded withjsonDecode(integers stayint,0.25staysdouble).- Not supported: the optional UDP transport.
Conformance status#
24/24 conformance scenarios on Linux with Dart 3.13.7 (26 checks including the dataset and one extra test on concurrent calls, 0 failed). The scenarios are listed in the specification page. The package's README.txt has the install steps and a short example.