clients.herodb #
HeroDB Client
A V client library for interacting with the HeroDB JSON-RPC API.
Features
- Connects to HeroDB's JSON-RPC server (default port 3000).
- Lists running database instances.
- Parses polymorphic backend types (InMemory, Redb, LanceDb).
Usage
import incubaid.herolib.clients.herodb
fn main() {
// Initialize the client
mut client := herodb.new(herodb.Config{
url: 'http://localhost:3000'
})!
// List instances
instances := client.list_instances()!
for instance in instances {
println('Index: ${instance.index}')
println('Name: ${instance.name}')
// Parse backend info
backend := instance.get_backend_info()!
println('Backend: ${backend.type_name}')
if backend.path != '' {
println('Path: ${backend.path}')
}
println('---')
}
}
API Reference
fn new(cfg Config) !HeroDB
Creates a new HeroDB client instance.
fn (mut self HeroDB) list_instances() ![]InstanceMetadata
Retrieves a list of all currently loaded database instances.
fn (m InstanceMetadata) get_backend_info() !BackendInfo
Helper method to parse the backend_type field from InstanceMetadata into a structured BackendInfo object.
fn new #
fn new(cfg Config) !HeroDB
struct BackendInfo #
struct BackendInfo {
pub:
type_name string // "InMemory", "Redb", "LanceDb"
path string // Empty for InMemory
}
Helper struct to represent the parsed backend info in a usable way
struct Config #
struct Config {
pub:
url string = 'http://localhost:3000'
}
struct HeroDB #
struct HeroDB {
pub:
server_url string
pub mut:
conn ?&httpconnection.HTTPConnection
}
fn (HeroDB) connection #
fn (mut self HeroDB) connection() !&httpconnection.HTTPConnection
fn (HeroDB) list_instances #
fn (mut self HeroDB) list_instances() ![]InstanceMetadata
struct InstanceMetadata #
struct InstanceMetadata {
pub:
index int
name string
// backend_type can be a string ("InMemory") or an object ({"Redb": "path"}).
// We use the `raw` attribute to capture the raw JSON and parse it manually.
backend_type string @[raw]
created_at string
}
HeroDB Specific Structures
fn (InstanceMetadata) get_backend_info #
fn (m InstanceMetadata) get_backend_info() !BackendInfo