V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
abcopp
V2EX  ›  程序员

Entgo 批量更新求助

  •  
  •   abcopp · 86 天前 · 556 次点击
    这是一个创建于 86 天前的主题,其中的信息可能已经有所发展或是发生改变。
    type MonitorDomain struct {
    ID int
    UID int
    BrandID int
    Type int8
    Domain string
    IsDel int8

    }

    type ReqBodyMonitorDomDel struct {
    Types int8
    DomList []string
    }

    func MonitorDomainDel(client *ent.Client, ctx context.Context, req *ReqBodyMonitorDomDel, uid int) error {

    _, err := client.MonitorDomain.
    Update().
    Where(
    monitordomain.UID(uid),
    monitordomain.Type(req.Types),
    func(s *sql.Selector) {
    s.Where(sql.DomainIn(monitordomain.FieldDomain, req.DomList...))
    }).

    //-1 = deleted

    SetIsDel(-1).
    SetUpdatedAt(time.Now().Unix()).
    Save(ctx)
    if err != nil {
    return errors.Wrap(err, "Update usersreg failed")
    }

    return nil
    }
    批量更新上面的代码是否正确。或者有没有其他更好的方式。

    付费求资深 Golang 程序员求答问题。
    1 条回复    2024-02-03 01:40:24 +08:00
    Akkuman
        1
    Akkuman  
       85 天前 via Android
    你这个好像是需要自动更新时间字段和软删除,官方文档好像有写这块内容
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3108 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:41 · PVG 21:41 · LAX 06:41 · JFK 09:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.