edsionxuanxuan

Results 2 comments of edsionxuanxuan

数据库那块最新的代码:用的是新版gorm及mysql,go版本1.15 package models import ( "fmt" "log" "gindemo/pkg/setting" "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/schema" ) var db *gorm.DB type Model struct { ID int `gorm:"primary_key" json:"id"` CreatedOn int `json:"created_on"` ModifiedOn int `json:"modified_on"` }...

新版本中gorm的Hook我用的是如下的代码,文中Hook方法中的参数类型*gorm.Scope好像在新版本中没有了。我是没有找到 // 创建之前钩子 func (article *Article) BeforeCreate(tx *gorm.DB) error { tx.Statement.SetColumn("CreatedOn", time.Now().Unix()) return nil } // 更新之前钩子 func (article *Article) BeforeUpdate(tx *gorm.DB) error { if tx.Statement.Changed() { tx.Statement.SetColumn("ModifiedOn", time.Now().Unix()) }...