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 *Segment)
- func (a *AST) Children() []Node
- func (a *AST) Context() antlr.ParseTree
- func (a *AST) Parent() Node
- func (a *AST) Segments() []*Segment
- 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 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 ColExpr
- type ColSelector
- func (bn *ColSelector) AddChild(child Node) error
- func (bn *ColSelector) Children() []Node
- func (s *ColSelector) ColExpr() (string, error)
- func (bn *ColSelector) Context() antlr.ParseTree
- func (s *ColSelector) IsColName() bool
- func (bn *ColSelector) Parent() Node
- func (bn *ColSelector) SetChildren(children []Node) error
- func (bn *ColSelector) SetContext(ctx antlr.ParseTree) error
- func (bn *ColSelector) SetParent(parent Node) error
- func (s *ColSelector) String() string
- func (bn *ColSelector) Text() string
- type Datasource
- func (bn *Datasource) AddChild(child Node) error
- func (bn *Datasource) Children() []Node
- func (bn *Datasource) Context() antlr.ParseTree
- func (bn *Datasource) Parent() Node
- func (bn *Datasource) SetChildren(children []Node) error
- func (bn *Datasource) SetContext(ctx antlr.ParseTree) error
- func (bn *Datasource) SetParent(parent Node) error
- func (d *Datasource) String() string
- func (bn *Datasource) Text() string
- type Expr
- func (e *Expr) AddChild(child Node) error
- func (bn *Expr) Children() []Node
- func (bn *Expr) Context() antlr.ParseTree
- func (bn *Expr) Parent() Node
- func (bn *Expr) SetChildren(children []Node) error
- func (bn *Expr) SetContext(ctx antlr.ParseTree) error
- func (bn *Expr) SetParent(parent Node) error
- func (e *Expr) String() string
- func (bn *Expr) Text() string
- type Func
- func (fn *Func) AddChild(child Node) error
- func (bn *Func) Children() []Node
- func (fn *Func) ColExpr() (string, error)
- func (bn *Func) Context() antlr.ParseTree
- func (fn *Func) FuncName() string
- func (fn *Func) IsColName() bool
- func (bn *Func) Parent() Node
- func (fn *Func) SetChildren(children []Node) error
- func (bn *Func) SetContext(ctx antlr.ParseTree) error
- func (bn *Func) SetParent(parent Node) error
- func (fn *Func) String() string
- func (bn *Func) Text() string
- type Group
- func (g *Group) AddChild(child Node) error
- func (bn *Group) Children() []Node
- func (bn *Group) Context() antlr.ParseTree
- func (bn *Group) Parent() Node
- func (bn *Group) SetChildren(children []Node) error
- func (bn *Group) SetContext(ctx antlr.ParseTree) error
- func (bn *Group) SetParent(parent Node) error
- func (g *Group) String() string
- func (bn *Group) Text() string
- type Inspector
- func (in *Inspector) CountNodes(typ reflect.Type) int
- func (in *Inspector) FindColExprSegment() (*Segment, error)
- func (in *Inspector) FindFinalSelectableSegment() (*Segment, error)
- func (in *Inspector) FindNodes(typ reflect.Type) []Node
- func (in *Inspector) FindSelectableSegments() []*Segment
- func (in *Inspector) FindWhereClauses() ([]*Where, error)
- type Join
- func (jn *Join) AddChild(node Node) error
- func (jn *Join) Children() []Node
- func (jn *Join) Context() antlr.ParseTree
- func (jn *Join) LeftTbl() *TblSelector
- func (jn *Join) Parent() Node
- func (jn *Join) RightTbl() *TblSelector
- func (jn *Join) Segment() *Segment
- func (jn *Join) Selectable()
- func (jn *Join) SetChildren(children []Node) error
- func (jn *Join) SetContext(ctx antlr.ParseTree) error
- func (jn *Join) SetParent(parent Node) error
- func (jn *Join) String() string
- func (jn *Join) Text() string
- type JoinConstraint
- func (jc *JoinConstraint) AddChild(child Node) error
- func (jc *JoinConstraint) Children() []Node
- func (jc *JoinConstraint) Context() antlr.ParseTree
- func (jc *JoinConstraint) Parent() Node
- func (jc *JoinConstraint) SetChildren(children []Node) error
- func (jc *JoinConstraint) SetContext(ctx antlr.ParseTree) error
- func (jc *JoinConstraint) SetParent(parent Node) error
- func (jc *JoinConstraint) String() string
- func (jc *JoinConstraint) Text() string
- type Literal
- func (bn *Literal) AddChild(child Node) error
- func (bn *Literal) Children() []Node
- func (bn *Literal) Context() antlr.ParseTree
- func (bn *Literal) Parent() Node
- func (bn *Literal) SetChildren(children []Node) error
- func (bn *Literal) SetContext(ctx antlr.ParseTree) error
- func (bn *Literal) SetParent(parent Node) error
- func (li *Literal) String() string
- func (bn *Literal) Text() string
- type Node
- type Operator
- func (bn *Operator) AddChild(child Node) error
- func (bn *Operator) Children() []Node
- func (bn *Operator) Context() antlr.ParseTree
- func (bn *Operator) Parent() Node
- func (bn *Operator) SetChildren(children []Node) error
- func (bn *Operator) SetContext(ctx antlr.ParseTree) error
- func (bn *Operator) SetParent(parent Node) error
- func (o *Operator) String() string
- func (bn *Operator) Text() string
- type RowRange
- func (bn *RowRange) AddChild(child Node) error
- func (bn *RowRange) Children() []Node
- func (bn *RowRange) Context() antlr.ParseTree
- func (bn *RowRange) Parent() Node
- func (rr *RowRange) Range() (offset, limit int)
- func (bn *RowRange) SetChildren(children []Node) error
- func (bn *RowRange) SetContext(ctx antlr.ParseTree) error
- func (rr *RowRange) SetParent(parent Node) error
- func (rr *RowRange) String() string
- func (bn *RowRange) Text() string
- type Segment
- func (s *Segment) AddChild(child Node) error
- func (s *Segment) ChildType() (reflect.Type, error)
- func (s *Segment) Children() []Node
- func (s *Segment) Context() antlr.ParseTree
- func (s *Segment) Next() *Segment
- func (s *Segment) Parent() Node
- func (s *Segment) Prev() *Segment
- func (s *Segment) SegIndex() int
- func (s *Segment) SetChildren(children []Node) error
- func (s *Segment) SetContext(ctx antlr.ParseTree) error
- func (s *Segment) SetParent(parent Node) error
- func (s *Segment) String() string
- func (s *Segment) Text() string
- type Selectable
- type Selector
- func (bn *Selector) AddChild(child Node) error
- func (bn *Selector) Children() []Node
- func (bn *Selector) Context() antlr.ParseTree
- func (bn *Selector) Parent() Node
- func (s *Selector) SelValue() string
- func (bn *Selector) SetChildren(children []Node) error
- func (bn *Selector) SetContext(ctx antlr.ParseTree) error
- func (bn *Selector) SetParent(parent Node) error
- func (s *Selector) String() string
- func (bn *Selector) Text() string
- type TblSelector
- func (bn *TblSelector) AddChild(child Node) error
- func (bn *TblSelector) Children() []Node
- func (bn *TblSelector) Context() antlr.ParseTree
- func (bn *TblSelector) Parent() Node
- func (s *TblSelector) SelValue() string
- func (s *TblSelector) Selectable()
- func (bn *TblSelector) SetChildren(children []Node) error
- func (bn *TblSelector) SetContext(ctx antlr.ParseTree) error
- func (bn *TblSelector) SetParent(parent Node) error
- func (s *TblSelector) String() string
- func (bn *TblSelector) Text() string
- type Terminal
- func (bn *Terminal) AddChild(child Node) error
- func (bn *Terminal) Children() []Node
- func (bn *Terminal) Context() antlr.ParseTree
- func (bn *Terminal) Parent() Node
- func (bn *Terminal) SetChildren(children []Node) error
- func (bn *Terminal) SetContext(ctx antlr.ParseTree) error
- func (bn *Terminal) SetParent(parent Node) error
- func (t *Terminal) String() string
- func (bn *Terminal) Text() string
- type Walker
- type Where
- func (w *Where) AddChild(node Node) error
- func (bn *Where) Children() []Node
- func (bn *Where) Context() antlr.ParseTree
- func (w *Where) Expr() *Expr
- func (bn *Where) Parent() Node
- func (bn *Where) SetChildren(children []Node) error
- func (bn *Where) SetContext(ctx antlr.ParseTree) error
- func (bn *Where) SetParent(parent Node) error
- func (w *Where) String() string
- func (bn *Where) 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) SetChildren ¶
type Cmpr ¶
type Cmpr struct {
// contains filtered or unexported fields
}
Cmpr models a comparison.
func (*Cmpr) SetChildren ¶
func (*Cmpr) SetContext ¶
type ColExpr ¶
type ColExpr interface { // IsColName returns true if the expr is a column name, e.g. "uid" or "users.uid". IsColName() bool ColExpr() (string, error) String() string }
ColExpr indicates a column selection expression such as a column name, or context-appropriate function (e.g. "COUNT(*)")
type ColSelector ¶
type ColSelector struct {
Selector
}
ColSelector models a column selector such as ".user_id".
func (*ColSelector) ColExpr ¶
func (s *ColSelector) ColExpr() (string, error)
ColExpr returns the column name.
func (*ColSelector) IsColName ¶
func (s *ColSelector) IsColName() bool
func (*ColSelector) SetChildren ¶
func (*ColSelector) SetContext ¶
func (*ColSelector) String ¶
func (s *ColSelector) String() string
type Datasource ¶
type Datasource struct {
// contains filtered or unexported fields
}
Datasource models a source such as "@sakila_sl3".
func (*Datasource) SetChildren ¶
func (*Datasource) SetContext ¶
func (*Datasource) String ¶
func (d *Datasource) String() string
type Expr ¶
type Expr struct {
// contains filtered or unexported fields
}
Expr models a SLQ expression such as ".uid > 4".
func (*Expr) SetChildren ¶
func (*Expr) SetContext ¶
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func models a function. For example, "COUNT()".
func (*Func) SetChildren ¶
SetChildren implements Node.
func (*Func) SetContext ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group models GROUP BY.
func (*Group) SetChildren ¶
func (*Group) SetContext ¶
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 ¶
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) FindFinalSelectableSegment ¶
FindFinalSelectableSegment returns the final segment that has at lest one child that implements Selectable.
func (*Inspector) FindSelectableSegments ¶
FindSelectableSegments returns the segments that have at least one child that implements Selectable.
func (*Inspector) FindWhereClauses ¶
FindWhereClauses returns all the WHERE clauses in the AST.
type Join ¶
type Join struct {
// contains filtered or unexported fields
}
Join models a SQL JOIN node. It has a child of type JoinConstraint.
func (*Join) LeftTbl ¶
func (jn *Join) LeftTbl() *TblSelector
LeftTbl is the selector for the left table of the join.
func (*Join) RightTbl ¶
func (jn *Join) RightTbl() *TblSelector
RightTbl is the selector for the right table of the join.
func (*Join) Selectable ¶
func (jn *Join) Selectable()
Selectable implements the Selectable marker interface.
func (*Join) SetChildren ¶
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 (jc *JoinConstraint) AddChild(child Node) error
func (*JoinConstraint) Children ¶
func (jc *JoinConstraint) Children() []Node
func (*JoinConstraint) Context ¶
func (jc *JoinConstraint) Context() antlr.ParseTree
func (*JoinConstraint) Parent ¶
func (jc *JoinConstraint) Parent() Node
func (*JoinConstraint) SetChildren ¶
func (jc *JoinConstraint) SetChildren(children []Node) error
func (*JoinConstraint) SetContext ¶
func (jc *JoinConstraint) SetContext(ctx antlr.ParseTree) error
func (*JoinConstraint) SetParent ¶
func (jc *JoinConstraint) SetParent(parent Node) error
func (*JoinConstraint) String ¶
func (jc *JoinConstraint) String() string
func (*JoinConstraint) Text ¶
func (jc *JoinConstraint) Text() string
type Literal ¶
type Literal struct {
// contains filtered or unexported fields
}
Literal is a leaf node representing a literal such as a number or a string.
func (*Literal) SetChildren ¶
func (*Literal) SetContext ¶
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 (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 representation. Text() string }
Node is an AST node.
type Operator ¶
type Operator struct {
// contains filtered or unexported fields
}
Operator is a leaf node in an expression representing an operator such as ">" or "==".
func (*Operator) SetChildren ¶
func (*Operator) SetContext ¶
type RowRange ¶
RowRange models a range, effectively {OFFSET,LIMIT}.
func (*RowRange) SetChildren ¶
func (*RowRange) SetContext ¶
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
Segment models a segment of a query (the elements separated by pipes). For example, ".user | .uid, .username" is two segments (".user" and ".uid, .username").
func (*Segment) ChildType ¶
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 Selector|Func
func (*Segment) SetChildren ¶
SetChildren implements ast.Node.
func (*Segment) SetContext ¶
SetContext implements ast.Node.
type Selectable ¶
type Selectable interface {
Selectable()
}
Selectable is a 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 [selectable]".
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector 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 TblSelector or ColSelector.
func (*Selector) SetChildren ¶
func (*Selector) SetContext ¶
type TblSelector ¶
TblSelector is a selector for a table, such as ".my_table" or "@my_src.my_table".
func (*TblSelector) SelValue ¶
func (s *TblSelector) SelValue() string
func (*TblSelector) Selectable ¶
func (s *TblSelector) Selectable()
Selectable implements the Selectable marker interface.
func (*TblSelector) SetChildren ¶
func (*TblSelector) SetContext ¶
func (*TblSelector) String ¶
func (s *TblSelector) String() string
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is a terminal/leaf node that typically is interpreted simply as its text value.
func (*Terminal) SetChildren ¶
func (*Terminal) SetContext ¶
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 the specified node type (and returns the receiver Walker, to enabled chaining).
type Where ¶
type Where struct {
// contains filtered or unexported fields
}
Where represents a SQL WHERE clause, i.e. a filter on the SELECT.
func (*Where) Expr ¶
Expr returns the expression that constitutes the SetWhere clause, or nil if no expression.
func (*Where) SetChildren ¶
func (*Where) SetContext ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
Package sqlbuilder contains functionality for building SQL from the AST.
|
Package sqlbuilder contains functionality for building SQL from the AST. |