1. 更新日志

1.1. v1.0

1.1.1. 破坏性变更

*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

导入它用import _ "github.com/jinzhu/gorm/dialects/mssql"

Hstore已移至github.com/jinzhu/gorm/dialects/postgres

gorm执行sql

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(&amp;re)
	fmt.Println(re)
	for _,k :=range re{
		fmt.Println(k.Uid)
	}
}