[英]Dynamic gremlin traversal construction
I'm migrating from the deprecated gremlin-javascript
to the new Tinkerpop gremlin
. 我正在从不推荐使用的
gremlin-javascript
迁移到新的Tinkerpop gremlin
。
gremlin-javascript
supported an execute
method that would take an arbitrary string as a traversal. gremlin-javascript
支持一种execute
方法,该方法将任意字符串作为遍历。 We could dynamically create and pass this string, such as chaining an arbitrary number of property
traversals on a vertex. 我们可以动态创建并传递此字符串,例如在顶点上链接任意数量的
property
遍历。
Is there a way to dynamically build traversals in the gremlin
js client? 有没有办法在
gremlin
js客户端中动态构建遍历?
For all language variants of Gremlin (Java, JS, Python, etc), you write Gremlin by constructing a Traversal
object. 对于Gremlin的所有语言变体(Java,JS,Python等),您可以通过构造
Traversal
对象来编写Gremlin。 You have a g
which is a GraphTraversalSource
which spawns those Traversal
objects and thus: 您有一个
g
,它是一个GraphTraversalSource
,它生成这些Traversal
对象,因此:
var t = g.V().values('names');
does not yield a result (ie a list of "name" values) in t
but a Traversal
object. 不会在
t
产生结果(即“名称”值的列表),而是Traversal
对象。 To get the result you need to iterate the traversal as for example: 为了获得结果,您需要迭代遍历,例如:
t.toList().then(names => console.log(names));
So, if you have a Traversal
object that is not yet iterated you can continue to add to it: 因此,如果您有尚未遍历的
Traversal
对象,则可以继续向其添加:
var t = g.V().values('names');
t = t.limit(1);
t.next().then(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.