The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
wo642436249

gorm 如何给某条数据的某字段值+1 或-1?

  •  
  •   wo642436249 · Aug 9, 2019 · 5759 views
    This topic created in 2643 days ago, the information mentioned may be changed or developed.

    gorm 如何给某条数据的某字段值+1 或-1,不要先读取后更新的操作,太 Low 了感觉

    5 replies  •  2019-08-09 18:03:42 +08:00
    AppxLite
    AppxLite
    Aug 9, 2019
    2
    昨晚刚刚遇到这个问题,官方文档案例有。
    {"price": gorm.Expr("price * ? + ?", 2, 100)}
    ("quantity", gorm.Expr("quantity - ?", 1)
    wo642436249
    wo642436249
    OP
    Aug 9, 2019
    3
    @janxin 看了,看到二楼的回答后,秒懂,哈哈,第一次看没看懂
    Bruin
    Bruin
    Aug 9, 2019
    4
    db.DbEngin.Exec("UPDATE xxxxx SET uv_count= uv_count + 1, update_time=? WHERE id = (?)", update_time, sumTmp.Id)
    wo642436249
    wo642436249
    OP
    Aug 9, 2019
    5
    @Bruin 晓得了。身为新手,使用 github.com/go-redis/redis 包时遇到一个新的问题,当在 set 一个 key 时,如何设置过期时间?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1302 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:05 · PVG 04:05 · LAX 12:05 · JFK 15:05
    ♥ Do have faith in what you're doing.