本文整理匯總了Golang中github.com/jinzhu/gorm.Scope.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Scope.Get方法的具體用法?Golang Scope.Get怎麽用?Golang Scope.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jinzhu/gorm.Scope
的用法示例。
在下文中一共展示了Scope.Get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: validate
func validate(scope *gorm.Scope) {
if _, ok := scope.Get("gorm:update_column"); !ok {
if result, ok := scope.DB().Get(skipValidations); !(ok && result.(bool)) {
scope.CallMethodWithErrorCheck("Validate")
}
}
}
示例2: isDraftMode
func isDraftMode(scope *gorm.Scope) bool {
if draftMode, ok := scope.Get("publish:draft_mode"); ok {
if isDraft, ok := draftMode.(bool); ok && isDraft {
return true
}
}
return false
}
示例3: createPublishEvent
func createPublishEvent(scope *gorm.Scope) {
if _, ok := scope.InstanceGet("publish:creating_publish_event"); ok {
if event, ok := scope.Get(publishEvent); ok {
if event, ok := event.(*PublishEvent); ok {
event.PublishStatus = DIRTY
scope.Err(scope.NewDB().Save(&event).Error)
}
}
}
}
示例4: 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
}
示例5: deleteScope
func deleteScope(scope *gorm.Scope) {
if !scope.HasError() {
_, supportedModel := scope.InstanceGet("publish:supported_model")
isDraftMode, ok := scope.Get("publish:draft_mode")
if supportedModel && (ok && isDraftMode.(bool)) {
scope.Raw(
fmt.Sprintf("UPDATE %v SET deleted_at=%v, publish_status=%v %v",
scope.QuotedTableName(),
scope.AddToVars(gorm.NowFunc()),
scope.AddToVars(DIRTY),
scope.CombinedConditionSql(),
))
scope.Exec()
} else {
gorm.Delete(scope)
}
}
}
示例6: validate
func validate(scope *gorm.Scope) {
if _, ok := scope.Get("gorm:update_column"); !ok {
if result, ok := scope.DB().Get(skipValidations); !(ok && result.(bool)) {
if !scope.HasError() {
scope.CallMethod("Validate")
resource := scope.IndirectValue().Interface()
_, validatorErrors := govalidator.ValidateStruct(resource)
if validatorErrors != nil {
if errors, ok := validatorErrors.(govalidator.Errors); ok {
for _, err := range flatValidatorErrors(errors) {
scope.DB().AddError(formattedError(err, resource))
}
} else {
scope.DB().AddError(validatorErrors)
}
}
}
}
}
}