{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/guides/embed/c/: 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": "walk",
  "url": "https://relatedb.ai/docs/guides/embed/c/samples/walk.json",
  "page": {
    "id": "guides/embed/c",
    "title": "Use the C ABI",
    "url": "https://relatedb.ai/docs/guides/embed/c/",
    "md_url": "https://relatedb.ai/docs/guides/embed/c.md"
  },
  "section": {
    "anchor": "walk-the-result",
    "heading": "Walk the result",
    "url": "https://relatedb.ai/docs/guides/embed/c/#walk-the-result"
  },
  "language": "c",
  "client": "C",
  "file": "sample.c",
  "env": null,
  "code": "#include <stdio.h>\n#include \"relate.h\"\n\nstatic const char *TEAM =\n    \"CREATE (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\nstatic int fail(const char *what, char *err) {\n    fprintf(stderr, \"%s failed: %s\\n\", what, err ? err : \"(no detail)\");\n    relate_free_string(err);\n    return 1;\n}\n\n/* Print a value of the kinds this statement returns; other kinds print their number. */\nstatic void print_value(relate_value v) {\n    size_t len = 0;\n    int64_t i = 0;\n    switch (relate_value_kind(v)) {\n    case RELATE_V_NULL: printf(\"null\"); break;\n    case RELATE_V_INT: relate_value_int(v, &i); printf(\"%lld\", (long long)i); break;\n    case RELATE_V_STRING: {\n        const char *s = relate_value_string(v, &len);\n        printf(\"'%.*s'\", (int)len, s);\n        break;\n    }\n    case RELATE_V_LIST:\n        printf(\"[\");\n        for (long long k = 0; k < relate_value_list_len(v); k++) {\n            if (k) printf(\", \");\n            print_value(relate_value_list_get(v, k));\n        }\n        printf(\"]\");\n        break;\n    case RELATE_V_MAP:\n    case RELATE_V_NODE:\n    case RELATE_V_RELATIONSHIP:\n        if (relate_value_kind(v) == RELATE_V_NODE) {\n            printf(\"node %s \", relate_value_element_id(v));\n            for (long long k = 0; k < relate_value_list_len(v); k++) {\n                const char *label = relate_value_string(relate_value_list_get(v, k), &len);\n                printf(\":%.*s\", (int)len, label);\n            }\n            printf(\" \");\n        } else if (relate_value_kind(v) == RELATE_V_RELATIONSHIP) {\n            const char *type = relate_value_string(v, &len);\n            printf(\"rel %s :%.*s (%s -> %s) \", relate_value_element_id(v), (int)len, type,\n                   relate_value_start_element_id(v), relate_value_end_element_id(v));\n        }\n        printf(\"{\");\n        for (long long k = 0; k < relate_value_map_len(v); k++) {\n            const char *key = relate_value_map_key(v, k, &len);\n            printf(\"%s%.*s: \", k ? \", \" : \"\", (int)len, key);\n            print_value(relate_value_map_get(v, key));\n        }\n        printf(\"}\");\n        break;\n    default: printf(\"<kind %d>\", relate_value_kind(v));\n    }\n}\n\nint main(void) {\n    relate_database db = NULL;\n    relate_connection conn = NULL;\n    relate_query_result r = NULL;\n    char *err = NULL;\n    if (relate_database_open(\":memory:\", &db, &err) != RELATE_OK) return fail(\"open\", err);\n    if (relate_connect_namespace(db, NULL, &conn, &err) != RELATE_OK) return fail(\"connect\", err);\n    if (relate_query_params(conn, TEAM, NULL, &r, &err) != RELATE_OK) return fail(\"query\", err);\n    relate_destroy_result(r);\n\n    if (relate_query_params(conn,\n            \"MATCH (p:Person {name: 'Ada'})-[w:WORKS_ON]->(proj:Project) \"\n            \"RETURN p, w, [proj.name, proj.language] AS project\", NULL, &r, &err) != RELATE_OK)\n        return fail(\"query\", err);\n    for (long long col = 0; col < relate_column_count(r); col++) {\n        printf(\"%s = \", relate_column_name(r, col));\n        print_value(relate_value_at(r, 0, col));\n        printf(\"\\n\");\n    }\n    relate_destroy_result(r); /* frees every value handle and string above */\n    relate_disconnect(conn);\n    relate_database_close(db);\n    return 0;\n}",
  "code_sha256": "01e45688d9ab795ba5e379384c826e9839eec1270ad071275e238d344822c963",
  "source_sha256": "fbaad4ff324c8786fafc8019cf0b7e872f69777116b7db1734cb4619c788d837",
  "output": {
    "text": "p = node 4:relate-neo4j:n0 :Person {name: 'Ada', role: 'engineer'}\nw = rel 5:relate-neo4j:r0 :WORKS_ON (4:relate-neo4j:n0 -> 4:relate-neo4j:n3) {since: 2024}\nproject = ['relate', 'Rust']",
    "sha256": "369658c3fa04fd0db90f6e512b70e3f2e0030d80c2807b6f9235500db4dff572"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "C",
      "package": "relate.h and librelate_ffi",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "relate.h and librelate_ffi built from upstream v0.1.2 (f0c09d2) (cargo build -p relate-ffi --release).",
      "toolchain": {
        "cc": "Apple clang 21.0.0"
      }
    },
    "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_CC",
      "RELATE_C_INCLUDE",
      "RELATE_LIB"
    ],
    "program": "<build dir>/sample.c",
    "files": [],
    "build": {
      "command": [
        "$RELATE_CC",
        "-I$RELATE_C_INCLUDE",
        "sample.c",
        "-L<directory of $RELATE_LIB>",
        "-lrelate_ffi",
        "-Wl,-rpath,<directory of $RELATE_LIB>",
        "-o",
        "<build dir>/sample"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "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)"
    }
  }
}
