Documentation ¶
Overview ¶
Package ast holds types and functionality for the SLQ AST.
The entrypoint is ast.Parse, which accepts a SLQ query, and returns an *ast.AST. The ast is a tree of ast.Node instances.
Note that much of the testing of package ast is performed in package libsq.
Index ¶
- func NodeUnwrap[T Node](node Node) (T, bool)
- type AST
- func (a *AST) AddChild(node Node) error
- func (a *AST) AddSegment(seg *SegmentNode)
- func (a *AST) Children() []Node
- func (a *AST) Parent() Node
- func (a *AST) Segments() []*SegmentNode
- func (a *AST) SetChildren(children []Node) 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 (n *ArgNode) Key() string
- func (bn *ArgNode) Parent() Node
- func (bn *ArgNode) SetChildren(children []Node) error
- func (bn *ArgNode) SetParent(parent Node) error
- func (n *ArgNode) String() string
- func (bn *ArgNode) 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 (n *ColSelectorNode) IsColumn() bool
- func (bn ColSelectorNode) Parent() Node
- func (bn ColSelectorNode) SetChildren(children []Node) error
- func (bn ColSelectorNode) SetParent(parent Node) error
- func (n *ColSelectorNode) String() string
- func (n *ColSelectorNode) Text() string
- type ExprElementNode
- func (ex *ExprElementNode) AddChild(child Node) error
- func (ex *ExprElementNode) Alias() string
- func (bn *ExprElementNode) Children() []Node
- func (ex *ExprElementNode) ExprNode() *ExprNode
- func (bn *ExprElementNode) Parent() Node
- func (ex *ExprElementNode) SetChildren(children []Node) error
- func (bn *ExprElementNode) SetParent(parent Node) error
- func (ex *ExprElementNode) String() string
- func (ex *ExprElementNode) Text() string
- type ExprNode
- func (n *ExprNode) AddChild(child Node) error
- func (bn *ExprNode) Children() []Node
- func (n *ExprNode) HasParens() bool
- func (bn *ExprNode) Parent() Node
- func (n *ExprNode) SetChildren(children []Node) 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 (fn *FuncNode) FuncName() string
- func (fn *FuncNode) IsProprietary() bool
- func (bn *FuncNode) Parent() Node
- func (fn *FuncNode) SetChildren(children []Node) 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) Parent() Node
- func (n *GroupByNode) SetChildren(children []Node) 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 (d *HandleNode) Handle() string
- func (bn *HandleNode) Parent() Node
- func (bn *HandleNode) SetChildren(children []Node) 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) FindFinalTableSegment() (*SegmentNode, error)
- func (in *Inspector) FindFirstHandle() (handle string)
- func (in *Inspector) FindFirstTableSelector() *TblSelectorNode
- func (in *Inspector) FindGroupByNode() (*GroupByNode, error)
- func (in *Inspector) FindHandles() []string
- func (in *Inspector) FindJoins() ([]*JoinNode, error)
- func (in *Inspector) FindNodes(typ reflect.Type) []Node
- func (in *Inspector) FindOrderByNode() (*OrderByNode, error)
- func (in *Inspector) FindRowRangeNode() (*RowRangeNode, error)
- func (in *Inspector) FindTableSegments() []*SegmentNode
- func (in *Inspector) FindUniqueNode() (*UniqueNode, error)
- func (in *Inspector) FindWhereClauses() ([]*WhereNode, error)
- type JoinNode
- func (n *JoinNode) AddChild(node Node) error
- func (n *JoinNode) Children() []Node
- func (n *JoinNode) JoinType() jointype.Type
- func (n *JoinNode) Parent() Node
- func (n *JoinNode) Predicate() *ExprNode
- func (n *JoinNode) Segment() *SegmentNode
- func (n *JoinNode) SetChildren(children []Node) error
- func (n *JoinNode) SetParent(parent Node) error
- func (n *JoinNode) String() string
- func (n *JoinNode) Table() *TblSelectorNode
- func (n *JoinNode) Text() string
- type LiteralNode
- func (bn *LiteralNode) AddChild(child Node) error
- func (bn *LiteralNode) Children() []Node
- func (n *LiteralNode) LiteralType() LiteralType
- func (bn *LiteralNode) Parent() Node
- func (bn *LiteralNode) SetChildren(children []Node) 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) Parent() Node
- func (bn *OperatorNode) SetChildren(children []Node) 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) Parent() Node
- func (n *OrderByNode) SetChildren(children []Node) 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 (n *OrderByTermNode) Direction() OrderByDirection
- func (bn *OrderByTermNode) Parent() Node
- func (n *OrderByTermNode) Selector() Node
- func (n *OrderByTermNode) SetChildren(children []Node) 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) Parent() Node
- func (rr *RowRangeNode) Range() (offset, limit int)
- func (bn *RowRangeNode) SetChildren(children []Node) 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) 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) 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) Parent() Node
- func (s *SelectorNode) SelValue() (string, error)
- func (bn *SelectorNode) SetChildren(children []Node) error
- func (bn *SelectorNode) SetParent(parent Node) error
- func (s *SelectorNode) String() string
- func (bn *SelectorNode) Text() string
- 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 (n *TblColSelectorNode) IsColumn() bool
- func (bn TblColSelectorNode) Parent() Node
- func (bn TblColSelectorNode) SetChildren(children []Node) 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 (n *TblSelectorNode) Alias() string
- func (bn *TblSelectorNode) Children() []Node
- func (n *TblSelectorNode) Handle() string
- func (bn *TblSelectorNode) Parent() Node
- func (n *TblSelectorNode) SelValue() (string, error)
- func (bn *TblSelectorNode) SetChildren(children []Node) error
- func (n *TblSelectorNode) SetHandle(h string)
- func (bn *TblSelectorNode) SetParent(parent Node) error
- func (n *TblSelectorNode) String() string
- func (n *TblSelectorNode) SyncTblNameAlias()
- func (n *TblSelectorNode) TblAliasOrName() string
- func (n *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) Parent() Node
- func (bn *UniqueNode) SetChildren(children []Node) 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 (n *WhereNode) Expr() *ExprNode
- func (bn *WhereNode) Parent() Node
- func (bn *WhereNode) SetChildren(children []Node) 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 ¶
func NodeUnwrap ¶ added in v0.38.0
NodeUnwrap "unwraps" node returning the lowest single contained node. False is returned if node (or any of its descendants), has more than one child. If node has no children, it is returned directly. This function is useful for "unwrapping" a node that is contained in an outer node. For example, an ExprNode may often contain just a single LiteralNode.
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
Segments returns the AST's segments (its direct children).
func (*AST) SetChildren ¶
SetChildren implements ast.Node.
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
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) 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) 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 ExprElementNode ¶ added in v0.38.0
type ExprElementNode struct {
// contains filtered or unexported fields
}
ExprElementNode is an expression that acts as a ResultColumn.
.actor | (1+2):alias
In the example above, the expression "(1+2)" is rendered with an alias, e.g.
SELECT 1+2 AS "alias" FROM "actor"
func (*ExprElementNode) AddChild ¶ added in v0.38.0
func (ex *ExprElementNode) AddChild(child Node) error
AddChild implements Node.
func (*ExprElementNode) Alias ¶ added in v0.38.0
func (ex *ExprElementNode) Alias() string
Alias implements ResultColumn.
func (*ExprElementNode) Children ¶ added in v0.38.0
func (bn *ExprElementNode) Children() []Node
Children implements Node.Children.
func (*ExprElementNode) ExprNode ¶ added in v0.38.0
func (ex *ExprElementNode) ExprNode() *ExprNode
ExprNode returns the child expression.
func (*ExprElementNode) Parent ¶ added in v0.38.0
func (bn *ExprElementNode) Parent() Node
Parent implements Node.Parent.
func (*ExprElementNode) SetChildren ¶ added in v0.38.0
func (ex *ExprElementNode) SetChildren(children []Node) error
SetChildren implements Node.
func (*ExprElementNode) String ¶ added in v0.38.0
func (ex *ExprElementNode) String() string
String returns a log/debug-friendly representation.
func (*ExprElementNode) Text ¶ added in v0.38.0
func (ex *ExprElementNode) 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) HasParens ¶ added in v0.38.0
HasParens returns true if the expression is enclosed in parentheses.
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.
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) IsProprietary ¶ added in v0.36.2
IsProprietary returns true if this is a DB-proprietary function, as opposed to a portable function. For example, SQLite has a "strftime" function. In the SLQ, this is referenced as "_strftime": SLQ uses the underscore to indicate a proprietary function.
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.
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) 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".
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) Handle ¶ added in v0.38.0
func (d *HandleNode) Handle() string
Handle returns the handle value, e.g. "@sakila".
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) String ¶ added in v0.26.0
func (d *HandleNode) String() string
String returns a log/debug-friendly representation.
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) FindFinalTableSegment ¶ added in v0.40.0
func (in *Inspector) FindFinalTableSegment() (*SegmentNode, error)
FindFinalTableSegment returns the final segment that has at least one child that is an ast.TblSelectorNode.
func (*Inspector) FindFirstHandle ¶ added in v0.38.0
FindFirstHandle returns the first handle mentioned in the query, or returns empty string.
func (*Inspector) FindFirstTableSelector ¶ added in v0.40.0
func (in *Inspector) FindFirstTableSelector() *TblSelectorNode
FindFirstTableSelector returns the first top-level (child of a segment) table selector node.
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) FindRowRangeNode ¶ added in v0.38.0
func (in *Inspector) FindRowRangeNode() (*RowRangeNode, error)
FindRowRangeNode returns the single RowRangeNode, or nil. An error can be returned if the AST is in an illegal state.
func (*Inspector) FindTableSegments ¶ added in v0.40.0
func (in *Inspector) FindTableSegments() []*SegmentNode
FindTableSegments returns the segments that have at least one child that is a ast.TblSelectorNode.
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 JoinNode ¶ added in v0.26.0
type JoinNode struct {
// contains filtered or unexported fields
}
JoinNode models a SQL JOIN node.
func (*JoinNode) Predicate ¶ added in v0.40.0
Predicate returns the join predicate, which may be nil.
func (*JoinNode) Segment ¶ added in v0.26.0
func (n *JoinNode) Segment() *SegmentNode
func (*JoinNode) SetChildren ¶ added in v0.26.0
SetChildren implements ast.Node.
func (*JoinNode) Table ¶ added in v0.40.0
func (n *JoinNode) Table() *TblSelectorNode
Table is the selector for join's target table.
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) 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 // Text returns the node's raw text value. Text() string // String returns a debug-friendly string representation. String() string // contains filtered or unexported methods }
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) 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) 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) 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) 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 // 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 // contains filtered or unexported methods }
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)
Range returns the offset and limit.
func (*RowRangeNode) SetChildren ¶ added in v0.27.0
func (*RowRangeNode) SetParent ¶ added in v0.27.0
func (rr *RowRangeNode) SetParent(parent Node) error
SetParent implements ast.Node.
func (*RowRangeNode) String ¶ added in v0.27.0
func (rr *RowRangeNode) String() string
String implements ast.Node.
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) 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) 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
String returns a log/debug-friendly representation.
func (*SegmentNode) Text ¶ added in v0.26.0
func (s *SegmentNode) Text() string
Text implements ast.Node.
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) String ¶ added in v0.26.0
func (s *SelectorNode) String() string
Strings returns a log/debug-friendly representation.
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) 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) 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) Alias ¶ added in v0.40.0
func (n *TblSelectorNode) Alias() string
Alias returns the node's alias, or empty string.
func (*TblSelectorNode) Children ¶ added in v0.26.0
func (bn *TblSelectorNode) Children() []Node
Children implements Node.Children.
func (*TblSelectorNode) Handle ¶ added in v0.26.0
func (n *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 (n *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) SetHandle ¶ added in v0.40.0
func (n *TblSelectorNode) SetHandle(h string)
SetHandle sets the handle.
func (*TblSelectorNode) String ¶ added in v0.26.0
func (n *TblSelectorNode) String() string
String returns a log/debug-friendly representation.
func (*TblSelectorNode) SyncTblNameAlias ¶ added in v0.40.0
func (n *TblSelectorNode) SyncTblNameAlias()
SyncTblNameAlias sets the table name to the alias value, if the alias is non-empty, and then sets the alias to empty.
func (*TblSelectorNode) TblAliasOrName ¶ added in v0.40.0
func (n *TblSelectorNode) TblAliasOrName() string
TblAliasOrName returns the table alias if set; if not, it returns the table name.
func (*TblSelectorNode) TblName ¶ added in v0.26.0
func (n *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) 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.