{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/get-started/go/: the program exactly as the page shows it, the standard output a run of it recorded (npm run docs:samples compares every replay with it byte for byte), the relate client build, toolchain and platform of the last replay, and how the docs' sample runner builds and runs it. Before launch every client is a source build, not a published package; verified.client names the upstream commit it was built from, and verified.docs_engine the build the rest of the docs were recorded from.",
  "id": "program",
  "url": "https://relatedb.ai/docs/get-started/go/samples/program.json",
  "page": {
    "id": "get-started/go",
    "title": "Embed relate in a Go program",
    "url": "https://relatedb.ai/docs/get-started/go/",
    "md_url": "https://relatedb.ai/docs/get-started/go.md"
  },
  "section": {
    "anchor": "put-it-together",
    "heading": "Put it together",
    "url": "https://relatedb.ai/docs/get-started/go/#put-it-together"
  },
  "language": "go",
  "client": "Go",
  "file": "main.go",
  "env": null,
  "code": "package main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\n\trelate \"github.com/relatedb/relate/clients/go\"\n)\n\nconst team = `\nCREATE (ada:Person {name: 'Ada', role: 'engineer'}),\n       (grace:Person {name: 'Grace', role: 'engineer'}),\n       (noor:Person {name: 'Noor', role: 'maintainer'}),\n       (relate:Project {name: 'relate', language: 'Rust'}),\n       (tck:Project {name: 'opencypher-tck', language: 'Gherkin'}),\n       (ada)-[:WORKS_ON {since: 2024}]->(relate),\n       (grace)-[:WORKS_ON {since: 2023}]->(relate),\n       (grace)-[:WORKS_ON {since: 2022}]->(tck),\n       (noor)-[:MAINTAINS]->(relate),\n       (ada)-[:KNOWS]->(grace)\n`\n\nconst teamOf = `\nMATCH (p:Person)-[w:WORKS_ON]->(:Project {name: $project})\nRETURN p.name AS name, w.since AS since\nORDER BY since\n`\n\nfunc ensureTeam(conn *relate.Connection) error {\n\tresult, err := conn.Query(\"MATCH (p:Person) RETURN count(p) AS n\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tpeople := result.Rows[0][0].(int64)\n\tif people == 0 {\n\t\tif _, err := conn.Query(team); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfmt.Println(\"created the team graph\")\n\t} else {\n\t\tfmt.Println(\"found\", people, \"people\")\n\t}\n\treturn nil\n}\n\nfunc report(conn *relate.Connection, project string) error {\n\tfmt.Println(project)\n\tresult, err := conn.QueryParams(teamOf, map[string]any{\"project\": project})\n\tif err != nil {\n\t\treturn err\n\t}\n\tfor _, row := range result.Rows {\n\t\tfmt.Println(\" \", row[0], \"since\", row[1])\n\t}\n\treturn nil\n}\n\nfunc run() error {\n\tdb, err := relate.Open(\"./team.rl\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer db.Close()\n\tconn, err := db.Connect()\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer conn.Close()\n\tif err := ensureTeam(conn); err != nil {\n\t\treturn err\n\t}\n\tif err := report(conn, \"relate\"); err != nil {\n\t\treturn err\n\t}\n\treturn report(conn, \"opencypher-tck\")\n}\n\nfunc main() {\n\tif err := run(); err != nil {\n\t\tvar e *relate.Error\n\t\tif errors.As(err, &e) {\n\t\t\tfmt.Fprintf(os.Stderr, \"relate error %s: %s\\n\", e.GQLStatus, e.Message)\n\t\t} else {\n\t\t\tfmt.Fprintln(os.Stderr, err)\n\t\t}\n\t\tos.Exit(1)\n\t}\n}",
  "code_sha256": "6b0770b4bfd0f2fbd22e882e9f3555511773135d87d2356d710e413147ee4cae",
  "source_sha256": "1e57cec6e8b7a44bc14f4c184af2c104e76cab7046332ceb59ed1b79db5f0782",
  "output": {
    "text": "created the team graph\nrelate\n  Grace since 2023\n  Ada since 2024\nopencypher-tck\n  Grace since 2022",
    "sha256": "1c4d6ad9d85b2e1c50b54653bde7361157564ad399ffab2ebfa5cfc05724e414"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "Go",
      "package": "github.com/relatedb/relate/clients/go",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "clients/go from a checkout of upstream v0.1.2 (f0c09d2), built with cgo against relate.h and librelate_ffi built from the same commit.",
      "toolchain": {
        "go": "1.27.3"
      }
    },
    "packages": [],
    "replayed": "2026-11-09",
    "platform": "macOS on arm64",
    "docs_engine": {
      "version": "0.1.2",
      "commit": "f0c09d2",
      "source_build": false
    }
  },
  "run": {
    "runner": "npm run docs:samples",
    "setup": "bash scripts/samples/setup.sh --upstream <path to the relate checkout>",
    "variables": [
      "RELATE_GO",
      "RELATE_GO_CLIENT",
      "RELATE_GO_HOME",
      "RELATE_C_INCLUDE",
      "RELATE_LIB"
    ],
    "program": "<build dir>/main.go",
    "files": [
      {
        "path": "<build dir>/go.mod",
        "content": "module relatesample\n\ngo 1.22\n\nrequire github.com/relatedb/relate/clients/go v0.0.0\n\nreplace github.com/relatedb/relate/clients/go => $RELATE_GO_CLIENT\n"
      }
    ],
    "build": {
      "command": [
        "$RELATE_GO",
        "build",
        "-o",
        "<build dir>/sample",
        "."
      ],
      "environment": {
        "DO_NOT_TRACK": "1",
        "GOPATH": "$RELATE_GO_HOME/path",
        "GOMODCACHE": "$RELATE_GO_HOME/mod",
        "GOCACHE": "$RELATE_GO_HOME/cache",
        "GOFLAGS": "-mod=mod",
        "GOTOOLCHAIN": "local",
        "GOPROXY": "off",
        "GOWORK": "off",
        "CGO_ENABLED": "1",
        "CGO_CFLAGS": "-I$RELATE_C_INCLUDE",
        "CGO_LDFLAGS": "-L<directory of $RELATE_LIB> -lrelate_ffi -Wl,-rpath,<directory of $RELATE_LIB>"
      },
      "directory": "<build dir>",
      "timeout_s": 600
    },
    "run": {
      "command": [
        "<build dir>/sample"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "directory": "<run dir>",
      "timeout_s": 60
    },
    "passes": "It exits 0 within 60 s and prints at least one line on standard output.",
    "output": "Standard output, with line endings as \\n, trailing spaces and blank lines removed, and the temporary directories' paths written as `.`; standard error is not recorded.",
    "placeholders": {
      "<run dir>": "a fresh, empty temporary directory: the program's working directory, deleted afterwards",
      "<build dir>": "a second fresh temporary directory, where a compiled sample is built",
      "$NAME": "a variable from the env.sh that scripts/samples/setup.sh writes (described in its header)"
    }
  }
}
