R connector
Install, connect, query and handle errors with raftdbclient, the Raft DB connector in base R.
The R 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#
R 4, base R only (socketConnection, readBin/writeBin, raw vectors). No CRAN package is needed.
Install#
Download the package from the Download page and install it:
R CMD INSTALL raftdb-r-connector-<version>.tar.gz # then library(raftdbclient)Connect#
library(raftdbclient)
con <- raftdb_connect("127.0.0.1:7480", user = "admin", password = "pw") # or token = "..."; timeout = 30Query#
raftdb_put(con, "u1", '{"name":"Asha","age":31}')
cat(raftdb_get(con, "u1"), "\n")
raftdb_count(con, '{"age":{"$gte":30}}')
raftdb_scan(con, "SELECT name FROM documents ORDER BY age", fn = function(row) cat(row, "\n"))
raftdb_close(con)A SQL page and a filter scan (from examples.R)#
p <- raftdb_query_sql(con, "SELECT name FROM documents ORDER BY age LIMIT 10")
cat(p$rows, sep = "\n")
raftdb_scan(con, '{"addr.city":"Pune"}', fn = function(row) cat("scan:", row, "\n"))Errors#
A server error is signalled with stop() of a condition of class c("raftdb_error", "error", "condition") carrying $code and $server_message. I/O failures are ordinary R errors. After a timeout or a partial frame the connection is closed.
tryCatch(raftdb_count(con, '{"age":'), raftdb_error = function(e) cat("code", e$code, "\n")) # code 4Transactions 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#
- Documents, filters and rows are JSON text (character strings). If the optional package
jsonliteis installed, R lists are also accepted andparse = TRUEreturns parsed lists; nothing requires it. nextis a reserved word in R: read it asp[["next"]].- Connections are not thread safe: one per process or worker.
- Not implemented: TLS, UDP transport, pipelining.
Conformance status#
24/24 conformance scenarios plus the dataset step on Linux (last run 2026-11-09: 25 passed, 0 failed). The test script, not the library, uses jsonlite. The scenarios are listed in the specification page. The package's README.txt has the install steps and a short example.