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].lencounts everything after itself (at least 5, at most 16 MiB).idis 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 tablemain.documents;Use(db, table)switches it. Names are 1-64 characters of letters, digits,_,-.
Credentials#
| server started with | credential in Hello |
|---|---|
| nothing | empty |
--token | the 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.
| operation | meaning |
|---|---|
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.
| code | name | meaning |
|---|---|---|
| 1 | BAD_STATE | for example a request before Hello |
| 2 | SCHEMA | document rejected, the message says why |
| 3 | EXISTS | |
| 4 | BAD_FILTER | filter or SQL text did not compile; the message has the position |
| 5 | OVERLOADED | |
| 6 | SHUTTING_DOWN | |
| 7 | AUTH | the server closes the connection |
| 8 | IO | |
| 9 | NOT_SUPPORTED | |
| 10 | NOT_FOUND | database or table |
| 11 | FORBIDDEN | the role does not allow it |
| 12 | READ_ONLY | the 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}.
| # | scenario | expected |
|---|---|---|
| 1 | connect to the open server, ping() | succeeds |
| 2 | get("u007") | equals the document put for i = 7 |
| 3 | get("nope") | absent |
| 4 | put("x1", {"v": 1}) twice | existed false, then true |
| 5 | delete("x1") twice | true, then false; get is absent |
| 6 | count({}) | 200 |
| 7 | count({"age": {"$gte": 60}}) | 40 |
| 8 | count({"addr.city": "c3"}) | 40 |
| 9 | count_sql("SELECT COUNT(*) FROM documents WHERE age >= 60") | 40 |
| 10 | query_sql("SELECT id FROM documents ORDER BY id DESC LIMIT 3") | ids 199, 198, 197 in that order |
| 11 | paging query({}, limit=50) following next | 200 distinct rows, last next is 0 |
| 12 | sorted paging with limit=70 | pages of 70, 70, 60 rows; ids 0..199 ascending |
| 13 | scan("SELECT id, name FROM documents WHERE age = 20 ORDER BY id") | 4 rows, each with exactly the keys id and name |
| 14 | unicode round trip | identical |
| 15 | a 1 MB string value round trip | identical |
| 16 | count('{"age":') | RaftDBError code 4 |
| 17 | put of text that is not a JSON object | RaftDBError code 2 |
| 18 | use("nodb", "nothing") | code 10; the connection still works |
| 19 | create_index("age", true), then scenario 7 again | same answer |
| 20 | use("main", "documents"), then get("u007") | still works |
| 21 | authenticated server, wrong password | code 7 (connection closed) |
| 22 | admin + right password; then token login | both connect and ping() |
| 23 | 4 connections in parallel, each 500 put + get | no error, every get returns what was put |
| 24 | close, then any call | an ordinary error (not a crash, not a hang) |
Status by language#
Every connector is a ready-made package on the Download page. Their status:
| language | page | style | status |
|---|---|---|---|
| Rust | Rust | blocking, pipelining available | tested by the server test suite |
| Python 3.9+ | Python | with, generators | 24/24 |
| JavaScript / Node.js | Node.js | async/await, scan() async generator | 24/24 |
| Go | Go | (value, error), json.RawMessage rows | 24/24 |
| Java 17+ | Java | AutoCloseable, rows as JSON text | 24/24 |
| C# / .NET 8+ | C# | IDisposable, rows as JsonElement | 24/24 (no *Async methods yet) |
| PHP 8+ | PHP | PSR-4 RaftDB\Client, arrays | 24/24 |
| Perl 5 | Perl | RaftDB::Client, RaftDB::Error exceptions, closure iterator | 24/24 on Windows and Linux |
| Ruby 3.3 | Ruby | block form, Enumerator scan | 24/24 on Linux |
| C (C99, POSIX) | C | raftdb.h/raftdb.c, error codes | 24/24 on Linux, also under ASan/UBSan |
| C++17 (POSIX) | C++ | single header, RAII, exceptions | 24/24 on Linux, also under ASan/UBSan |
| Elixir 1.18 | Elixir | {:ok, v} / {:error, e}, lazy Stream scan | 24/24 on Linux |
| R 4 | R | raftdb_* functions, rows as JSON text | 24/24 on Linux |
| OCaml 5 | OCaml | Raftdb.Error exceptions, callbacks | 24/24 on Linux |
| Dart 3 | Dart | Future/Stream, RaftDBException | 24/24 on Linux |
| Lua 5.4 (+ LuaSocket) | Lua | colon methods, rows as JSON text | 24/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:
- 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- 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.