Connectors

C# connector

Build, connect, query and handle errors with the Raft DB C# connector (.NET 8, no NuGet packages).

The C# 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#

.NET 8 or newer. Base class library only (System.Net.Sockets, System.Text.Json), no NuGet packages.

Install#

Download the NuGet package from the Download page, keep it in a folder and add it from there:

Shell
dotnet add package raftdb-csharp-connector --version <version> --source <folder with the .nupkg>

The package holds the compiled RaftDB.dll for .NET 8 (namespace RaftDB).

Connect#

C#
using RaftDB;
using System.Text.Json;

// or Connect(host, port, user, password, token, timeoutMs); the timeout default is 30 s
using var c = Client.Connect("127.0.0.1", 7480);

Query#

C#
c.Put("u1", new { name = "Asha", age = 31 });                  // object, JsonElement, or a JSON string
JsonElement? row = c.Get("u1");                                // null if absent
long n = c.Count("{\"age\":{\"$gte\":30}}");
Page p = c.QuerySql("SELECT id FROM documents ORDER BY id", 70);
foreach (JsonElement r in c.Scan("{}")) Console.WriteLine(r);  // follows cursors lazily

A SQL page and a filter scan (from examples/Example.cs)#

C#
c.CreateIndex("age", ordered: true);
foreach (JsonElement row in c.QuerySql("SELECT name FROM documents ORDER BY age LIMIT 10").Rows)
    Console.WriteLine("row:   " + row);

foreach (JsonElement row in c.Scan("{\"addr.city\":\"Pune\"}"))
    Console.WriteLine("scan:  " + row.GetProperty("name").GetString());

Errors#

RaftDBException has Code. After code 7 the connection is closed. IOException is a network failure, a timeout or a protocol violation (the client closes itself); a disposed client throws ObjectDisposedException.

C#
try { c.Count("{\"age\":"); }
catch (RaftDBException e) { Console.WriteLine("error code " + 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#

  • A string passed as a document or filter is used as JSON text as it is; any other object is serialised with System.Text.Json. The connector rewrites surrogate-pair escapes to the literal character before sending (servers older than 2026-11-09 refused them).
  • Only synchronous methods exist (no *Async variants yet).
  • Every request takes a lock: a shared client is safe but serialised.

Conformance status#

24/24 conformance scenarios (no *Async methods yet). The scenarios are listed in the specification page. The package's README.txt has the install steps and a short example.

See also#