我如何从 Orient DB 中 select 分层数据树?
How do i select hierarchical data tree out of Orient DB?
假设我在 Orient DB 中有 3 个 Class 扩展了 Vertex
和 2 扩展 E
关系如下:
Class_V1 -> edge_E1 -> Class_V2 -> edge_E2 -> Class_V3
如何通过查询获得 json 中的嵌套树?
像
+class_V1{name:abc0}
|___+class_V2 {name:abc1}
|___+class_V2 {name:abc2}
| |___+class_V3 {name:abc3}
| |___+class_V3 {name:abc4)
+ class_V1 {name:abc5)
我试过:
select name , out().name as children from class_V1
但我只得到了我想要的第一层深度。
是否可以一次查询完成?
我使用的是Orientdb-企业版V.2.1.5
在此先感谢您的帮助。
我不认为你可以通过一次查询得到这样的结果。你可以写一个 JS server-side function that aggregates results in that way. Or you could use a tabular approach, thanks to the UNWIND 关键字:
SELECT name, out().name AS children, out().out().name AS children2
FROM class_V1
UNWIND children, children2
这样你就有了一个公寓table。有关 UNWIND 的更多信息,请查看 http://orientdb.com/docs/last/SQL-Query.html#unwind.
假设我在 Orient DB 中有 3 个 Class 扩展了 Vertex 和 2 扩展 E
关系如下:
Class_V1 -> edge_E1 -> Class_V2 -> edge_E2 -> Class_V3
如何通过查询获得 json 中的嵌套树? 像
+class_V1{name:abc0}
|___+class_V2 {name:abc1}
|___+class_V2 {name:abc2}
| |___+class_V3 {name:abc3}
| |___+class_V3 {name:abc4)
+ class_V1 {name:abc5)
我试过:
select name , out().name as children from class_V1
但我只得到了我想要的第一层深度。
是否可以一次查询完成?
我使用的是Orientdb-企业版V.2.1.5
在此先感谢您的帮助。
我不认为你可以通过一次查询得到这样的结果。你可以写一个 JS server-side function that aggregates results in that way. Or you could use a tabular approach, thanks to the UNWIND 关键字:
SELECT name, out().name AS children, out().out().name AS children2
FROM class_V1
UNWIND children, children2
这样你就有了一个公寓table。有关 UNWIND 的更多信息,请查看 http://orientdb.com/docs/last/SQL-Query.html#unwind.