本文整理汇总了Golang中github.com/couchbaselabs/query/value.AnnotatedValue.SetAttachment方法的典型用法代码示例。如果您正苦于以下问题:Golang AnnotatedValue.SetAttachment方法的具体用法?Golang AnnotatedValue.SetAttachment怎么用?Golang AnnotatedValue.SetAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbaselabs/query/value.AnnotatedValue
的用法示例。
在下文中一共展示了AnnotatedValue.SetAttachment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processItem
func (this *Clone) processItem(item value.AnnotatedValue, context *Context) bool {
target, ok := item.GetAttachment("target").(value.Value)
if !ok {
target = item
}
item.SetAttachment("clone", target.CopyForUpdate())
return this.sendItem(item)
}
示例2: processMatch
func (this *Merge) processMatch(item value.AnnotatedValue,
context *Context, update, delete, insert Operator) bool {
kv, e := this.plan.Key().Evaluate(item, context)
if e != nil {
context.Error(errors.NewError(e, "Error evaluatating MERGE key."))
return false
}
ka := kv.Actual()
k, ok := ka.(string)
if !ok {
context.Error(errors.NewError(nil,
fmt.Sprintf("Invalid MERGE key %v of type %T.", ka, ka)))
return false
}
bvs, err := this.plan.Keyspace().Fetch([]string{k})
if err != nil {
context.Error(err)
return false
}
if len(bvs) > 0 {
bv := bvs[0].Value
// Matched; join source and target
if update != nil {
item.SetAttachment("target", bv)
}
abv := value.NewAnnotatedValue(bv)
item.SetField(this.plan.KeyspaceRef().Alias(), abv)
// Perform UPDATE and/or DELETE
if update != nil {
update.Input().ItemChannel() <- item
}
if delete != nil {
delete.Input().ItemChannel() <- item
}
} else {
// Not matched; INSERT
if insert != nil {
insert.Input().ItemChannel() <- item
}
}
return true
}
示例3: processItem
func (this *Set) processItem(item value.AnnotatedValue, context *Context) bool {
clone, ok := item.GetAttachment("clone").(value.AnnotatedValue)
if !ok {
context.Error(errors.NewError(nil,
fmt.Sprintf("Invalid UPDATE clone of type %T.", clone)))
return false
}
var e error
for _, t := range this.plan.Node().Terms() {
clone, e = setPath(t, clone, item, context)
if e != nil {
context.Error(errors.NewError(e, "Error evaluating SET clause."))
return false
}
}
item.SetAttachment("clone", clone)
return this.sendItem(item)
}
示例4: flushBatch
func (this *Fetch) flushBatch(context *Context) bool {
if len(this.batch) == 0 {
return true
}
// Build list of keys
keys := make([]string, len(this.batch))
for i, av := range this.batch {
meta := av.GetAttachment("meta")
switch meta := meta.(type) {
case map[string]interface{}:
key := meta["id"]
act := value.NewValue(key).Actual()
switch act := act.(type) {
case string:
keys[i] = act
default:
context.Error(errors.NewError(nil, fmt.Sprintf(
"Missing or invalid primary key %v of type %T.",
act, act)))
return false
}
default:
context.Error(errors.NewError(nil,
"Missing or invalid meta for primary key."))
return false
}
}
// Fetch
pairs, err := this.plan.Keyspace().Fetch(keys)
if err != nil {
context.Error(err)
return false
}
// Attach meta and send
for i, pair := range pairs {
item := pair.Value
var fv value.AnnotatedValue
// Apply projection, if any
projection := this.plan.Term().Projection()
if projection != nil {
projectedItem, e := projection.Evaluate(item, context)
if e != nil {
context.Error(errors.NewError(e,
"Error evaluating fetch path."))
return false
}
if projectedItem.Type() == value.MISSING {
continue
}
fv = value.NewAnnotatedValue(projectedItem)
} else {
fv = value.NewAnnotatedValue(item)
}
av := this.batch[i]
switch item := item.(type) {
case value.AnnotatedValue:
meta := item.(value.AnnotatedValue).GetAttachment("meta")
fv.SetAttachment("meta", meta)
default:
fv.SetAttachment("meta", av.GetAttachment("meta"))
}
av.SetField(this.plan.Term().Alias(), fv)
if !this.sendItem(av) {
return false
}
}
return true
}
示例5: processItem
func (this *Nest) processItem(item value.AnnotatedValue, context *Context) bool {
kv, e := this.plan.Term().Keys().Evaluate(item, context)
if e != nil {
context.Error(errors.NewError(e, "Error evaluating NEST keys."))
return false
}
actuals := kv.Actual()
switch actuals.(type) {
case []interface{}:
case nil:
actuals = []interface{}(nil)
default:
actuals = []interface{}{actuals}
}
acts := actuals.([]interface{})
if len(acts) == 0 {
// Outer nest
return !this.plan.Outer() || this.sendItem(item)
}
// Build list of keys
keys := make([]string, 0, len(acts))
for _, key := range acts {
k := value.NewValue(key).Actual()
switch k := k.(type) {
case string:
keys = append(keys, k)
}
}
// Fetch
pairs, err := this.plan.Keyspace().Fetch(keys)
if err != nil {
context.Error(err)
return false
}
found := len(pairs) > 0
if !found && !this.plan.Outer() {
return true
}
nvs := make([]interface{}, 0, len(pairs))
for i, pair := range pairs {
nestItem := pair.Value
var nv value.AnnotatedValue
// Apply projection, if any
projection := this.plan.Term().Projection()
if projection != nil {
projectedItem, e := projection.Evaluate(nestItem, context)
if e != nil {
context.Error(errors.NewError(e,
"Error evaluating nest path."))
return false
}
if projectedItem.Type() == value.MISSING {
continue
}
nv = value.NewAnnotatedValue(projectedItem)
} else {
nv = value.NewAnnotatedValue(nestItem)
}
nv.SetAttachment("meta", map[string]interface{}{"id": keys[i]})
nvs = append(nvs, nv)
}
// Attach and send
item.SetField(this.plan.Term().Alias(), nvs)
return this.sendItem(item)
}
示例6: processItem
func (this *Join) processItem(item value.AnnotatedValue, context *Context) bool {
kv, e := this.plan.Term().Keys().Evaluate(item, context)
if e != nil {
context.Error(errors.NewError(e, "Error evaluating JOIN keys."))
return false
}
actuals := kv.Actual()
switch actuals.(type) {
case []interface{}:
case nil:
actuals = []interface{}(nil)
default:
actuals = []interface{}{actuals}
}
acts := actuals.([]interface{})
if len(acts) == 0 {
// Outer join
return !this.plan.Outer() || this.sendItem(item)
}
// Build list of keys
keys := make([]string, 0, len(acts))
for _, key := range acts {
k := value.NewValue(key).Actual()
switch k := k.(type) {
case string:
keys = append(keys, k)
}
}
// Fetch
pairs, err := this.plan.Keyspace().Fetch(keys)
if err != nil {
context.Error(err)
return false
}
found := len(pairs) > 0
// Attach and send
for i, pair := range pairs {
joinItem := pair.Value
var jv value.AnnotatedValue
// Apply projection, if any
projection := this.plan.Term().Projection()
if projection != nil {
projectedItem, e := projection.Evaluate(joinItem, context)
if e != nil {
context.Error(errors.NewError(e,
"Error evaluating join path."))
return false
}
jv = value.NewAnnotatedValue(projectedItem)
} else {
jv = value.NewAnnotatedValue(joinItem)
}
jv.SetAttachment("meta", map[string]interface{}{"id": keys[i]})
var av value.AnnotatedValue
if i < len(pairs)-1 {
av = value.NewAnnotatedValue(item.Copy())
} else {
av = item
}
av.SetField(this.plan.Term().Alias(), jv)
if !this.sendItem(av) {
return false
}
}
return found || !this.plan.Outer() || this.sendItem(item)
}