本文整理匯總了Golang中github.com/couchbase/query/value.Value.CopyForUpdate方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.CopyForUpdate方法的具體用法?Golang Value.CopyForUpdate怎麽用?Golang Value.CopyForUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/couchbase/query/value.Value
的用法示例。
在下文中一共展示了Value.CopyForUpdate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Apply
/*
This method takes in an object, a name and a value
and returns a new object that contains the name /
attribute pair. If the type of input is missing
then return a missing value, and if not an object
return a null value.
If the key is found, an error is thrown
*/
func (this *ObjectAdd) Apply(context Context, first, second, third value.Value) (value.Value, error) {
// First must be an object, or we're out
if first.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else if first.Type() != value.OBJECT {
return value.NULL_VALUE, nil
}
// second must be a non empty string
if second.Type() != value.STRING || second.Actual().(string) == "" {
return first, nil
}
field := second.Actual().(string)
// we don't overwrite
_, exists := first.Field(field)
if exists {
return value.NULL_VALUE, nil
}
// SetField will remove if the attribute is missing, but we don't
// overwrite anyway, so we might just skip now
if third.Type() != value.MISSING {
rv := first.CopyForUpdate()
rv.SetField(field, third)
return rv, nil
}
return first, nil
}