{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/guides/embed/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": "params",
  "url": "https://relatedb.ai/docs/guides/embed/swift/samples/params.json",
  "page": {
    "id": "guides/embed/swift",
    "title": "Use the Swift package",
    "url": "https://relatedb.ai/docs/guides/embed/swift/",
    "md_url": "https://relatedb.ai/docs/guides/embed/swift.md"
  },
  "section": {
    "anchor": "bind-parameters-and-read-typed-values",
    "heading": "Bind parameters and read typed values",
    "url": "https://relatedb.ai/docs/guides/embed/swift/#bind-parameters-and-read-typed-values"
  },
  "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\nlet conn = try Database.inMemory().connect()\ntry conn.query(team)\n\nlet project = \"relate\"\nlet members = try conn.query(\"\"\"\n    MATCH (p:Person)-[w:WORKS_ON]->(:Project {name: $project})\n    RETURN p, w.since AS since ORDER BY since\n    \"\"\", [\"project\": CypherValue(project)])\nfor record in members.records {\n    let person = record[\"p\"]!.nodeValue!\n    print(person.properties[\"name\"]!, person.labels, \"since\", record[\"since\"]!.intValue!)\n}\n\nlet noor = try conn.query(\"\"\"\n    MATCH (p:Person {name: $name})\n    SET p.joined = $joined, p.focus = $focus\n    RETURN p.joined AS joined, p.focus AS focus, elementId(p) AS id\n    \"\"\", [\n        \"name\": \"Noor\",\n        \"joined\": .date(.init(year: 2025, month: 3, day: 1)),\n        \"focus\": .vector(.floats(dtype: .float32, values: [0.25, 0.5, 1])),\n    ])\nlet row = noor.records[0]\nprint(\"joined\", row[\"joined\"]!, row[\"joined\"]!.kind)\nprint(\"focus\", row[\"focus\"]!)\n\nlet byId = try conn.query(\"MATCH (p) WHERE elementId(p) = $id RETURN p.name AS name\", [\"id\": row[\"id\"]!])\nprint(\"by element id:\", try byId.scalar())",
  "code_sha256": "62a0e3c1f96ddaa50fc697bac892c4cb2b3e0ee759b813e2698517efd6052e3b",
  "source_sha256": "5dc46ebb451bb01e89808647db30dcaf54147547cf69b53e291cef630193a7f2",
  "output": {
    "text": "'Grace' [\"Person\"] since 2023\n'Ada' [\"Person\"] since 2024\njoined 2025-03-01 date\nfocus vector<FLOAT32>[0.25, 0.5, 1.0]\nby element id: 'Noor'",
    "sha256": "e63745c0aaf5cd3886be8f195979ec4c7b1525feb8e416b00d85809b176fb8f4"
  },
  "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)"
    }
  }
}
