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


Golang Scope.New方法代碼示例

本文整理匯總了Golang中github.com/jinzhu/gorm.Scope.New方法的典型用法代碼示例。如果您正苦於以下問題:Golang Scope.New方法的具體用法?Golang Scope.New怎麽用?Golang Scope.New使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/jinzhu/gorm.Scope的用法示例。


在下文中一共展示了Scope.New方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: isProductionModeAndNewScope

func isProductionModeAndNewScope(scope *gorm.Scope) (isProduction bool, clone *gorm.Scope) {
	if !IsDraftMode(scope.DB()) {
		if _, ok := scope.InstanceGet("publish:supported_model"); ok {
			table := OriginalTableName(scope.TableName())
			clone := scope.New(scope.Value)
			clone.Search.Table(table)
			return true, clone
		}
	}
	return false, nil
}
開發者ID:qor,項目名稱:publish,代碼行數:11,代碼來源:callbacks.go

示例2: getModeAndNewScope

func getModeAndNewScope(scope *gorm.Scope) (isProduction bool, clone *gorm.Scope) {
	if draftMode, ok := scope.Get("publish:draft_mode"); !ok || !draftMode.(bool) {
		if _, ok := scope.InstanceGet("publish:supported_model"); ok {
			table := originalTableName(scope.TableName())
			clone := scope.New(scope.Value)
			clone.Search.Table(table)
			return true, clone
		}
	}
	return false, nil
}
開發者ID:kennylixi,項目名稱:qor,代碼行數:11,代碼來源:callbacks.go

示例3: updateFields

// Callback function: invoked after the creation/update of an object. To populate its default fields
func updateFields(scope *gorm.Scope) {
	if !scope.HasError() {
		newScope := scope.New(scope.Value)
		newScope.Search = newScope.Search.Table(scope.TableName())

		if scope.PrimaryKey() != "" {
			gorm.Query(newScope)
		} else {
			// TODO: find a way to populate fields of scope.Value selecting * matching on every fields

		}
		scope = newScope
	}
}
開發者ID:alfateam123,項目名稱:nerdz-api,代碼行數:15,代碼來源:db.go

示例4: 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

示例5: 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

示例6: getCurrentUser

func getCurrentUser(scope *gorm.Scope) (string, bool) {
	var user interface{}
	var hasUser bool

	user, hasUser = scope.DB().Get("qor:current_user")

	if !hasUser {
		user, hasUser = scope.DB().Get("audited:current_user")
	}

	if hasUser {
		var currentUser string
		if primaryField := scope.New(user).PrimaryField(); primaryField != nil {
			currentUser = fmt.Sprintf("%v", primaryField.Field.Interface())
		} else {
			currentUser = fmt.Sprintf("%v", user)
		}

		return currentUser, true
	}

	return "", false
}
開發者ID:8legd,項目名稱:qor-qor,代碼行數:23,代碼來源:callbacks.go


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