relate
Create graph relationships between records in SurrealDB to model connections like follows, likes, or purchases with optional relationship data.
Instructions
Create a graph relation (edge) between two records in SurrealDB.
This tool creates relationships in SurrealDB's graph structure, allowing you to:
Connect records with named relationships
Store data on the relationship itself
Build complex graph queries later
Model many-to-many relationships efficiently
Args: from_thing: The source record ID in format "table:id" (e.g., "user:john") relation_name: The name of the relation/edge table (e.g., "likes", "follows", "purchased") to_thing: The destination record ID in format "table:id" (e.g., "product:laptop-123") data: Optional dictionary containing data to store on the relation itself. Examples: - {"rating": 5, "review": "Great product!"} - {"quantity": 2, "price": 99.99} - {"since": "2024-01-01", "type": "friend"}
Returns: A dictionary containing: - success: Boolean indicating if relation was created successfully - data: The created relation record(s) - relation_id: The ID of the created relation - error: Error message if creation failed (only present on failure)
Examples: >>> await relate("user:john", "likes", "product:laptop-123", {"rating": 5}) { "success": true, "data": [{"id": "likes:xyz", "in": "user:john", "out": "product:laptop-123", "rating": 5}], "relation_id": "likes:xyz" }
Note: You can query these relations later using graph syntax: SELECT * FROM user:john->likes->product SELECT * FROM user:alice->follows->user
Input Schema
Name | Required | Description | Default |
---|---|---|---|
data | No | ||
from_thing | Yes | ||
relation_name | Yes | ||
to_thing | Yes |