尝试保存和重用一个query- clone();
我已经尝试过query.clone()
,clone(query)
,statics.clone(query)
,graphPredicate.clone(query)
参考:http://tinkerpop.apache.org/docs/current/recipes/#traversal-component-reuse
const { Graph } = gremlin.structure;
const { P: graphPredicate, statics } = gremlin.process;
const { _ } = gremlin.process.statics;
const g = graph.traversal().withRemote(gremlinConnection);
const query = statics.hasLabel(‘Movie’).hasId(gt(‘C’))
const count = g.V().flatMap(query.clone()).count().next()```
`Exception: TypeError: Cannot read property 'clone' of undefined`
答案 0 :(得分:0)
javascript中没有clone()
。但是您可以轻松创建一个:
function clone(traversal) {
return new gremlin.process.GraphTraversal(
traversal.graph,
traversal.traversalStrategies,
new gremlin.process.Bytecode(traversal.bytecode)
)
}
您还可以将其添加到遍历本身:http://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-dsl
class MyTraversal extends gremlin.process.GraphTraversal {
constructor(graph, traversalStrategies, bytecode) {
super(graph, traversalStrategies, bytecode)
}
clone() {
return new MyTraversal(
this.graph,
this.traversalStrategies,
new gremlin.process.Bytecode(this.bytecode)
)
}
}
class MyTraversalSource extends gremlin.process.GraphTraversalSource {
constructor(graph, strategies, bytecode) {
super(graph, strategies, bytecode, MyTraversalSource, MyTraversal)
}
}
const g = traversal(MyTraversalSource).withRemote(dc)