doubeishuai6598 2018-02-16 16:37
浏览 259
已采纳

Golang neo4j MERGE需要文字映射

In my go application, I'm trying to execute a MERGE query, using the golang-neo4j-bolt-driver.

The interface of the ExecNeo and ExecPipeline requires a string map with interface object as a parameter. When executing the query, I get the error message that a literal map is required:

Internal Error(messages.FailureMessage): messages.FailureMessage{Metadata:map[string]interface {}{"code":"Neo.ClientError.Statement.SyntaxError", "message":"Parameter maps cannot be used in MERGE patterns (use a literal map instead`).

Does anyone have an example of creating an literal map?

  • 写回答

1条回答 默认 最新

  • dtvam48220 2018-02-18 15:39
    关注

    Thanks everyone for pointing me in the right direction. Here's a piece of sample code that 'works on my machine':

    func TestMergeWithLiteralMap(t *testing.T) {
    d := bolt.NewDriver()
    
    conn, err := d.OpenNeo("bolt://neo4j:admin@127.0.0.1:7687")
    if err != nil {
        panic(err)
    }
    defer conn.Close()
    
    qry := `MATCH (f:Node1 {Name: {f_name}, Group: {f_group} }), 
                  (t:Node2{Name: {t_name}, Group: {t_group} })
            WITH f,t 
            MERGE (t) <- [:NREL] - (f)`
    params := map[string]interface{}{"f_name": "apple", "f_group": "public", "t_name": "pear", "t_group": "private"}
    stmt, err := conn.PrepareNeo(qry)
    if err != nil {
        panic(err)
    }
    results, err := stmt.ExecNeo(params)
    if err != nil {
        panic(err)
    }
    glog.Errorf("Executed statement: %s
    With values: %s
    ", stmt, params)
    
    numResult, _ := results.RowsAffected()
    metadata := results.Metadata()
    glog.Errorf("[NEO-CLIENT] Graphed %s '%s (%s)', CREATED ROWS: %d
    ", metadata["kind"], metadata["name"], metadata["namespace"], numResult)
    
    err = stmt.Close()
    if err != nil {
        panic(err)
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题