Replies: 5 comments 3 replies
-
Wondering the same thing. Documentation doesn't seem to mention this as a use case? Worse case scenario I think we just need to adapt a de/serializer, but I'd expect to be able to do this with surreal. |
Beta Was this translation helpful? Give feedback.
-
Recursive data structures. There are many ways to do this in relational database though, for example you could just treat each of them as an independent document and put relations in an external table. This is known as closure tables. |
Beta Was this translation helpful? Give feedback.
-
What about a Nested Set? Or is this old-school relational database thinking? |
Beta Was this translation helpful? Give feedback.
-
This is how i implemented Nested Sets
Demo 1
Demo 2Example from Wikipedia | Nested set model
|
Beta Was this translation helpful? Give feedback.
-
I just tackled this issue, see if https://matthewdavis.io/surrealdb-recursive-graph-query/ helps you out. TL;DR: DEFINE FUNCTION fn::recurse($e: any) {
RETURN (
SELECT *,fn::recurse(component_link.out) FROM <-component_link.in
);
};
SELECT *,fn::recurse($this) AS children FROM component; |
Beta Was this translation helpful? Give feedback.
-
I want every node in the tree can be selected from database alone. then how to flat the tree and store the single node alone, and how to store the relations of every nodes?
The depth of the tree is Infinite.
In MySQL or MongoDB,
If I store a whole json tree in one row, then select whole tree is easy, select a single node is difficult.
If I flat the tree and use parentId or childrenIds to describe the relation in every node, it is easy to select a single node, but complex to select a whole tree or child tree.
Can SurrealDB simplify this data model?
I hope the CRUDs are all extremely flexible.
Beta Was this translation helpful? Give feedback.
All reactions