V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
wo642436249

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

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

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

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