Ruby 3.1+ SDK
Pure Ruby SPD2 + TLS driver with arbitrary-precision Integer U64 decoding, Enumerable results, and pooling.
1 min read Official SDKs (12 Languages)
The official Ruby driver (spyddb) implements SpydWire v2 (SPD2) canonical binary framing over TCP or OpenSSL TLS 1.2/1.3 using pure Ruby stdlib (socket, openssl), offering arbitrary-precision Integer decoding for U64, Enumerable results, prepared statements, block transactions, and pooling.
1. Installation#
sh
gem install spyddb2. Connecting, Querying & Multi-Type Reads#
ruby
require "spyddb"
dsn = "spydwire://app:YOUR_TOKEN@127.0.0.1:5433/default" \
"?tls=true&ca=docker/tls/ca.crt&server_name=localhost"
client = SpydDB::Client.new(dsn, timeout: 10)
begin
client.ping
client.use_database("default")
client.execute(
"events | insert [{ id: 18446744073709551000, kind: $1, score: 1.5, ok: true }]",
["checkout"]
)
result = client.query("events | where ok == $1 | pick id, kind, score | take 20", [true])
result.each do |row|
# Ruby Integer holds full 64-bit unsigned precision natively
puts "id=#{row['id'].to_i} kind=#{row['kind']} score=#{row[2].to_f}"
end
ensure
client.close
end3. Prepared Statements, Block Transactions & Pool#
ruby
require "spyddb"
dsn = "spydwire://app:YOUR_TOKEN@127.0.0.1:5433/default?tls=true&ca=docker/tls/ca.crt"
client = SpydDB::Client.new(dsn)
# 1. Prepared statements
stmt = client.prepare("events | where kind == $1 | pick id, score")
rows = client.query_prepared(stmt, ["checkout"])
puts "Matched #{rows.size} rows"
client.close_prepared(stmt)
# 2. Block transaction (auto-commits on return, rolls back on exception)
client.transaction do
client.execute("accounts | where id == $1 | set { balance: balance_delta(balance, 0, 100000, -25) }", [1])
client.execute("accounts | where id == $1 | set { balance: balance_delta(balance, 0, 100000, +25) }", [2])
end
# 3. Connection Pool
pool = SpydDB::Pool.new(dsn, max_open: 8, max_idle: 4)
count = pool.query("events | agg count() as n").scalar.to_i
puts "Total events: #{count}"
pool.close4. Result, Row & Value Methods#
Resultmixes inEnumerableand provides.each,.size/.length,.empty?,.first,.scalar,.column_names,.column_types, and.affected.Rowsupports integer (row[0]) and string (row["name"]) column lookup.Valueexposes.kind,.text,.null?,.to_i,.to_f,.to_bool,.to_time(UTCTimefrom microsecondTimestamp), and.to_s.- All wire, authentication, query, and protocol failures raise
SpydDB::Error.