Skip to content

Start here

Overview

The tuple model, the package map, and a first record in Go.

Read this when
  • You open the XDB docs for the first time
  • You decide which package to start with

XDB stores data as tuples. A tuple is a path, an attribute, and a typed value:

xdb://com.example/posts/p-1#title = "Hello"

A record is the set of tuples at one path. You read and write records from Go, over JSON-RPC, or with the xdb CLI. The same calls work on each backend: memory, files, Redis, or SQLite.

Packages

PackageContents
coreTuples, records, URIs, and typed values
schemaSchema definitions and validation modes
storeThe store facade. It validates each write against its schema and sets the record version.
store/xdbmemory, store/xdbfs, store/xdbredis, store/xdbsqliteThe drivers. Each driver writes tuples to one backend.
encoding/xdbjson, encoding/xdbproto, encoding/xdbstructConversion between tuples and JSON, protobuf messages, or Go structs
filterCEL filters for record lists
api, rpcThe JSON-RPC server. It has one method for each action, for example records.create.
cmd/xdbThe CLI and the daemon. The CLI sends each command to the daemon over JSON-RPC.

Your first record

This program keeps a record in memory and reads one attribute back.

package main
import (
"context"
"fmt"
"log"
"github.com/xdb-dev/xdb/core"
"github.com/xdb-dev/xdb/store"
"github.com/xdb-dev/xdb/store/xdbmemory"
)
func main() {
ctx := context.Background()
st := store.New(xdbmemory.NewDriver())
post := core.NewRecord("com.example", "posts", "p-1").
Set("title", "Hello").
Set("views", 42)
if err := st.CreateRecord(ctx, post); err != nil {
log.Fatal(err)
}
got, err := st.GetRecord(ctx, core.MustParseURI("xdb://com.example/posts/p-1"))
if err != nil {
log.Fatal(err)
}
title, err := got.Get("title").AsStr()
if err != nil {
log.Fatal(err)
}
fmt.Println(title)
}

To use the CLI instead, read Get started.

Find a page