本文整理汇总了Golang中github.com/couchbase/query/expression.Function类的典型用法代码示例。如果您正苦于以下问题:Golang Function类的具体用法?Golang Function怎么用?Golang Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Function类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: VisitFunction
func (this *DNF) VisitFunction(expr expression.Function) (interface{}, error) {
var exp expression.Expression = expr
switch expr := expr.(type) {
case *expression.IsBoolean:
exp = expression.NewLE(expr.Operand(), expression.TRUE_EXPR)
case *expression.IsNumber:
exp = expression.NewAnd(
expression.NewGT(expr.Operand(), expression.TRUE_EXPR),
expression.NewLT(expr.Operand(), expression.EMPTY_STRING_EXPR))
case *expression.IsString:
exp = expression.NewAnd(
expression.NewGE(expr.Operand(), expression.EMPTY_STRING_EXPR),
expression.NewLT(expr.Operand(), expression.EMPTY_ARRAY_EXPR))
case *expression.IsArray:
exp = expression.NewAnd(
expression.NewGE(expr.Operand(), expression.EMPTY_ARRAY_EXPR),
expression.NewLT(expr.Operand(), _EMPTY_OBJECT_EXPR))
case *expression.IsObject:
// Not equivalent to IS OBJECT. Includes BINARY values.
exp = expression.NewGE(expr.Operand(), _EMPTY_OBJECT_EXPR)
}
return exp, exp.MapChildren(this)
}
示例2: VisitFunction
// Function
func (this *sargFactory) VisitFunction(expr expression.Function) (interface{}, error) {
switch expr := expr.(type) {
case *expression.RegexpLike:
return newSargLike(expr, expr.Regexp()), nil
}
return newSargDefault(expr), nil
}
示例3: VisitFunction
// Function
func (this *JSConverter) VisitFunction(expr expression.Function) (interface{}, error) {
var buf bytes.Buffer
functionExpr := &funcExpr{operands: list.New()}
//buf.WriteString("(")
var nopush bool
var nobracket bool
var pushOperands bool
var writeLater bool
var functionName string
switch strings.ToLower(expr.Name()) {
case "lower":
functionName = ".toLowerCase()"
writeLater = true
case "upper":
functionName = ".toUpperCase()"
writeLater = true
case "object_length":
fallthrough
case "array_length":
fallthrough
case "poly_length":
fallthrough
case "string_length":
fallthrough
case "length":
functionName = ".length"
writeLater = true
case "str_to_millis":
fallthrough
case "millis":
nopush = true
buf.WriteString("Date.parse(")
case "contains":
functionExpr.name = ".indexOf("
this.stack.Push(functionExpr)
pushOperands = true
case "substr":
functionExpr.name = ".substring("
this.stack.Push(functionExpr)
pushOperands = true
case "now_millis":
buf.WriteString("Date.now().toString()")
case "meta":
buf.WriteString("meta")
nobracket = true
default:
nopush = true
buf.WriteString(expr.Name())
buf.WriteString("(")
}
var firstOp expression.Expression
for i, op := range expr.Operands() {
if pushOperands == true {
if i == 0 {
firstOp = op
continue
} else {
functionExpr.operands.PushBack(op)
}
} else {
if i > 0 {
buf.WriteString(", ")
}
if op == nil {
buf.WriteString("*") // for count(*)
} else {
buf.WriteString(this.Visit(op))
}
}
}
if firstOp != nil {
buf.WriteString(this.Visit(firstOp))
}
if nopush == true && nobracket == false {
buf.WriteString(")")
}
if writeLater == true {
buf.WriteString(functionName)
}
return buf.String(), nil
}