1. 更新日志
1.1. v1.0
1.1.1. 破坏性变更
gorm.open*gorm.dbgorm.db
beforesavebeforeupdatescope.setcolumn
func (user *user) beforeupdate(scope *gorm.scope) { if pw, err := bcrypt.generatefrompassword(user.password, 0); err == nil { scope.setcolumn("encryptedpassword", pw) // user.encryptedpassword = pw // 不工作,更新时不会包括encryptedpassword字段 } }
deleted_at is null
之前它会检查deleted_at小于0001-01-02也排除空白时间,如:
select * from users where deleted_at is null or deleted_at <= '0001-01-02'
*time.timedeletedatgorm.model
select * from users where deleted_at is null
gorm.modeldeleted_atnull
import ( "github.com/jinzhu/now" ) func main() { var models = []interface{}{&user{}, &image{}} for _, model := range models { db.unscoped().model(model).where("deleted_at < ?", now.mustparse("0001-01-02")).update("deleted_at", gorm.expr("null")) } }
- 新的todbname逻辑
httpuri
httphttph_t_t_pskus_k_u
recordnotfounderrrecordnotfound
mssql
gorm执行sql导入它用import _ "github.com/jinzhu/gorm/dialects/mssql"
hstore已移至github.com/jinzhu/gorm/dialects/postgres
type object interface { grouporderopenlog() (uidlist []int) } func (o *object) grouporderopenlog() { type res struct { uid int `json:"uid"` } var re []res sql:= "select uid from order_openlog group by uid" o.db.raw(sql).scan(&re) fmt.println(re) for _,k :=range re{ fmt.println(k.uid) } }
本文来自网络收集,不代表猴子技术宅立场,如涉及侵权请点击右边联系管理员删除。
如若转载,请注明出处:https://www.ssfiction.com/sqljc/1091608.html