Connectors

Connectors overview

The connector specification (binary protocol version 1), the operations every connector offers, the 24 conformance scenarios and the documented status of each language.

A connector is a client library for the Raft DB binary protocol. Every connector speaks the same small protocol and offers the same operations, so a program ported from one language to another keeps its meaning. Connectors have no dependencies beyond their language's standard library, JSON handling included. The one exception is the Lua connector, which needs LuaSocket because Lua has no sockets of its own.

The contract is the connector specification and the acceptance test is the conformance suite of 24 scenarios; the reference codec is the raftdb-proto crate.

There is no TLS yet. Credentials travel in clear text over the connector protocol: use it only on trusted networks.

Transport#

  • TCP, default port 7480. The same port also serves HTTP; the server tells the two apart by the first bytes.
  • A frame is [len u32 LE][kind u8][id u32 LE][body]. len counts everything after itself (at least 5, at most 16 MiB). id is chosen by the client and echoed in the reply.
  • A simple client sends one request, then reads one reply.
  • The first request on a connection must be Hello (version varint = 1, then the credential). A connection starts on table main.documents; Use(db, table) switches it. Names are 1-64 characters of letters, digits, _, -.

Credentials#

server started withcredential in Hello
nothingempty
--tokenthe shared token (raw bytes)
--user NAME:PASSWORD[:ROLE[@DB]]user NUL password (UTF-8, one zero byte between)

Operations every connector offers#

Names follow each language's conventions (snake_case, camelCase, PascalCase); semantics are identical.

operationmeaning
connect(host, port, user?, password?, token?, timeout?)open and send Hello; fails on failure
close()close the socket
use(db, table)switch table
ping()round trip
get(key)the row as JSON, or null / None if absent
put(key, doc)insert or replace; returns whether the key already existed
delete(key)returns whether the key existed
count(filter)number of rows matching a JSON filter ({} = all)
count_sql(sql)the same for a SQL SELECT COUNT(*)...
query(filter, limit?, cursor?)one page: {rows, next} for a JSON filter
query_sql(sql, limit?, cursor?)one page for a SQL SELECT
scan(filter_or_sql, page_size?)follows next until it is 0 and yields every row
create_index(field, ordered)secondary index on a top-level field

limit 0 means the server default (100); the server caps pages at 10,000 rows. The cursor is opaque: send back exactly the next of the previous page; next 0 means no more rows. A scan argument that starts with SELECT is SQL.

There is no transaction operation and no prepared-statement operation in the protocol. For those, use the SQL front-end with a standard driver: see Standard MySQL and MariaDB drivers.

Filters#

A filter is a JSON object, for example {"age": {"$gte": 30}, "name": "Asha"} (implicit AND). Operators: $eq $ne $lt $lte $gt $gte $in $nin $exists; logical $and $or $not; dotted paths reach nested fields ("address.city"). Types are strict: 30 (integer) never equals 30.0 (double). The full list is on the filter language page; the SQL subset of query_sql is on the HTTP queries page.

Errors#

A server refusal is reported as one RaftDBError type with a code and a message. I/O failures are a different, ordinary error of the language.

codenamemeaning
1BAD_STATEfor example a request before Hello
2SCHEMAdocument rejected, the message says why
3EXISTS
4BAD_FILTERfilter or SQL text did not compile; the message has the position
5OVERLOADED
6SHUTTING_DOWN
7AUTHthe server closes the connection
8IO
9NOT_SUPPORTED
10NOT_FOUNDdatabase or table
11FORBIDDENthe role does not allow it
12READ_ONLYthe server is a replica that has not been promoted

Any malformed frame also closes the connection. Connections are not thread-safe unless a connector says so: use one connection per thread, or a pool.

JSON text sent to the server#

The server's JSON reader accepts the full JSON grammar for strings, including \uXXXX escapes and surrogate pairs; an unpaired surrogate is refused with code 2. Servers built before 2026-11-09 refused surrogate pairs, so a connector that must work with them writes non-BMP characters literally. Duplicate field names in one object are refused (code 2); integers must fit in 64 bits.

Versioning#

Hello.version is 1. New request kinds are only added, so connectors written against version 1 keep working. Servers from 2026-11-11 (D69) also accept version 2, which adds Stream, Defer, Sync and Project for programs that put many callers on one connection. The SPEC says no connector needs them (sections 7 and 10); the Rust client uses them.

UDP transport#

An optional faster path for many small requests, on the same port number, available when the server is started with --udp. A connector that does not implement it loses nothing: TCP always works. The SPEC describes it; the READMEs of the Perl, Ruby, C, C++, Elixir, R, OCaml, Dart and Lua connectors state that they do not implement it. The Rust client does implement it (its connection pauses UDP for 30 s after repeated timeouts).

Conformance#

Every connector passes the same 24 scenarios against a running Raft DB server. They are run before each release by a driver that starts the servers, exports the environment (RAFTDB_ADDR, RAFTDB_AUTH_ADDR, RAFTDB_USER, RAFTDB_PASSWORD, RAFTDB_TOKEN) and runs every connector's test; the packages on the Download page do not contain the tests.

Environment given to the tests: RAFTDB_ADDR (an open server, fresh data directory), RAFTDB_AUTH_ADDR (a server started with --user admin:s3cret-pw and --token tok3n-value), RAFTDB_USER, RAFTDB_PASSWORD, RAFTDB_TOKEN.

The dataset (scenario D, run first): 200 rows with keys u000 to u199; for i in 0..199 the document is {"id": i, "name": "user i", "age": 20 + (i % 50), "tags": ["a", "b"], "addr": {"city": "c" + (i % 5)}, "score": i / 4}.

#scenarioexpected
1connect to the open server, ping()succeeds
2get("u007")equals the document put for i = 7
3get("nope")absent
4put("x1", {"v": 1}) twiceexisted false, then true
5delete("x1") twicetrue, then false; get is absent
6count({})200
7count({"age": {"$gte": 60}})40
8count({"addr.city": "c3"})40
9count_sql("SELECT COUNT(*) FROM documents WHERE age >= 60")40
10query_sql("SELECT id FROM documents ORDER BY id DESC LIMIT 3")ids 199, 198, 197 in that order
11paging query({}, limit=50) following next200 distinct rows, last next is 0
12sorted paging with limit=70pages of 70, 70, 60 rows; ids 0..199 ascending
13scan("SELECT id, name FROM documents WHERE age = 20 ORDER BY id")4 rows, each with exactly the keys id and name
14unicode round tripidentical
15a 1 MB string value round tripidentical
16count('{"age":')RaftDBError code 4
17put of text that is not a JSON objectRaftDBError code 2
18use("nodb", "nothing")code 10; the connection still works
19create_index("age", true), then scenario 7 againsame answer
20use("main", "documents"), then get("u007")still works
21authenticated server, wrong passwordcode 7 (connection closed)
22admin + right password; then token loginboth connect and ping()
234 connections in parallel, each 500 put + getno error, every get returns what was put
24close, then any callan ordinary error (not a crash, not a hang)

Status by language#

Every connector is a ready-made package on the Download page. Their status:

languagepagestylestatus
RustRustblocking, pipelining availabletested by the server test suite
Python 3.9+Pythonwith, generators24/24
JavaScript / Node.jsNode.jsasync/await, scan() async generator24/24
GoGo(value, error), json.RawMessage rows24/24
Java 17+JavaAutoCloseable, rows as JSON text24/24
C# / .NET 8+C#IDisposable, rows as JsonElement24/24 (no *Async methods yet)
PHP 8+PHPPSR-4 RaftDB\Client, arrays24/24
Perl 5PerlRaftDB::Client, RaftDB::Error exceptions, closure iterator24/24 on Windows and Linux
Ruby 3.3Rubyblock form, Enumerator scan24/24 on Linux
C (C99, POSIX)Craftdb.h/raftdb.c, error codes24/24 on Linux, also under ASan/UBSan
C++17 (POSIX)C++single header, RAII, exceptions24/24 on Linux, also under ASan/UBSan
Elixir 1.18Elixir{:ok, v} / {:error, e}, lazy Stream scan24/24 on Linux
R 4Rraftdb_* functions, rows as JSON text24/24 on Linux
OCaml 5OCamlRaftdb.Error exceptions, callbacks24/24 on Linux
Dart 3DartFuture/Stream, RaftDBException24/24 on Linux
Lua 5.4 (+ LuaSocket)Luacolon methods, rows as JSON text24/24 on Linux

Rows come back as parsed JSON, or as JSON text in Java, Go, C, C++, R, OCaml and Lua.

Languages without a connector#

Not provided as separate libraries: Kotlin, Scala and Clojure (use the Java connector, it is a normal JVM library), and languages with no toolchain on the development machines or no socket support in their standard library (Swift, Haskell and others; untested connectors are not shipped). Julia, Tcl, Nim, Zig and others have what is needed but nobody has written a connector yet. Two ways to reach Raft DB from any language:

  1. The HTTP/JSON API on the same port:
curl -H 'content-type: application/json' -d '{"language":"sql","text":"SELECT * FROM documents LIMIT 5"}' http://127.0.0.1:7480/v1/query
  1. The protocol itself: a 4-byte length, a kind, an id and varints. The specification is short and the conformance scenarios above are the acceptance test.

Applications that already speak MySQL or MariaDB do not need a connector: see Standard MySQL and MariaDB drivers and Web applications verified against Raft DB.

See also#