Documentation ¶
Overview ¶
Package ast holds types and functionality for the SLQ AST.
Note: the SLQ language implementation is fairly rudimentary and has some incomplete functionality.
Index ¶
- type AST
- func (a *AST) AddChild(node Node) error
- func (a *AST) AddSegment(seg *SegmentNode)
- func (a *AST) Children() []Node
- func (a *AST) Context() antlr.ParseTree
- func (a *AST) Parent() Node
- func (a *AST) Segments() []*SegmentNode
- func (a *AST) SetChildren(children []Node) error
- func (a *AST) SetContext(ctx antlr.ParseTree) error
- func (a *AST) SetParent(parent Node) error
- func (a *AST) String() string
- func (a *AST) Text() string
- type ArgNode
- func (bn *ArgNode) AddChild(child Node) error
- func (bn *ArgNode) Children() []Node
- func (bn *ArgNode) Context() antlr.ParseTree
- func (n *ArgNode) Key() string
- func (bn *ArgNode) Parent() Node
- func (bn *ArgNode) SetChildren(children []Node) error
- func (bn *ArgNode) SetContext(ctx antlr.ParseTree) error
- func (bn *ArgNode) SetParent(parent Node) error
- func (n *ArgNode) String() string
- func (bn *ArgNode) Text() string
- type Cmpr
- func (bn *Cmpr) AddChild(child Node) error
- func (bn *Cmpr) Children() []Node
- func (bn *Cmpr) Context() antlr.ParseTree
- func (bn *Cmpr) Parent() Node
- func (bn *Cmpr) SetChildren(children []Node) error
- func (bn *Cmpr) SetContext(ctx antlr.ParseTree) error
- func (bn *Cmpr) SetParent(parent Node) error
- func (c *Cmpr) String() string
- func (bn *Cmpr) Text() string
- type ColSelectorNode
- func (bn ColSelectorNode) AddChild(child Node) error
- func (n *ColSelectorNode) Alias() string
- func (bn ColSelectorNode) Children() []Node
- func (n *ColSelectorNode) ColName() string
- func (bn ColSelectorNode) Context() antlr.ParseTree
- func (n *ColSelectorNode) IsColumn() bool
- func (bn ColSelectorNode) Parent() Node
- func (bn ColSelectorNode) SetChildren(children []Node) error
- func (bn ColSelectorNode) SetContext(ctx antlr.ParseTree) error
- func (bn ColSelectorNode) SetParent(parent Node) error
- func (n *ColSelectorNode) String() string
- func (n *ColSelectorNode) Text() string
- type ExprNode
- func (n *ExprNode) AddChild(child Node) error
- func (bn *ExprNode) Children() []Node
- func (bn *ExprNode) Context() antlr.ParseTree
- func (bn *ExprNode) Parent() Node
- func (n *ExprNode) SetChildren(children []Node) error
- func (bn *ExprNode) SetContext(ctx antlr.ParseTree) error
- func (bn *ExprNode) SetParent(parent Node) error
- func (n *ExprNode) String() string
- func (bn *ExprNode) Text() string
- type FuncNode
- func (fn *FuncNode) AddChild(child Node) error
- func (fn *FuncNode) Alias() string
- func (bn *FuncNode) Children() []Node
- func (bn *FuncNode) Context() antlr.ParseTree
- func (fn *FuncNode) FuncName() string
- func (fn *FuncNode) IsColumn() bool
- func (bn *FuncNode) Parent() Node
- func (fn *FuncNode) SetChildren(children []Node) error
- func (bn *FuncNode) SetContext(ctx antlr.ParseTree) error
- func (bn *FuncNode) SetParent(parent Node) error
- func (fn *FuncNode) String() string
- func (fn *FuncNode) Text() string
- type GroupByNode
- func (n *GroupByNode) AddChild(child Node) error
- func (bn *GroupByNode) Children() []Node
- func (bn *GroupByNode) Context() antlr.ParseTree
- func (bn *GroupByNode) Parent() Node
- func (n *GroupByNode) SetChildren(children []Node) error
- func (bn *GroupByNode) SetContext(ctx antlr.ParseTree) error
- func (bn *GroupByNode) SetParent(parent Node) error
- func (n *GroupByNode) String() string
- func (bn *GroupByNode) Text() string
- type HandleNode
- func (bn *HandleNode) AddChild(child Node) error
- func (bn *HandleNode) Children() []Node
- func (bn *HandleNode) Context() antlr.ParseTree
- func (bn *HandleNode) Parent() Node
- func (bn *HandleNode) SetChildren(children []Node) error
- func (bn *HandleNode) SetContext(ctx antlr.ParseTree) error
- func (bn *HandleNode) SetParent(parent Node) error
- func (d *HandleNode) String() string
- func (bn *HandleNode) Text() string
- type Inspector
- func (in *Inspector) CountNodes(typ reflect.Type) int
- func (in *Inspector) FindColExprSegment() (*SegmentNode, error)
- func (in *Inspector) FindFinalTablerSegment() (*SegmentNode, error)
- func (in *Inspector) FindGroupByNode() (*GroupByNode, error)
- func (in *Inspector) FindHandles() []string
- func (in *Inspector) FindNodes(typ reflect.Type) []Node
- func (in *Inspector) FindOrderByNode() (*OrderByNode, error)
- func (in *Inspector) FindTablerSegments() []*SegmentNode
- func (in *Inspector) FindUniqueNode() (*UniqueNode, error)
- func (in *Inspector) FindWhereClauses() ([]*WhereNode, error)
- type JoinConstraint
- func (n *JoinConstraint) AddChild(child Node) error
- func (n *JoinConstraint) Children() []Node
- func (n *JoinConstraint) Context() antlr.ParseTree
- func (n *JoinConstraint) Parent() Node
- func (n *JoinConstraint) SetChildren(children []Node) error
- func (n *JoinConstraint) SetContext(ctx antlr.ParseTree) error
- func (n *JoinConstraint) SetParent(parent Node) error
- func (n *JoinConstraint) String() string
- func (n *JoinConstraint) Text() string
- type JoinNode
- func (jn *JoinNode) AddChild(node Node) error
- func (jn *JoinNode) Children() []Node
- func (jn *JoinNode) Context() antlr.ParseTree
- func (jn *JoinNode) LeftTbl() *TblSelectorNode
- func (jn *JoinNode) Parent() Node
- func (jn *JoinNode) RightTbl() *TblSelectorNode
- func (jn *JoinNode) Segment() *SegmentNode
- func (jn *JoinNode) SetChildren(children []Node) error
- func (jn *JoinNode) SetContext(ctx antlr.ParseTree) error
- func (jn *JoinNode) SetParent(parent Node) error
- func (jn *JoinNode) String() string
- func (jn *JoinNode) Text() string
- type LiteralNode
- func (bn *LiteralNode) AddChild(child Node) error
- func (bn *LiteralNode) Children() []Node
- func (bn *LiteralNode) Context() antlr.ParseTree
- func (n *LiteralNode) LiteralType() LiteralType
- func (bn *LiteralNode) Parent() Node
- func (bn *LiteralNode) SetChildren(children []Node) error
- func (bn *LiteralNode) SetContext(ctx antlr.ParseTree) error
- func (bn *LiteralNode) SetParent(parent Node) error
- func (n *LiteralNode) String() string
- func (bn *LiteralNode) Text() string
- type LiteralType
- type Node
- type OperatorNode
- func (bn *OperatorNode) AddChild(child Node) error
- func (bn *OperatorNode) Children() []Node
- func (bn *OperatorNode) Context() antlr.ParseTree
- func (bn *OperatorNode) Parent() Node
- func (bn *OperatorNode) SetChildren(children []Node) error
- func (bn *OperatorNode) SetContext(ctx antlr.ParseTree) error
- func (bn *OperatorNode) SetParent(parent Node) error
- func (n *OperatorNode) String() string
- func (bn *OperatorNode) Text() string
- type OrderByDirection
- type OrderByNode
- func (n *OrderByNode) AddChild(child Node) error
- func (bn *OrderByNode) Children() []Node
- func (bn *OrderByNode) Context() antlr.ParseTree
- func (bn *OrderByNode) Parent() Node
- func (n *OrderByNode) SetChildren(children []Node) error
- func (bn *OrderByNode) SetContext(ctx antlr.ParseTree) error
- func (bn *OrderByNode) SetParent(parent Node) error
- func (n *OrderByNode) String() string
- func (n *OrderByNode) Terms() []*OrderByTermNode
- func (bn *OrderByNode) Text() string
- type OrderByTermNode
- func (n *OrderByTermNode) AddChild(child Node) error
- func (bn *OrderByTermNode) Children() []Node
- func (bn *OrderByTermNode) Context() antlr.ParseTree
- func (n *OrderByTermNode) Direction() OrderByDirection
- func (bn *OrderByTermNode) Parent() Node
- func (n *OrderByTermNode) Selector() Node
- func (n *OrderByTermNode) SetChildren(children []Node) error
- func (bn *OrderByTermNode) SetContext(ctx antlr.ParseTree) error
- func (bn *OrderByTermNode) SetParent(parent Node) error
- func (n *OrderByTermNode) String() string
- func (bn *OrderByTermNode) Text() string
- type ResultColumn
- type RowRangeNode
- func (bn *RowRangeNode) AddChild(child Node) error
- func (bn *RowRangeNode) Children() []Node
- func (bn *RowRangeNode) Context() antlr.ParseTree
- func (bn *RowRangeNode) Parent() Node
- func (rr *RowRangeNode) Range() (offset, limit int)
- func (bn *RowRangeNode) SetChildren(children []Node) error
- func (bn *RowRangeNode) SetContext(ctx antlr.ParseTree) error
- func (rr *RowRangeNode) SetParent(parent Node) error
- func (rr *RowRangeNode) String() string
- func (bn *RowRangeNode) Text() string
- type SegmentNode
- func (s *SegmentNode) AddChild(child Node) error
- func (s *SegmentNode) ChildType() (reflect.Type, error)
- func (s *SegmentNode) Children() []Node
- func (s *SegmentNode) Context() antlr.ParseTree
- func (s *SegmentNode) Next() *SegmentNode
- func (s *SegmentNode) Parent() Node
- func (s *SegmentNode) Prev() *SegmentNode
- func (s *SegmentNode) SegIndex() int
- func (s *SegmentNode) SetChildren(children []Node) error
- func (s *SegmentNode) SetContext(ctx antlr.ParseTree) error
- func (s *SegmentNode) SetParent(parent Node) error
- func (s *SegmentNode) String() string
- func (s *SegmentNode) Text() string
- type Selector
- type SelectorNode
- func (bn *SelectorNode) AddChild(child Node) error
- func (bn *SelectorNode) Children() []Node
- func (bn *SelectorNode) Context() antlr.ParseTree
- func (bn *SelectorNode) Parent() Node
- func (s *SelectorNode) SelValue() (string, error)
- func (bn *SelectorNode) SetChildren(children []Node) error
- func (bn *SelectorNode) SetContext(ctx antlr.ParseTree) error
- func (bn *SelectorNode) SetParent(parent Node) error
- func (s *SelectorNode) String() string
- func (bn *SelectorNode) Text() string
- type Tabler
- type TblColSelectorNode
- func (bn TblColSelectorNode) AddChild(child Node) error
- func (n *TblColSelectorNode) Alias() string
- func (bn TblColSelectorNode) Children() []Node
- func (n *TblColSelectorNode) ColName() string
- func (bn TblColSelectorNode) Context() antlr.ParseTree
- func (n *TblColSelectorNode) IsColumn() bool
- func (bn TblColSelectorNode) Parent() Node
- func (bn TblColSelectorNode) SetChildren(children []Node) error
- func (bn TblColSelectorNode) SetContext(ctx antlr.ParseTree) error
- func (bn TblColSelectorNode) SetParent(parent Node) error
- func (n *TblColSelectorNode) String() string
- func (n *TblColSelectorNode) TblName() string
- func (n *TblColSelectorNode) Text() string
- type TblSelectorNode
- func (bn *TblSelectorNode) AddChild(child Node) error
- func (bn *TblSelectorNode) Children() []Node
- func (bn *TblSelectorNode) Context() antlr.ParseTree
- func (s *TblSelectorNode) Handle() string
- func (bn *TblSelectorNode) Parent() Node
- func (s *TblSelectorNode) SelValue() (string, error)
- func (bn *TblSelectorNode) SetChildren(children []Node) error
- func (bn *TblSelectorNode) SetContext(ctx antlr.ParseTree) error
- func (bn *TblSelectorNode) SetParent(parent Node) error
- func (s *TblSelectorNode) String() string
- func (s *TblSelectorNode) TblName() string
- func (bn *TblSelectorNode) Text() string
- type UniqueNode
- func (bn *UniqueNode) AddChild(child Node) error
- func (bn *UniqueNode) Children() []Node
- func (bn *UniqueNode) Context() antlr.ParseTree
- func (bn *UniqueNode) Parent() Node
- func (bn *UniqueNode) SetChildren(children []Node) error
- func (bn *UniqueNode) SetContext(ctx antlr.ParseTree) error
- func (bn *UniqueNode) SetParent(parent Node) error
- func (n *UniqueNode) String() string
- func (bn *UniqueNode) Text() string
- type Walker
- type WhereNode
- func (n *WhereNode) AddChild(node Node) error
- func (bn *WhereNode) Children() []Node
- func (bn *WhereNode) Context() antlr.ParseTree
- func (n *WhereNode) Expr() *ExprNode
- func (bn *WhereNode) Parent() Node
- func (bn *WhereNode) SetChildren(children []Node) error
- func (bn *WhereNode) SetContext(ctx antlr.ParseTree) error
- func (bn *WhereNode) SetParent(parent Node) error
- func (n *WhereNode) String() string
- func (bn *WhereNode) Text() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AST ¶
type AST struct {
// contains filtered or unexported fields
}
AST is the Abstract Syntax Tree. It is the root node of a SQL query/stmt.
func (*AST) AddSegment ¶
func (a *AST) AddSegment(seg *SegmentNode)
AddSegment appends seg to the AST.
func (*AST) Segments ¶
func (a *AST) Segments() []*SegmentNode
func (*AST) SetChildren ¶
func (*AST) SetContext ¶
type ArgNode ¶ added in v0.31.0
type ArgNode struct {
// contains filtered or unexported fields
}
ArgNode implements the SQL "DISTINCT" clause.
func (*ArgNode) AddChild ¶ added in v0.31.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*ArgNode) Children ¶ added in v0.31.0
func (bn *ArgNode) Children() []Node
Children implements Node.Children.
func (*ArgNode) Key ¶ added in v0.31.0
Key returns the arg key. If the arg is "$name", the key is "name".
func (*ArgNode) Parent ¶ added in v0.31.0
func (bn *ArgNode) Parent() Node
Parent implements Node.Parent.
func (*ArgNode) SetChildren ¶ added in v0.31.0
func (*ArgNode) SetContext ¶ added in v0.31.0
func (bn *ArgNode) SetContext(ctx antlr.ParseTree) error
type Cmpr ¶
type Cmpr struct {
// contains filtered or unexported fields
}
Cmpr models a comparison, such as ".age == 42".
func (*Cmpr) AddChild ¶
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*Cmpr) SetChildren ¶
func (*Cmpr) SetContext ¶
func (bn *Cmpr) SetContext(ctx antlr.ParseTree) error
type ColSelectorNode ¶ added in v0.26.0
type ColSelectorNode struct { *SelectorNode // contains filtered or unexported fields }
ColSelectorNode models a column selector such as ".first_name".
func (ColSelectorNode) AddChild ¶ added in v0.26.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*ColSelectorNode) Alias ¶ added in v0.26.0
func (n *ColSelectorNode) Alias() string
Alias returns the column alias, which may be empty. For example, given the selector ".first_name:given_name", the alias is "given_name".
func (ColSelectorNode) Children ¶ added in v0.26.0
func (bn ColSelectorNode) Children() []Node
Children implements Node.Children.
func (*ColSelectorNode) ColName ¶ added in v0.26.0
func (n *ColSelectorNode) ColName() string
ColName returns the column name. Note the name is not escaped/quoted, thus it could contain whitespace, etc.
func (ColSelectorNode) Context ¶ added in v0.26.0
func (bn ColSelectorNode) Context() antlr.ParseTree
func (*ColSelectorNode) IsColumn ¶ added in v0.26.0
func (n *ColSelectorNode) IsColumn() bool
IsColumn always returns true.
func (ColSelectorNode) Parent ¶ added in v0.26.0
func (bn ColSelectorNode) Parent() Node
Parent implements Node.Parent.
func (ColSelectorNode) SetChildren ¶ added in v0.26.0
func (ColSelectorNode) SetContext ¶ added in v0.26.0
func (bn ColSelectorNode) SetContext(ctx antlr.ParseTree) error
func (*ColSelectorNode) String ¶ added in v0.26.0
func (n *ColSelectorNode) String() string
String returns a log/debug-friendly representation.
func (*ColSelectorNode) Text ¶ added in v0.26.0
func (n *ColSelectorNode) Text() string
Text implements ResultColumn.
type ExprNode ¶ added in v0.27.0
type ExprNode struct {
// contains filtered or unexported fields
}
ExprNode models a SLQ expression such as ".uid > 4".
func (*ExprNode) Children ¶ added in v0.27.0
func (bn *ExprNode) Children() []Node
Children implements Node.Children.
func (*ExprNode) Parent ¶ added in v0.27.0
func (bn *ExprNode) Parent() Node
Parent implements Node.Parent.
func (*ExprNode) SetChildren ¶ added in v0.27.0
SetChildren implements Node.
func (*ExprNode) SetContext ¶ added in v0.27.0
func (bn *ExprNode) SetContext(ctx antlr.ParseTree) error
type FuncNode ¶ added in v0.27.0
type FuncNode struct {
// contains filtered or unexported fields
}
FuncNode models a function. For example, "COUNT()".
func (*FuncNode) Children ¶ added in v0.27.0
func (bn *FuncNode) Children() []Node
Children implements Node.Children.
func (*FuncNode) Parent ¶ added in v0.27.0
func (bn *FuncNode) Parent() Node
Parent implements Node.Parent.
func (*FuncNode) SetChildren ¶ added in v0.27.0
SetChildren implements Node.
func (*FuncNode) SetContext ¶ added in v0.27.0
func (bn *FuncNode) SetContext(ctx antlr.ParseTree) error
type GroupByNode ¶ added in v0.27.0
type GroupByNode struct {
// contains filtered or unexported fields
}
GroupByNode models GROUP BY. The children of GroupBy node can be of type selector or FuncNode.
func (*GroupByNode) AddChild ¶ added in v0.27.0
func (n *GroupByNode) AddChild(child Node) error
AddChild implements Node.
func (*GroupByNode) Children ¶ added in v0.27.0
func (bn *GroupByNode) Children() []Node
Children implements Node.Children.
func (*GroupByNode) Parent ¶ added in v0.27.0
func (bn *GroupByNode) Parent() Node
Parent implements Node.Parent.
func (*GroupByNode) SetChildren ¶ added in v0.27.0
func (n *GroupByNode) SetChildren(children []Node) error
SetChildren implements ast.Node.
func (*GroupByNode) SetContext ¶ added in v0.27.0
func (bn *GroupByNode) SetContext(ctx antlr.ParseTree) error
func (*GroupByNode) String ¶ added in v0.27.0
func (n *GroupByNode) String() string
String returns a log/debug-friendly representation.
type HandleNode ¶ added in v0.26.0
type HandleNode struct {
// contains filtered or unexported fields
}
HandleNode models a source handle such as "@sakila_sl3".
func (*HandleNode) AddChild ¶ added in v0.26.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*HandleNode) Children ¶ added in v0.26.0
func (bn *HandleNode) Children() []Node
Children implements Node.Children.
func (*HandleNode) Parent ¶ added in v0.26.0
func (bn *HandleNode) Parent() Node
Parent implements Node.Parent.
func (*HandleNode) SetChildren ¶ added in v0.26.0
func (*HandleNode) SetContext ¶ added in v0.26.0
func (bn *HandleNode) SetContext(ctx antlr.ParseTree) error
func (*HandleNode) String ¶ added in v0.26.0
func (d *HandleNode) String() string
type Inspector ¶
type Inspector struct {
// contains filtered or unexported fields
}
Inspector provides functionality for AST interrogation.
func NewInspector ¶
NewInspector returns an Inspector instance for ast.
func (*Inspector) CountNodes ¶
CountNodes counts the number of nodes having typ.
func (*Inspector) FindColExprSegment ¶
func (in *Inspector) FindColExprSegment() (*SegmentNode, error)
FindColExprSegment returns the segment containing col expressions (such as ".uid, .email"). This is typically the last segment. It's also possible that there is no such segment (which usually results in a SELECT * FROM).
func (*Inspector) FindFinalTablerSegment ¶ added in v0.30.0
func (in *Inspector) FindFinalTablerSegment() (*SegmentNode, error)
FindFinalTablerSegment returns the final segment that has at lest one child that implements Tabler.
func (*Inspector) FindGroupByNode ¶ added in v0.28.0
func (in *Inspector) FindGroupByNode() (*GroupByNode, error)
FindGroupByNode returns the GroupByNode, or nil if not found.
func (*Inspector) FindHandles ¶ added in v0.29.0
FindHandles returns all handles mentioned in the AST.
func (*Inspector) FindOrderByNode ¶ added in v0.27.0
func (in *Inspector) FindOrderByNode() (*OrderByNode, error)
FindOrderByNode returns the OrderByNode, or nil if not found.
func (*Inspector) FindTablerSegments ¶ added in v0.30.0
func (in *Inspector) FindTablerSegments() []*SegmentNode
FindTablerSegments returns the segments that have at least one child that implements Tabler.
func (*Inspector) FindUniqueNode ¶ added in v0.30.0
func (in *Inspector) FindUniqueNode() (*UniqueNode, error)
FindUniqueNode returns any UniqueNode, or nil.
func (*Inspector) FindWhereClauses ¶
FindWhereClauses returns all the WHERE clauses in the AST.
type JoinConstraint ¶
type JoinConstraint struct {
// contains filtered or unexported fields
}
JoinConstraint models a join's constraint. For example the elements inside the parentheses in "join(.uid == .user_id)".
func (*JoinConstraint) AddChild ¶
func (n *JoinConstraint) AddChild(child Node) error
func (*JoinConstraint) Children ¶
func (n *JoinConstraint) Children() []Node
func (*JoinConstraint) Context ¶
func (n *JoinConstraint) Context() antlr.ParseTree
func (*JoinConstraint) Parent ¶
func (n *JoinConstraint) Parent() Node
func (*JoinConstraint) SetChildren ¶
func (n *JoinConstraint) SetChildren(children []Node) error
func (*JoinConstraint) SetContext ¶
func (n *JoinConstraint) SetContext(ctx antlr.ParseTree) error
func (*JoinConstraint) SetParent ¶
func (n *JoinConstraint) SetParent(parent Node) error
func (*JoinConstraint) String ¶
func (n *JoinConstraint) String() string
func (*JoinConstraint) Text ¶
func (n *JoinConstraint) Text() string
type JoinNode ¶ added in v0.26.0
type JoinNode struct {
// contains filtered or unexported fields
}
JoinNode models a SQL JOIN node. It has a child of type JoinConstraint.
func (*JoinNode) LeftTbl ¶ added in v0.26.0
func (jn *JoinNode) LeftTbl() *TblSelectorNode
LeftTbl is the selector for the left table of the join.
func (*JoinNode) RightTbl ¶ added in v0.26.0
func (jn *JoinNode) RightTbl() *TblSelectorNode
RightTbl is the selector for the right table of the join.
func (*JoinNode) Segment ¶ added in v0.26.0
func (jn *JoinNode) Segment() *SegmentNode
func (*JoinNode) SetChildren ¶ added in v0.26.0
func (*JoinNode) SetContext ¶ added in v0.26.0
type LiteralNode ¶ added in v0.27.0
type LiteralNode struct {
// contains filtered or unexported fields
}
LiteralNode is a leaf node representing a literal such as a number or a string.
func (*LiteralNode) AddChild ¶ added in v0.27.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*LiteralNode) Children ¶ added in v0.27.0
func (bn *LiteralNode) Children() []Node
Children implements Node.Children.
func (*LiteralNode) LiteralType ¶ added in v0.31.0
func (n *LiteralNode) LiteralType() LiteralType
LiteralType returns the literal type (number, string, etc).
func (*LiteralNode) Parent ¶ added in v0.27.0
func (bn *LiteralNode) Parent() Node
Parent implements Node.Parent.
func (*LiteralNode) SetChildren ¶ added in v0.27.0
func (*LiteralNode) SetContext ¶ added in v0.27.0
func (bn *LiteralNode) SetContext(ctx antlr.ParseTree) error
func (*LiteralNode) String ¶ added in v0.27.0
func (n *LiteralNode) String() string
String returns a log/debug-friendly representation.
type LiteralType ¶ added in v0.31.0
type LiteralType string
LiteralType is an enum of literal types.
const ( LiteralNull LiteralType = "null" LiteralNaturalNumber LiteralType = "int" LiteralAnyNumber LiteralType = "float" LiteralString LiteralType = "string" )
type Node ¶
type Node interface { // Parent returns the node's parent, which may be nil.. Parent() Node // SetParent sets the node's parent, returning an error if illegal. SetParent(n Node) error // Children returns the node's children (which may be empty). Children() []Node // SetChildren sets the node's children, returning an error if illegal. SetChildren(children []Node) error // AddChild adds a child node, returning an error if illegal. AddChild(child Node) error // Context returns the parse tree context. Context() antlr.ParseTree // SetContext sets the parse tree context, returning an error if illegal. SetContext(ctx antlr.ParseTree) error // String returns a debug-friendly string representation. String() string // Text returns the node's text value. This is convenience // method for Node.Context().GetText(). Text() string }
Node is an AST node.
func NodeNextSibling ¶ added in v0.31.0
NodeNextSibling returns the node's next sibling, or nil.
func NodePrevSibling ¶ added in v0.31.0
NodePrevSibling returns the node's previous sibling, or nil.
func NodesHavingText ¶ added in v0.31.0
NodesHavingText returns any node whose node.Text() method returns text.
type OperatorNode ¶ added in v0.27.0
type OperatorNode struct {
// contains filtered or unexported fields
}
OperatorNode is a leaf node in an expression representing an operator such as ">" or "==".
func (*OperatorNode) AddChild ¶ added in v0.27.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*OperatorNode) Children ¶ added in v0.27.0
func (bn *OperatorNode) Children() []Node
Children implements Node.Children.
func (*OperatorNode) Parent ¶ added in v0.27.0
func (bn *OperatorNode) Parent() Node
Parent implements Node.Parent.
func (*OperatorNode) SetChildren ¶ added in v0.27.0
func (*OperatorNode) SetContext ¶ added in v0.27.0
func (bn *OperatorNode) SetContext(ctx antlr.ParseTree) error
func (*OperatorNode) String ¶ added in v0.27.0
func (n *OperatorNode) String() string
String returns a log/debug-friendly representation.
type OrderByDirection ¶ added in v0.27.0
type OrderByDirection string
OrderByDirection specifies the "ORDER BY" direction.
const ( // OrderByDirectionNone is the default order direction. OrderByDirectionNone OrderByDirection = "" // OrderByDirectionAsc is the ascending (DESC) order direction. OrderByDirectionAsc OrderByDirection = "ASC" // OrderByDirectionDesc is the descending (DESC) order direction. OrderByDirectionDesc OrderByDirection = "DESC" )
type OrderByNode ¶ added in v0.27.0
type OrderByNode struct {
// contains filtered or unexported fields
}
OrderByNode implements the SQL "ORDER BY" clause.
func (*OrderByNode) AddChild ¶ added in v0.27.0
func (n *OrderByNode) AddChild(child Node) error
AddChild implements Node.AddChild. It returns an error if child is nil or not type OrderByTermNode.
func (*OrderByNode) Children ¶ added in v0.27.0
func (bn *OrderByNode) Children() []Node
Children implements Node.Children.
func (*OrderByNode) Parent ¶ added in v0.27.0
func (bn *OrderByNode) Parent() Node
Parent implements Node.Parent.
func (*OrderByNode) SetChildren ¶ added in v0.27.0
func (n *OrderByNode) SetChildren(children []Node) error
SetChildren implements ast.Node.
func (*OrderByNode) SetContext ¶ added in v0.27.0
func (bn *OrderByNode) SetContext(ctx antlr.ParseTree) error
func (*OrderByNode) String ¶ added in v0.27.0
func (n *OrderByNode) String() string
String returns a log/debug-friendly representation.
func (*OrderByNode) Terms ¶ added in v0.27.0
func (n *OrderByNode) Terms() []*OrderByTermNode
Terms returns a new slice containing the ordering terms of the OrderByNode. The returned slice has at least one term.
type OrderByTermNode ¶ added in v0.27.0
type OrderByTermNode struct {
// contains filtered or unexported fields
}
OrderByTermNode is a child of OrderByNode.
func (*OrderByTermNode) AddChild ¶ added in v0.27.0
func (n *OrderByTermNode) AddChild(child Node) error
AddChild accepts a single child of type *SelectorNode.
func (*OrderByTermNode) Children ¶ added in v0.27.0
func (bn *OrderByTermNode) Children() []Node
Children implements Node.Children.
func (*OrderByTermNode) Context ¶ added in v0.27.0
func (bn *OrderByTermNode) Context() antlr.ParseTree
func (*OrderByTermNode) Direction ¶ added in v0.27.0
func (n *OrderByTermNode) Direction() OrderByDirection
Direction returns the ordering term's direction.
func (*OrderByTermNode) Parent ¶ added in v0.27.0
func (bn *OrderByTermNode) Parent() Node
Parent implements Node.Parent.
func (*OrderByTermNode) Selector ¶ added in v0.27.0
func (n *OrderByTermNode) Selector() Node
Selector returns the ordering term's selector.
func (*OrderByTermNode) SetChildren ¶ added in v0.27.0
func (n *OrderByTermNode) SetChildren(children []Node) error
SetChildren implements ast.Node.
func (*OrderByTermNode) SetContext ¶ added in v0.27.0
func (bn *OrderByTermNode) SetContext(ctx antlr.ParseTree) error
func (*OrderByTermNode) String ¶ added in v0.27.0
func (n *OrderByTermNode) String() string
String returns a log/debug-friendly representation.
type ResultColumn ¶ added in v0.26.0
type ResultColumn interface { Node // IsColumn returns true if the expression represents // a column, e.g. ".first_name" or "actor.first_name". // This method returns false for functions, e.g. "COUNT(*)". // REVISIT: We can probably get rid of this? IsColumn() bool // String returns a log/debug-friendly representation. String() string // Alias returns the column alias, which may be empty. // For example, given the selector ".first_name:given_name", the // alias is "given_name". Alias() string // Text returns the raw text of the node, e.g. ".actor" or "1*2". Text() string }
ResultColumn indicates a column selection expression Node such as a column name, or context-appropriate function, e.g. "COUNT(*)". See: https://www.sqlite.org/syntax/result-column.html
type RowRangeNode ¶ added in v0.27.0
RowRangeNode models a range, effectively {OFFSET,LIMIT}.
func (*RowRangeNode) AddChild ¶ added in v0.27.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*RowRangeNode) Children ¶ added in v0.27.0
func (bn *RowRangeNode) Children() []Node
Children implements Node.Children.
func (*RowRangeNode) Parent ¶ added in v0.27.0
func (bn *RowRangeNode) Parent() Node
Parent implements Node.Parent.
func (*RowRangeNode) Range ¶ added in v0.27.0
func (rr *RowRangeNode) Range() (offset, limit int)
func (*RowRangeNode) SetChildren ¶ added in v0.27.0
func (*RowRangeNode) SetContext ¶ added in v0.27.0
func (bn *RowRangeNode) SetContext(ctx antlr.ParseTree) error
func (*RowRangeNode) SetParent ¶ added in v0.27.0
func (rr *RowRangeNode) SetParent(parent Node) error
func (*RowRangeNode) String ¶ added in v0.27.0
func (rr *RowRangeNode) String() string
type SegmentNode ¶ added in v0.26.0
type SegmentNode struct {
// contains filtered or unexported fields
}
SegmentNode models a segment of a query (the elements separated by pipes). For example, ".user | .uid, .username" is two segments (".user" and ".uid, .username").
func (*SegmentNode) AddChild ¶ added in v0.26.0
func (s *SegmentNode) AddChild(child Node) error
AddChild implements ast.Node.
func (*SegmentNode) ChildType ¶ added in v0.26.0
func (s *SegmentNode) ChildType() (reflect.Type, error)
ChildType returns the expected Type of the segment's elements, based on the content of the segment's node's children. The type should be something like SelectorNode|FuncNode.
func (*SegmentNode) Children ¶ added in v0.26.0
func (s *SegmentNode) Children() []Node
Children implements ast.Node.
func (*SegmentNode) Context ¶ added in v0.26.0
func (s *SegmentNode) Context() antlr.ParseTree
Context implements ast.Node.
func (*SegmentNode) Next ¶ added in v0.26.0
func (s *SegmentNode) Next() *SegmentNode
Next returns the next segment, or nil if this is the last segment.
func (*SegmentNode) Parent ¶ added in v0.26.0
func (s *SegmentNode) Parent() Node
Parent implements ast.Node.
func (*SegmentNode) Prev ¶ added in v0.26.0
func (s *SegmentNode) Prev() *SegmentNode
Prev returns the previous segment, or nil if this is the first segment.
func (*SegmentNode) SegIndex ¶ added in v0.26.0
func (s *SegmentNode) SegIndex() int
SegIndex returns the index of this segment.
func (*SegmentNode) SetChildren ¶ added in v0.26.0
func (s *SegmentNode) SetChildren(children []Node) error
SetChildren implements ast.Node.
func (*SegmentNode) SetContext ¶ added in v0.26.0
func (s *SegmentNode) SetContext(ctx antlr.ParseTree) error
SetContext implements ast.Node.
func (*SegmentNode) SetParent ¶ added in v0.26.0
func (s *SegmentNode) SetParent(parent Node) error
SetParent implements ast.Node.
func (*SegmentNode) String ¶ added in v0.26.0
func (s *SegmentNode) String() string
func (*SegmentNode) Text ¶ added in v0.26.0
func (s *SegmentNode) Text() string
type Selector ¶
type Selector interface { Node // contains filtered or unexported methods }
Selector is a Node marker interface for selector node types. A selector node models a selector such as ".first_name" or ".actor.last_name".
type SelectorNode ¶ added in v0.26.0
type SelectorNode struct {
// contains filtered or unexported fields
}
SelectorNode is a selector such as ".my_table" or ".my_col". The generic selector will typically be replaced with a more specific selector node such as TblSelectorNode or ColSelectorNode.
func (*SelectorNode) AddChild ¶ added in v0.26.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*SelectorNode) Children ¶ added in v0.26.0
func (bn *SelectorNode) Children() []Node
Children implements Node.Children.
func (*SelectorNode) Parent ¶ added in v0.26.0
func (bn *SelectorNode) Parent() Node
Parent implements Node.Parent.
func (*SelectorNode) SelValue ¶ added in v0.26.0
func (s *SelectorNode) SelValue() (string, error)
SelValue returns the selector value. See extractSelValue.
func (*SelectorNode) SetChildren ¶ added in v0.26.0
func (*SelectorNode) SetContext ¶ added in v0.26.0
func (bn *SelectorNode) SetContext(ctx antlr.ParseTree) error
func (*SelectorNode) String ¶ added in v0.26.0
func (s *SelectorNode) String() string
Strings returns a log/debug-friendly representation.
type Tabler ¶ added in v0.29.0
type Tabler interface { Node // contains filtered or unexported methods }
Tabler is a Node marker interface to indicate that the node can be selected from. That is, the node represents a SQL table, view, or join table, and can be used like "SELECT * FROM [tabler]".
type TblColSelectorNode ¶ added in v0.26.0
type TblColSelectorNode struct { *SelectorNode // contains filtered or unexported fields }
TblColSelectorNode models the TABLE.COLUMN selector, e.g. actor.first_name.
func (TblColSelectorNode) AddChild ¶ added in v0.26.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*TblColSelectorNode) Alias ¶ added in v0.26.0
func (n *TblColSelectorNode) Alias() string
Alias returns the column alias, which may be empty. For example, given the selector ".first_name:given_name", the alias is "given_name".
func (TblColSelectorNode) Children ¶ added in v0.26.0
func (bn TblColSelectorNode) Children() []Node
Children implements Node.Children.
func (*TblColSelectorNode) ColName ¶ added in v0.26.0
func (n *TblColSelectorNode) ColName() string
ColName returns the column name, e.g. first_name.
func (TblColSelectorNode) Context ¶ added in v0.26.0
func (bn TblColSelectorNode) Context() antlr.ParseTree
func (*TblColSelectorNode) IsColumn ¶ added in v0.26.0
func (n *TblColSelectorNode) IsColumn() bool
IsColumn implements ResultColumn.
func (TblColSelectorNode) Parent ¶ added in v0.26.0
func (bn TblColSelectorNode) Parent() Node
Parent implements Node.Parent.
func (TblColSelectorNode) SetChildren ¶ added in v0.26.0
func (TblColSelectorNode) SetContext ¶ added in v0.26.0
func (bn TblColSelectorNode) SetContext(ctx antlr.ParseTree) error
func (*TblColSelectorNode) String ¶ added in v0.26.0
func (n *TblColSelectorNode) String() string
String returns a log/debug-friendly representation.
func (*TblColSelectorNode) TblName ¶ added in v0.26.0
func (n *TblColSelectorNode) TblName() string
TblName returns the table name, e.g. actor.
func (*TblColSelectorNode) Text ¶ added in v0.26.0
func (n *TblColSelectorNode) Text() string
Text implements ResultColumn.
type TblSelectorNode ¶ added in v0.26.0
type TblSelectorNode struct { SelectorNode // contains filtered or unexported fields }
TblSelectorNode is a selector for a table, such as ".my_table" or "@my_src.my_table".
func (*TblSelectorNode) AddChild ¶ added in v0.26.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*TblSelectorNode) Children ¶ added in v0.26.0
func (bn *TblSelectorNode) Children() []Node
Children implements Node.Children.
func (*TblSelectorNode) Context ¶ added in v0.26.0
func (bn *TblSelectorNode) Context() antlr.ParseTree
func (*TblSelectorNode) Handle ¶ added in v0.26.0
func (s *TblSelectorNode) Handle() string
Handle returns the handle, which may be empty.
func (*TblSelectorNode) Parent ¶ added in v0.26.0
func (bn *TblSelectorNode) Parent() Node
Parent implements Node.Parent.
func (*TblSelectorNode) SelValue ¶ added in v0.26.0
func (s *TblSelectorNode) SelValue() (string, error)
SelValue returns the table name. TODO: Can we get rid of this method SelValue?
func (*TblSelectorNode) SetChildren ¶ added in v0.26.0
func (*TblSelectorNode) SetContext ¶ added in v0.26.0
func (bn *TblSelectorNode) SetContext(ctx antlr.ParseTree) error
func (*TblSelectorNode) String ¶ added in v0.26.0
func (s *TblSelectorNode) String() string
String returns a log/debug-friendly representation.
func (*TblSelectorNode) TblName ¶ added in v0.26.0
func (s *TblSelectorNode) TblName() string
TblName returns the table name. This is the raw value without punctuation.
type UniqueNode ¶ added in v0.30.0
type UniqueNode struct {
// contains filtered or unexported fields
}
UniqueNode implements the SQL "DISTINCT" clause.
func (*UniqueNode) AddChild ¶ added in v0.30.0
AddChild always returns an error. Node implementations should implement a type-specific method that only accepts a child of an appropriate type for that node.
func (*UniqueNode) Children ¶ added in v0.30.0
func (bn *UniqueNode) Children() []Node
Children implements Node.Children.
func (*UniqueNode) Parent ¶ added in v0.30.0
func (bn *UniqueNode) Parent() Node
Parent implements Node.Parent.
func (*UniqueNode) SetChildren ¶ added in v0.30.0
func (*UniqueNode) SetContext ¶ added in v0.30.0
func (bn *UniqueNode) SetContext(ctx antlr.ParseTree) error
func (*UniqueNode) String ¶ added in v0.30.0
func (n *UniqueNode) String() string
String returns a log/debug-friendly representation.
type Walker ¶
type Walker struct {
// contains filtered or unexported fields
}
Walker traverses a node tree (the AST, or a subset thereof).
func (*Walker) AddVisitor ¶
AddVisitor adds a visitor function for any node that is assignable to typ.
type WhereNode ¶ added in v0.27.0
type WhereNode struct {
// contains filtered or unexported fields
}
WhereNode represents a SQL WHERE clause, i.e. a filter on the SELECT.
func (*WhereNode) Children ¶ added in v0.27.0
func (bn *WhereNode) Children() []Node
Children implements Node.Children.
func (*WhereNode) Expr ¶ added in v0.27.0
Expr returns the expression that constitutes the SetWhere clause, or nil if no expression.
func (*WhereNode) Parent ¶ added in v0.27.0
func (bn *WhereNode) Parent() Node
Parent implements Node.Parent.
func (*WhereNode) SetChildren ¶ added in v0.27.0
func (*WhereNode) SetContext ¶ added in v0.27.0
func (bn *WhereNode) SetContext(ctx antlr.ParseTree) error