{
  "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": "open",
  "url": "https://relatedb.ai/docs/guides/embed/c/samples/open.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": "open-a-store",
    "heading": "Open a store",
    "url": "https://relatedb.ai/docs/guides/embed/c/#open-a-store"
  },
  "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\n/* Print a caller-owned error string and free it. */\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/* Run one statement on a new connection; print its row count and counters, or its error. */\nstatic int run(relate_database db, const char *cypher) {\n    relate_connection conn = NULL;\n    relate_query_result r = NULL;\n    char *err = NULL;\n    if (relate_connect_namespace(db, NULL, &conn, &err) != RELATE_OK) return fail(\"connect\", err);\n    if (relate_query_params(conn, cypher, NULL, &r, &err) != RELATE_OK) {\n        relate_disconnect(conn);\n        return fail(\"query\", err);\n    }\n    if (relate_result_is_error(r)) {\n        printf(\"statement failed: %s\\n\", relate_result_error_json(r));\n    } else {\n        printf(\"rows=%lld stats=%s\\n\", relate_row_count(r), relate_result_stats(r));\n    }\n    relate_destroy_result(r);\n    relate_disconnect(conn);\n    return 0;\n}\n\nint main(void) {\n    relate_database db = NULL;\n    char *err = NULL;\n    printf(\"ABI version %d\\n\", relate_abi_version());\n\n    /* An in-memory store, then a single-file store created on first open. */\n    if (relate_database_open(\":memory:\", &db, &err) != RELATE_OK) return fail(\"open\", err);\n    if (run(db, TEAM) != 0) return 1;\n    relate_database_close(db);\n\n    if (relate_database_open(\"./team.rl\", &db, &err) != RELATE_OK) return fail(\"open\", err);\n    if (run(db, TEAM) != 0) return 1;\n    relate_database_close(db);\n\n    /* The same file, read-only: the write comes back as an error result. */\n    if (relate_database_open_read_only(\"./team.rl\", &db, &err) != RELATE_OK) return fail(\"open\", err);\n    if (run(db, \"MATCH (p:Person) RETURN p.name AS name\") != 0) return 1;\n    if (run(db, \"CREATE (:Person {name: 'Lin'})\") != 0) return 1;\n    relate_database_close(db);\n    return 0;\n}",
  "code_sha256": "93f158f91b727df6d56b907f975c03d001803fc77fb00e559c22dacf1410c9ec",
  "source_sha256": "4280f8181709f311bdb259d5f32084a965d72f14773ca572d14ac604e8156ac4",
  "output": {
    "text": "ABI version 2\nrows=0 stats={\"constraints_added\":0,\"constraints_removed\":0,\"indexes_added\":0,\"indexes_removed\":0,\"labels_added\":5,\"labels_removed\":0,\"nodes_created\":5,\"nodes_deleted\":0,\"properties_set\":13,\"relationships_created\":5,\"relationships_deleted\":0}\nrows=0 stats={\"constraints_added\":0,\"constraints_removed\":0,\"indexes_added\":0,\"indexes_removed\":0,\"labels_added\":5,\"labels_removed\":0,\"nodes_created\":5,\"nodes_deleted\":0,\"properties_set\":13,\"relationships_created\":5,\"relationships_deleted\":0}\nrows=3 stats={\"constraints_added\":0,\"constraints_removed\":0,\"indexes_added\":0,\"indexes_removed\":0,\"labels_added\":0,\"labels_removed\":0,\"nodes_created\":0,\"nodes_deleted\":0,\"properties_set\":0,\"relationships_created\":0,\"relationships_deleted\":0}\nstatement failed: {\"code\":\"Neo.ClientError.Statement.SemanticError\",\"gql_status\":\"42N18\",\"stage\":\"runtime\",\"retryable\":false,\"message\":\"semantic error: WriteOnReadOnlyAccessDatabase: No write operations are allowed on this database. The database is in read-only mode on this Neo4j instance.\"}",
    "sha256": "ec83e0cbe52d04e94d555f24bded7e64d0b1ec6b67c8828d0c5d074506143184"
  },
  "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)"
    }
  }
}
