如何在gorethink中使用r.Do和r.Branch?

如何在gorethink中使用r.Do和r.Branch?,go,rethinkdb,Go,Rethinkdb,我正在寻找gorethink中r.Do()和r.Branch()函数的清晰示例。Go RejectDB driver的作者在Github上非常活跃,如果在那里询问,您可能会得到更快的答案 下面是Do的一个示例 res, _ := r.DB("test").Table("table").Get("ID").Do(func(issue r.Term) r.Term { return issue.Merge(map[string]string{ "new

我正在寻找gorethink中r.Do()和r.Branch()函数的清晰示例。

Go RejectDB driver的作者在Github上非常活跃,如果在那里询问,您可能会得到更快的答案

下面是
Do
的一个示例

    res, _ := r.DB("test").Table("table").Get("ID").Do(func(issue r.Term) r.Term {
        return issue.Merge(map[string]string{
            "new_field": "new_value",
        })
    }).Run(session)
    var b []interface{}
    a.All(&b)
    fmt.Println(b)
我认为最重要的是确保我们声明了正确的类型
Term
。我将DB驱动程序作为
r
导入,因此使用了
r.Term
。然后在
Do
函数中,您可以使用以下术语中的任何命令:

Do
Branch
同时出现的示例:

    r.DB("test").Table("issues").Insert(map[string]interface{}{
        "id": 1111,
    }).Do(func(result r.Term) r.Term {
        return r.Branch(result.Field("inserted").Gt(0),
            r.DB("test").Table("log").Insert(map[string]interface{}{
                "time":   r.Now(),
                "result": "ok",
            }),
            r.DB("test").Table("log").Insert(map[string]interface{}{
                "time":   r.Now(),
                "result": "failed",
            }))
    }).Run(session)
基本上,在
Do
中,我们可以访问RejectionDB的上一个函数调用的返回值,并且我们可以像在
Map
函数中一样,继续对该返回值调用REQUL命令

分支
中,我们传递了3个参数,它们都是
术语
在数据库驱动程序中键入的。您还可以参考官方示例:


由于语言的性质,要熟悉Go驱动程序有点困难,并且不能适应官方驱动程序的动态风格(Ruby、Python、JS)。语言上更令人困惑的是,我们无法控制命令

Go DB driver的作者在Github上非常活跃,如果在那里询问,你可能会得到更快的答案

下面是
Do
的一个示例

    res, _ := r.DB("test").Table("table").Get("ID").Do(func(issue r.Term) r.Term {
        return issue.Merge(map[string]string{
            "new_field": "new_value",
        })
    }).Run(session)
    var b []interface{}
    a.All(&b)
    fmt.Println(b)
我认为最重要的是确保我们声明了正确的类型
Term
。我将DB驱动程序作为
r
导入,因此使用了
r.Term
。然后在
Do
函数中,您可以使用以下术语中的任何命令:

Do
Branch
同时出现的示例:

    r.DB("test").Table("issues").Insert(map[string]interface{}{
        "id": 1111,
    }).Do(func(result r.Term) r.Term {
        return r.Branch(result.Field("inserted").Gt(0),
            r.DB("test").Table("log").Insert(map[string]interface{}{
                "time":   r.Now(),
                "result": "ok",
            }),
            r.DB("test").Table("log").Insert(map[string]interface{}{
                "time":   r.Now(),
                "result": "failed",
            }))
    }).Run(session)
基本上,在
Do
中,我们可以访问RejectionDB的上一个函数调用的返回值,并且我们可以像在
Map
函数中一样,继续对该返回值调用REQUL命令

分支
中,我们传递了3个参数,它们都是
术语
在数据库驱动程序中键入的。您还可以参考官方示例:


由于语言的性质,要熟悉Go驱动程序有点困难,并且不能适应官方驱动程序的动态风格(Ruby、Python、JS)。语言上更令人困惑的是,我们无法控制命令

Go DB driver的作者在Github上非常活跃,如果在那里询问,你可能会得到更快的答案

下面是
Do
的一个示例

    res, _ := r.DB("test").Table("table").Get("ID").Do(func(issue r.Term) r.Term {
        return issue.Merge(map[string]string{
            "new_field": "new_value",
        })
    }).Run(session)
    var b []interface{}
    a.All(&b)
    fmt.Println(b)
我认为最重要的是确保我们声明了正确的类型
Term
。我将DB驱动程序作为
r
导入,因此使用了
r.Term
。然后在
Do
函数中,您可以使用以下术语中的任何命令:

Do
Branch
同时出现的示例:

    r.DB("test").Table("issues").Insert(map[string]interface{}{
        "id": 1111,
    }).Do(func(result r.Term) r.Term {
        return r.Branch(result.Field("inserted").Gt(0),
            r.DB("test").Table("log").Insert(map[string]interface{}{
                "time":   r.Now(),
                "result": "ok",
            }),
            r.DB("test").Table("log").Insert(map[string]interface{}{
                "time":   r.Now(),
                "result": "failed",
            }))
    }).Run(session)
基本上,在
Do
中,我们可以访问RejectionDB的上一个函数调用的返回值,并且我们可以像在
Map
函数中一样,继续对该返回值调用REQUL命令

分支
中,我们传递了3个参数,它们都是
术语
在数据库驱动程序中键入的。您还可以参考官方示例:


由于语言的性质,要熟悉Go驱动程序有点困难,并且不能适应官方驱动程序的动态风格(Ruby、Python、JS)。语言上更令人困惑的是,我们无法控制命令

Go DB driver的作者在Github上非常活跃,如果在那里询问,你可能会得到更快的答案

下面是
Do
的一个示例

    res, _ := r.DB("test").Table("table").Get("ID").Do(func(issue r.Term) r.Term {
        return issue.Merge(map[string]string{
            "new_field": "new_value",
        })
    }).Run(session)
    var b []interface{}
    a.All(&b)
    fmt.Println(b)
我认为最重要的是确保我们声明了正确的类型
Term
。我将DB驱动程序作为
r
导入,因此使用了
r.Term
。然后在
Do
函数中,您可以使用以下术语中的任何命令:

Do
Branch
同时出现的示例:

    r.DB("test").Table("issues").Insert(map[string]interface{}{
        "id": 1111,
    }).Do(func(result r.Term) r.Term {
        return r.Branch(result.Field("inserted").Gt(0),
            r.DB("test").Table("log").Insert(map[string]interface{}{
                "time":   r.Now(),
                "result": "ok",
            }),
            r.DB("test").Table("log").Insert(map[string]interface{}{
                "time":   r.Now(),
                "result": "failed",
            }))
    }).Run(session)
基本上,在
Do
中,我们可以访问RejectionDB的上一个函数调用的返回值,并且我们可以像在
Map
函数中一样,继续对该返回值调用REQUL命令

分支
中,我们传递了3个参数,它们都是
术语
在数据库驱动程序中键入的。您还可以参考官方示例:


由于语言的性质,要熟悉Go驱动程序有点困难,并且不能适应官方驱动程序的动态风格(Ruby、Python、JS)。语言上更令人困惑的是,我们无法控制命令

您最好使用此选项代替任何代码来帮助修复。您最好使用此选项代替任何代码来帮助修复。您最好使用此选项代替任何代码来帮助修复。您最好使用此选项代替任何代码来帮助修复。您最好使用此选项代替任何代码来帮助修复。