本文整理汇总了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
}