sq/libsq/ast/func.go

55 lines
1.0 KiB
Go
Raw Normal View History

2020-08-06 20:58:47 +03:00
package ast
var (
_ Node = (*FuncNode)(nil)
_ ResultColumn = (*FuncNode)(nil)
)
2020-08-06 20:58:47 +03:00
// FuncNode models a function. For example, "COUNT()".
type FuncNode struct {
2020-08-06 20:58:47 +03:00
baseNode
fnName string
alias string
2020-08-06 20:58:47 +03:00
}
// FuncName returns the function name.
func (fn *FuncNode) FuncName() string {
2020-08-06 20:58:47 +03:00
return fn.fnName
}
// String returns a log/debug-friendly representation.
func (fn *FuncNode) String() string {
str := nodeString(fn)
if fn.alias != "" {
str += ":" + fn.alias
}
return str
2020-08-06 20:58:47 +03:00
}
// Text implements ResultColumn.
func (fn *FuncNode) Text() string {
return fn.ctx.GetText()
2020-08-06 20:58:47 +03:00
}
// Alias implements ResultColumn.
func (fn *FuncNode) Alias() string {
return fn.alias
}
2020-08-06 20:58:47 +03:00
// SetChildren implements Node.
func (fn *FuncNode) SetChildren(children []Node) error {
2020-08-06 20:58:47 +03:00
fn.setChildren(children)
return nil
}
// IsColumn implements ResultColumn.
func (fn *FuncNode) IsColumn() bool {
2020-08-06 20:58:47 +03:00
return false
}
func (fn *FuncNode) AddChild(child Node) error {
// TODO: add check for valid FuncNode child types
2020-08-06 20:58:47 +03:00
fn.addChild(child)
return child.SetParent(fn)
}