V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
kssss
V2EX  ›  Go 编程语言

问一个 entgo 批量更新字段的问题

  •  
  •   kssss · 2020-11-25 17:53:29 +08:00 · 1212 次点击
    这是一个创建于 1247 天前的主题,其中的信息可能已经有所发展或是发生改变。

    -----------------------------官方例子是这样的

    n, err := client.User.      // UserClient.
        Update().                   // Pet update builder.
        Where(                      //
            user.Or(                // (age >= 30 OR name = "bar") 
                user.AgeEQ(30),     //
                user.Name("bar"),   // AND
            ),                      //  
            user.HasFollowers(),    // UserHasFollowers()  
        ).                          //
        SetName("foo").             // Set field name.
        Save(ctx)                   // exec and return.
    

    但是我想把 用户表里面年龄大于 30 的 所有用户的余额增加 100,类似 SQL 的 update column = column + 100,这条语句怎么写?

    4 条回复    2020-11-25 18:55:49 +08:00
    notamail
        1
    notamail  
       2020-11-25 18:05:31 +08:00
    AddAmount(100)
    kssss
        2
    kssss  
    OP
       2020-11-25 18:09:28 +08:00
    @notamail 我有一个时间字段貌似没有生成 ADD 方法
    notamail
        3
    notamail  
       2020-11-25 18:47:26 +08:00
    AddField 就是 set field=filed+n 的操作,时间字段不能支持
    kssss
        4
    kssss  
    OP
       2020-11-25 18:55:49 +08:00
    @notamail 我来是用的 DATE_ADD 但是现在换成 entgo 就不知道怎么搞了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1138 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:52 · PVG 06:52 · LAX 15:52 · JFK 18:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.