本文整理匯總了Golang中github.com/couchbase/query/value.Value.Type方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.Type方法的具體用法?Golang Value.Type怎麽用?Golang Value.Type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/couchbase/query/value.Value
的用法示例。
在下文中一共展示了Value.Type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Apply
/*
Perform either case-sensitive or case-insensitive field lookup.
*/
func (this *Field) Apply(context Context, first, second value.Value) (value.Value, error) {
switch second.Type() {
case value.STRING:
s := second.Actual().(string)
v, ok := first.Field(s)
if !ok && this.caseInsensitive {
s = strings.ToLower(s)
fields := first.Fields()
for f, val := range fields {
if s == strings.ToLower(f) {
return value.NewValue(val), nil
}
}
}
return v, nil
case value.MISSING:
return value.MISSING_VALUE, nil
default:
if first.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else {
return value.NULL_VALUE, nil
}
}
}
示例2: Apply
/*
It returns a string based on the input expr value. Values
missing, null and strings return themselves. False, true
(boolean) and numbers return their string representation.
This is done using the Sprint method defined in fmt for Go.
All other values map to null.
*/
func (this *ToString) Apply(context Context, arg value.Value) (value.Value, error) {
switch arg.Type() {
case value.MISSING, value.NULL, value.STRING:
return arg, nil
case value.BOOLEAN:
return value.NewValue(fmt.Sprint(arg.Actual())), nil
case value.NUMBER:
f := arg.Actual().(float64)
if f == -0 {
f = 0
}
s := strconv.FormatFloat(f, 'f', -1, 64)
return value.NewValue(s), nil
case value.BINARY:
raw, ok := arg.Actual().([]byte)
if !ok {
return value.NULL_VALUE, nil
}
s := string(raw)
return value.NewValue(s), nil
default:
return value.NULL_VALUE, nil
}
}
示例3: Apply
/*
This method returns an object value. The input of types
missing, null and object return themselves. For all other
values, return an _EMPTY_OBJECT value.
*/
func (this *ToObject) Apply(context Context, arg value.Value) (value.Value, error) {
switch arg.Type() {
case value.MISSING, value.NULL, value.OBJECT:
return arg, nil
}
return _EMPTY_OBJECT, nil
}
示例4: Apply
/*
Evaluates the Is Missing comparison operation for expressions.
Return true if the input argument value is a missing value,
else return false.
*/
func (this *IsMissing) Apply(context Context, arg value.Value) (value.Value, error) {
switch arg.Type() {
case value.MISSING:
return value.TRUE_VALUE, nil
default:
return value.FALSE_VALUE, nil
}
}
示例5: Apply
/*
Return the neagation of the input value, if the type of input is a number.
For missing return a missing value, and for all other input types return a
null.
*/
func (this *Neg) Apply(context Context, arg value.Value) (value.Value, error) {
if arg.Type() == value.NUMBER {
return value.NewValue(-arg.Actual().(float64)), nil
} else if arg.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else {
return value.NULL_VALUE, nil
}
}
示例6: Apply
func (this *Base64) Apply(context Context, operand value.Value) (value.Value, error) {
if operand.Type() == value.MISSING {
return operand, nil
}
bytes, _ := operand.MarshalJSON() // Ignore errors from BINARY values
str := base64.StdEncoding.EncodeToString(bytes)
return value.NewValue(str), nil
}
示例7: get
func (this *preparedCache) get(name value.Value) *Prepared {
if name.Type() != value.STRING || !name.Truth() {
return nil
}
this.RLock()
rv := this.prepareds[name.Actual().(string)]
this.RUnlock()
return rv
}
示例8: Apply
/*
This method returns true if he value is an array and contains at least one element.
This is done by checking the length of the array. If the type of input value
is missing then return a missing value, and for all other types return null.
*/
func (this *Exists) Apply(context Context, arg value.Value) (value.Value, error) {
if arg.Type() == value.ARRAY {
a := arg.Actual().([]interface{})
return value.NewValue(len(a) > 0), nil
} else if arg.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else {
return value.NULL_VALUE, nil
}
}
示例9: Apply
/*
This method returns the length of the object. If the type of
input is missing then return a missing value, and if not an
object return a null value. Convert it to a valid Go type.
Cast it to a map from string to interface and return its
length by using the len function by casting it to float64.
*/
func (this *ObjectLength) Apply(context Context, arg value.Value) (value.Value, error) {
if arg.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else if arg.Type() != value.OBJECT {
return value.NULL_VALUE, nil
}
oa := arg.Actual().(map[string]interface{})
return value.NewValue(float64(len(oa))), nil
}
示例10: Apply
/*
This method returns the length of the input array using
the len method. If the input value is of type missing
return a missing value, and for all non array values
return null.
*/
func (this *ArrayLength) Apply(context Context, arg value.Value) (value.Value, error) {
if arg.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else if arg.Type() != value.ARRAY {
return value.NULL_VALUE, nil
}
aa := arg.Actual().([]interface{})
return value.NewValue(float64(len(aa))), nil
}
示例11: Apply
/*
This method takes in an argument value and returns its length
as value. If the input type is missing return missing, and if
it isnt string then return null value. Use the len method to
return the length of the input string. Convert it into valid
N1QL value and return.
*/
func (this *Length) Apply(context Context, arg value.Value) (value.Value, error) {
if arg.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else if arg.Type() != value.STRING {
return value.NULL_VALUE, nil
}
rv := len(arg.Actual().(string))
return value.NewValue(float64(rv)), nil
}
示例12: CumulateInitial
/*
Aggregates input data by evaluating operands.For all
values other than Number, return the input value itself.
Call setAdd to compute the intermediate aggregate value
and return it.
*/
func (this *AvgDistinct) CumulateInitial(item, cumulative value.Value, context Context) (value.Value, error) {
item, e := this.Operand().Evaluate(item, context)
if e != nil {
return nil, e
}
if item.Type() != value.NUMBER {
return cumulative, nil
}
return setAdd(item, cumulative)
}
示例13: Apply
func (this *Not) Apply(context Context, arg value.Value) (value.Value, error) {
switch arg.Type() {
case value.MISSING, value.NULL:
return arg, nil
default:
if arg.Truth() {
return value.FALSE_VALUE, nil
} else {
return value.TRUE_VALUE, nil
}
}
}
示例14: CumulateInitial
/*
Aggregates input data by evaluating operands. For missing
item values, return the input value itself. Call
cumulatePart to compute the intermediate aggregate value
and return it.
*/
func (this *ArrayAgg) CumulateInitial(item, cumulative value.Value, context Context) (value.Value, error) {
item, e := this.Operand().Evaluate(item, context)
if e != nil {
return nil, e
}
if item.Type() <= value.MISSING || item.Type() == value.BINARY {
return cumulative, nil
}
return this.cumulatePart(value.NewValue([]interface{}{item}), cumulative, context)
}
示例15: CumulateInitial
func (this *Sum) CumulateInitial(item, cumulative value.Value, context Context) (value.Value, error) {
item, e := this.Operand().Evaluate(item, context)
if e != nil {
return nil, e
}
if item.Type() != value.NUMBER {
return cumulative, nil
}
return this.cumulatePart(item, cumulative, context)
}