{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/get-started/node/: 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": "transaction",
  "url": "https://relatedb.ai/docs/get-started/node/samples/transaction.json",
  "page": {
    "id": "get-started/node",
    "title": "Embed relate in a Node.js app",
    "url": "https://relatedb.ai/docs/get-started/node/",
    "md_url": "https://relatedb.ai/docs/get-started/node.md"
  },
  "section": {
    "anchor": "change-it-in-a-transaction",
    "heading": "Change it in a transaction",
    "url": "https://relatedb.ai/docs/get-started/node/#change-it-in-a-transaction"
  },
  "language": "js",
  "client": "Node.js",
  "file": "sample.cjs",
  "env": null,
  "code": "const { Database } = require(\"@relate/relate\");\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 COUNT_PEOPLE = \"MATCH (p:Person) RETURN count(p) AS n\";\nconst COUNT_PROJECTS = \"MATCH (p:Project) RETURN count(p) AS n\";\n\nconst conn = Database.open(\":memory:\").connect();\nconn.query(TEAM);\n\nconn.begin();\nconn.query(\n  \"MATCH (tck:Project {name: 'opencypher-tck'}) \" +\n    \"CREATE (:Person {name: 'Lin', role: 'engineer'})-[:WORKS_ON {since: 2026}]->(tck)\"\n);\nconn.commit();\nconsole.log(\"people after commit:\", conn.query(COUNT_PEOPLE).single().n);\n\nconn.begin();\nconn.query(\"MATCH (p:Project) DETACH DELETE p\");\nconsole.log(\"projects inside the transaction:\", conn.query(COUNT_PROJECTS).single().n);\nconn.rollback();\nconsole.log(\"projects after rollback:\", conn.query(COUNT_PROJECTS).single().n);",
  "code_sha256": "0e7ae97ad0d6403ac66192d4b375f2461b1fafb46e5207c1d3811686534bf447",
  "source_sha256": "5c6db43c47b4fb9cd8c90e932775dde3b3ff312ad8b62fff17d0f349198f096a",
  "output": {
    "text": "people after commit: 4\nprojects inside the transaction: 0\nprojects after rollback: 2",
    "sha256": "0f51df80809fdf03db4ab2a2610e218b9c45f56d7cffec251508e4abfd9d4891"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "Node.js",
      "package": "@relate/relate",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "A copy of clients/javascript at upstream v0.1.2 (f0c09d2) with koffi, loading librelate_ffi built from the same commit (cargo build -p relate-ffi --release), with the pinned frameworks beside it.",
      "toolchain": {
        "node": "26.13.0"
      }
    },
    "packages": [
      "ai@7.0.165",
      "zod@4.6.7",
      "@mastra/core@1.82.0"
    ],
    "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_NODE",
      "NODE_PATH",
      "RELATE_LIB"
    ],
    "program": "<run dir>/sample.cjs",
    "files": [
      {
        "path": "<run dir>/node_modules",
        "link": "$NODE_PATH",
        "note": "a link, so require and import both resolve @relate/relate"
      }
    ],
    "build": null,
    "run": {
      "command": [
        "$RELATE_NODE",
        "sample.cjs"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "unset": [
        "NODE_OPTIONS"
      ],
      "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)"
    }
  }
}
