db_base.go 413 B

123456789101112131415161718
  1. // @Time : 2020/10/29 8:31 下午
  2. // @Author : bingee
  3. package models
  4. import (
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. // 更新
  8. func UpdateByExpr(ptrStructOrTableName interface{}, where, updateParams map[string]interface{}) error {
  9. o := orm.NewOrm()
  10. qs := o.QueryTable(ptrStructOrTableName)
  11. for expr, exprV := range where {
  12. qs = qs.Filter(expr, exprV)
  13. }
  14. _, err := qs.Update(updateParams)
  15. return err
  16. }