本文整理匯總了Golang中github.com/jinzhu/gorm.Scope.SetColumn方法的典型用法代碼示例。如果您正苦於以下問題:Golang Scope.SetColumn方法的具體用法?Golang Scope.SetColumn怎麽用?Golang Scope.SetColumn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jinzhu/gorm.Scope
的用法示例。
在下文中一共展示了Scope.SetColumn方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: assignCreatedBy
func assignCreatedBy(scope *gorm.Scope) {
if isAuditable(scope) {
if user, ok := getCurrentUser(scope); ok {
scope.SetColumn("CreatedBy", user)
}
}
}
示例2: updateTimeStampWhenCreate
func updateTimeStampWhenCreate(scope *gorm.Scope) {
if !scope.HasError() {
now := time.Now()
scope.SetColumn("Created", now)
scope.SetColumn("Updated", now)
}
}
示例3: initalizePosition
func initalizePosition(scope *gorm.Scope) {
if !scope.HasError() {
if _, ok := scope.Value.(sortingInterface); ok {
var lastPosition int
scope.NewDB().Set("l10n:mode", "locale").Model(modelValue(scope.Value)).Select("position").Order("position DESC").Limit(1).Row().Scan(&lastPosition)
scope.SetColumn("Position", lastPosition+1)
}
}
}
示例4: setEncryptedPassword
func (user *User) setEncryptedPassword(scope *gorm.Scope) error {
pw, err := bcrypt.GenerateFromPassword([]byte(user.Password), 0)
if err != nil {
return err
}
scope.SetColumn("EncryptedPassword", string(pw))
user.Password = ""
return nil
}
示例5: assignUpdatedBy
func assignUpdatedBy(scope *gorm.Scope) {
if isAuditable(scope) {
if user, ok := getCurrentUser(scope); ok {
if attrs, ok := scope.InstanceGet("gorm:update_attrs"); ok {
updateAttrs := attrs.(map[string]interface{})
updateAttrs["updated_by"] = user
scope.InstanceSet("gorm:update_attrs", updateAttrs)
} else {
scope.SetColumn("UpdatedBy", user)
}
}
}
}
示例6: BeforeCreate
func (session *Session) BeforeCreate(scope *gorm.Scope) error {
scope.SetColumn("Token", GenerateRandomString(64))
scope.SetColumn("UUID", generateUUID())
scope.SetColumn("Moment", time.Now().UTC().Unix())
scope.SetColumn("ExpiresIn", expirationLengthForTokenType(session.TokenType))
return nil
}
示例7: assignCreatedBy
func assignCreatedBy(scope *gorm.Scope) {
if isAuditable(scope) {
if user, ok := scope.DB().Get("audited:current_user"); ok {
var currentUser string
if primaryField := scope.New(user).PrimaryField(); primaryField != nil {
currentUser = fmt.Sprintf("%v", primaryField.Field.Interface())
} else {
currentUser = fmt.Sprintf("%v", user)
}
scope.SetColumn("CreatedBy", currentUser)
}
}
}
示例8: assignUpdatedBy
func assignUpdatedBy(scope *gorm.Scope) {
if isAuditable(scope) {
if user, ok := scope.DB().Get("audited:current_user"); ok {
var currentUser string
if primaryField := scope.New(user).PrimaryField(); primaryField != nil {
currentUser = fmt.Sprintf("%v", primaryField.Field.Interface())
} else {
currentUser = fmt.Sprintf("%v", user)
}
if attrs, ok := scope.InstanceGet("gorm:update_attrs"); ok {
updateAttrs := attrs.(map[string]interface{})
updateAttrs["updated_by"] = currentUser
scope.InstanceSet("gorm:update_attrs", updateAttrs)
} else {
scope.SetColumn("UpdatedBy", currentUser)
}
}
}
}
示例9: BeforeCreate
func (client *Client) BeforeCreate(scope *gorm.Scope) error {
scope.SetColumn("UUID", generateUUID())
scope.SetColumn("Key", GenerateRandomString(32))
if crypted, err := bcrypt.GenerateFromPassword([]byte(client.Secret), bcrypt.DefaultCost); err == nil {
scope.SetColumn("Secret", crypted)
} else {
return err
}
return nil
}
示例10: BeforeUpdate
// 顧客情報更新前処理
func (customer *Customer) BeforeUpdate(scope *gorm.Scope) error {
// UpdatedAtの設定
scope.SetColumn("UpdatedAt", time.Now())
return nil
}
示例11: BeforeUpdate
func (friend *Friends) BeforeUpdate(scope *gorm.Scope) (err error) {
scope.SetColumn("updated_at", time.Now().Unix())
return
}