【问题标题】:Gremlin Javascript fold, coalesce, and unfoldGremlin Javascript 折叠、合并和展开
【发布时间】:2019-03-29 15:17:08
【问题描述】:

使用 gremlin-javascript,我想执行“如果不存在则添加”事务,例如:

g.V()
  .hasLabel('account').has('uid', '1')
  .fold()
  .coalesce(
    g.V().unfold(),
    g.V().addV('account').property('uid', '1')
  )

我该如何表达这种查询?

【问题讨论】:

    标签: javascript gremlin


    【解决方案1】:

    更明确地说:

    const __ = gremlin.process.statics;
    
    g.V()
      .hasLabel('account').has('uid', '1')
      .fold()
      .coalesce(
        __.unfold(),
        __.addV('account').property('uid', '1')
      )
    

    【讨论】:

      【解决方案2】:

      我假设您已经在其他地方看到过这种模式,也许在 Gremlin 控制台中得到了展示。虽然那是 Gremlin Groovy,但 Gremlin 就是 Gremlin 就是 Gremlin,与您的编程语言无关。除了一些细微的惯用差异之外,Gremlin 的大多数变体都彼此相同。对于 Javascript 和您所询问的 Gremlin 的这一特殊部分,Gremlin 与 Groovy 没有什么不同:

      g.V().
        hasLabel('account').has('uid', '1').
        fold().
        coalesce(unfold(),
                 addV('account').property('uid', '1'))
      

      注意unfold()addV()anonymous fashion 中被调用。它们只需要从__ 导入即可,如here 所述。

      【讨论】:

        猜你喜欢
        • 2014-02-26
        • 2012-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-13
        • 2013-06-06
        • 1970-01-01
        • 2012-05-15
        相关资源
        最近更新 更多