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)
    }
    

    }

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

报告相同问题?

悬赏问题

  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了