.NET 8 / C# SDK

Managed SPD2 driver with ulong/Int128 precision, System.Text.Json document binding, and SpydPool.

1 min read Official SDKs (12 Languages)

The official .NET 8 driver (SpydDb.Client) speaks SpydWire v2 (SPD2) binary framing natively in pure managed C# — zero native shared libraries required — featuring TLS 1.2+ with CA verification, ulong & Int128 precision for unsigned 64-bit values, prepared statements, transactions, System.Text.Json schemaless document binding, and SpydPool.

1. Installation#

sh
dotnet add package SpydDb.Client

Targets .NET 8.0+.

2. Connecting, Querying & Exact Integer Precision#

csharp
using SpydDb;

var dsn = "spydwire://app:YOUR_TOKEN@127.0.0.1:5433/default"
        + "?tls=true&ca=docker/tls/ca.crt&server_name=localhost";

using var client = new SpydClient(dsn, timeoutMilliseconds: 10_000);
client.Ping();
client.UseDatabase("default");

client.Execute(
    "create collection if not exists ledger { id: u64 primary, label: text, ratio: f64, posted: bool, at: timestamp }");

client.Execute(
    "ledger | insert [{ id: 18446744073709551000, label: $1, ratio: $2, posted: $3, at: \"2026-01-02T03:04:05Z\" }]",
    "q4-settlement", 1.5, true);

var result = client.Query("ledger | pick id, label, ratio, posted, at | take 20");
foreach (var row in result.Rows)
{
    var id = row[0];
    // Values above long.MaxValue stay exact in ulong / Int128 while AsInt64() returns null
    Console.WriteLine(
        $"kind={id.Kind} ulong={id.AsUInt64()} int128={id.AsInt128()} " +
        $"int64={id.AsInt64()?.ToString() ?? "null"} label={row["label"].AsString()} " +
        $"at={row["at"].AsDateTime():O}");
}

3. Prepared Statements, Transactions & SpydPool#

csharp
// 1. Prepared statement lifecycle
var stmt = client.Prepare("ledger | where label == $1 | pick id, ratio");
try
{
    var found = client.QueryPrepared(stmt, "q4-settlement");
    Console.WriteLine($"Prepared rows: {found.Rows.Count}");
}
finally
{
    client.ClosePrepared(stmt);
}

// 2. Interactive ACID transaction
client.Begin();
try
{
    client.Execute("accounts | where id == $1 | set { balance: balance_delta(balance, 0, 100000, -50) }", 1);
    client.Execute("accounts | where id == $1 | set { balance: balance_delta(balance, 0, 100000, +50) }", 2);
    client.Commit();
}
catch (SpydException)
{
    client.Rollback();
    throw;
}

// 3. Multi-threaded connection pool
using var pool = new SpydPool(dsn, maxOpen: 16, maxIdle: 4);
var total = pool.Query("ledger | agg count() as n").Scalar.AsUInt64();
Console.WriteLine($"Row count: {total}");

4. Schemaless JSON Document Binding (JsonObject / JsonArray)#

csharp
using System.Text.Json.Nodes;

client.Execute("create collection if not exists events { id: u64 primary, title: text, schemaless }");

client.Execute(
    "events | insert $1",
    new JsonArray(
        new JsonObject
        {
            ["id"] = 1,
            ["title"] = "checkout",
            ["region"] = "eu-central",
            ["retries"] = 0,
        }));

var region = client.Query("events | pick json_text(document, \"region\")").Scalar.AsString();
Console.WriteLine($"Event region: {region}");

5. SpydValue Type Accessors & Error Handling#

  • row["col"] or row[index]: Access cells by column name or 0-based ordinal.
  • Typed accessors: IsNull, Text, Kind (ValueKind), AsUInt64(), AsInt64(), AsInt128(), AsDouble(), AsBool(), AsString(), AsDateTime(), AsBytes().
  • Exceptions: Server, auth, constraint, and protocol failures throw SpydException carrying Code and Message, and populate client.Error.