當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Scope.SetColumn方法代碼示例

本文整理匯總了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)
		}
	}
}
開發者ID:8legd,項目名稱:qor-qor,代碼行數:7,代碼來源:callbacks.go

示例2: updateTimeStampWhenCreate

func updateTimeStampWhenCreate(scope *gorm.Scope) {
	if !scope.HasError() {
		now := time.Now()
		scope.SetColumn("Created", now)
		scope.SetColumn("Updated", now)
	}
}
開發者ID:thnguyn2,項目名稱:WebGPU,代碼行數:7,代碼來源:models.go

示例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)
		}
	}
}
開發者ID:8legd,項目名稱:qor-sorting,代碼行數:9,代碼來源:callbacks.go

示例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
}
開發者ID:fengjh,項目名稱:gorm_cannot_updates_virtual_attributes,代碼行數:11,代碼來源:main.go

示例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)
			}
		}
	}
}
開發者ID:8legd,項目名稱:qor-qor,代碼行數:13,代碼來源:callbacks.go

示例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
}
開發者ID:earaujoassis,項目名稱:space,代碼行數:7,代碼來源:sessions.go

示例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)
		}
	}
}
開發者ID:JosephBuchma,項目名稱:qor,代碼行數:14,代碼來源:callbacks.go

示例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)
			}
		}
	}
}
開發者ID:JosephBuchma,項目名稱:qor,代碼行數:20,代碼來源:callbacks.go

示例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
}
開發者ID:earaujoassis,項目名稱:space,代碼行數:10,代碼來源:clients.go

示例10: BeforeUpdate

// 顧客情報更新前処理
func (customer *Customer) BeforeUpdate(scope *gorm.Scope) error {
	// UpdatedAtの設定
	scope.SetColumn("UpdatedAt", time.Now())
	return nil
}
開發者ID:yoito,項目名稱:nasuzugaru-server,代碼行數:6,代碼來源:customer.go

示例11: BeforeUpdate

func (friend *Friends) BeforeUpdate(scope *gorm.Scope) (err error) {
	scope.SetColumn("updated_at", time.Now().Unix())
	return
}
開發者ID:ts25504,項目名稱:MuShare,代碼行數:4,代碼來源:friends.go


注:本文中的github.com/jinzhu/gorm.Scope.SetColumn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。