{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/get-started/swift/: 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/swift/samples/transaction.json",
  "page": {
    "id": "get-started/swift",
    "title": "Embed relate in a Swift app",
    "url": "https://relatedb.ai/docs/get-started/swift/",
    "md_url": "https://relatedb.ai/docs/get-started/swift.md"
  },
  "section": {
    "anchor": "change-it-in-a-transaction",
    "heading": "Change it in a transaction",
    "url": "https://relatedb.ai/docs/get-started/swift/#change-it-in-a-transaction"
  },
  "language": "swift",
  "client": "Swift",
  "file": "main.swift",
  "env": null,
  "code": "import Relate\n\nlet 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\nfunc count(_ conn: Connection, _ label: String) throws -> Int64 {\n    try conn.query(\"MATCH (n:\\(label)) RETURN count(n) AS n\").scalar().intValue ?? 0\n}\n\nlet db = try Database(path: \":memory:\")\nlet conn = try db.connect()\ntry conn.query(team)\n\ntry conn.begin()\ntry conn.query(\n    \"MATCH (tck:Project {name: 'opencypher-tck'}) \"\n        + \"CREATE (:Person {name: 'Lin', role: 'engineer'})-[:WORKS_ON {since: 2026}]->(tck)\")\nlet bookmark = try conn.commit()\nprint(\"committed:\", bookmark != nil)\nprint(\"people after commit:\", try count(conn, \"Person\"))\n\ntry conn.begin()\ntry conn.query(\"MATCH (p:Project) DETACH DELETE p\")\nprint(\"projects inside the transaction:\", try count(conn, \"Project\"))\ntry conn.rollback()\nprint(\"projects after rollback:\", try count(conn, \"Project\"))",
  "code_sha256": "60bf222d4c9a1a16f6e2011b7591729d6431525656b80438bff36c60fcd848a7",
  "source_sha256": "e47aa0150452d0e57d4cd7a69df21878dcc55b58c57952db550b7f64e61aaa91",
  "output": {
    "text": "committed: true\npeople after commit: 4\nprojects inside the transaction: 0\nprojects after rollback: 2",
    "sha256": "76b973543567e5168f8c53014d7a2dfbfdbbaad5071140e418795882dbe96122"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "Swift",
      "package": "Relate",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "A copy of Package.swift and clients/swift at upstream v0.1.2 (f0c09d2), with an XCFramework made from librelate_ffi built from the same commit.",
      "toolchain": {
        "swift": "6.4.2"
      }
    },
    "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_SWIFT",
      "RELATE_SWIFT_PACKAGE"
    ],
    "program": "<build dir>/Sources/sample/main.swift",
    "files": [
      {
        "path": "<build dir>/Package.swift",
        "content": "// swift-tools-version: 6.0\nimport PackageDescription\n\nlet package = Package(\n    name: \"sample\",\n    platforms: [.macOS(.v13)],\n    dependencies: [.package(path: \"$RELATE_SWIFT_PACKAGE\")],\n    targets: [\n        .executableTarget(\n            name: \"sample\",\n            dependencies: [.product(name: \"Relate\", package: \"relate\")],\n            path: \"Sources/sample\"\n        ),\n    ],\n    swiftLanguageModes: [.v6]\n)\n"
      },
      {
        "path": "<build dir>/sample-bin",
        "from": "<directory of $RELATE_SWIFT_PACKAGE>/scratch/debug/sample",
        "note": "the built product, copied out after the build"
      }
    ],
    "build": {
      "command": [
        "$RELATE_SWIFT",
        "build",
        "-c",
        "debug",
        "--package-path",
        "<build dir>",
        "--scratch-path",
        "<directory of $RELATE_SWIFT_PACKAGE>/scratch",
        "--product",
        "sample",
        "--quiet"
      ],
      "environment": {
        "DO_NOT_TRACK": "1",
        "RELATE_LOCAL_XCFRAMEWORK": "1"
      },
      "directory": "<build dir>",
      "timeout_s": 600
    },
    "run": {
      "command": [
        "<build dir>/sample-bin"
      ],
      "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)"
    }
  }
}
