doubeishuai6598
doubeishuai6598
2018-02-16 16:37

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 dtvam48220 3年前

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

    }

    点赞 评论 复制链接分享

为你推荐