ast

package
v0.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2023 License: MIT Imports: 12 Imported by: 0

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

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 Parse

func Parse(log *slog.Logger, input string) (*AST, error)

Parse parses the SLQ input string and builds the AST.

func (*AST) AddChild

func (a *AST) AddChild(node Node) error

func (*AST) AddSegment

func (a *AST) AddSegment(seg *SegmentNode)

AddSegment appends seg to the AST.

func (*AST) Children

func (a *AST) Children() []Node

func (*AST) Context

func (a *AST) Context() antlr.ParseTree

func (*AST) Parent

func (a *AST) Parent() Node

func (*AST) Segments

func (a *AST) Segments() []*SegmentNode

func (*AST) SetChildren

func (a *AST) SetChildren(children []Node) error

func (*AST) SetContext

func (a *AST) SetContext(ctx antlr.ParseTree) error

func (*AST) SetParent

func (a *AST) SetParent(parent Node) error

func (*AST) String

func (a *AST) String() string

func (*AST) Text

func (a *AST) Text() string

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

func (bn *ArgNode) AddChild(child Node) error

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) Context added in v0.31.0

func (bn *ArgNode) Context() antlr.ParseTree

func (*ArgNode) Key added in v0.31.0

func (n *ArgNode) Key() string

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 (bn *ArgNode) SetChildren(children []Node) error

func (*ArgNode) SetContext added in v0.31.0

func (bn *ArgNode) SetContext(ctx antlr.ParseTree) error

func (*ArgNode) SetParent added in v0.31.0

func (bn *ArgNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*ArgNode) String added in v0.31.0

func (n *ArgNode) String() string

String returns a log/debug-friendly representation.

func (*ArgNode) Text added in v0.31.0

func (bn *ArgNode) Text() string

type Cmpr

type Cmpr struct {
	// contains filtered or unexported fields
}

Cmpr models a comparison, such as ".age == 42".

func (*Cmpr) AddChild

func (bn *Cmpr) AddChild(child Node) error

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) Children

func (bn *Cmpr) Children() []Node

Children implements Node.Children.

func (*Cmpr) Context

func (bn *Cmpr) Context() antlr.ParseTree

func (*Cmpr) Parent

func (bn *Cmpr) Parent() Node

Parent implements Node.Parent.

func (*Cmpr) SetChildren

func (bn *Cmpr) SetChildren(children []Node) error

func (*Cmpr) SetContext

func (bn *Cmpr) SetContext(ctx antlr.ParseTree) error

func (*Cmpr) SetParent

func (bn *Cmpr) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*Cmpr) String

func (c *Cmpr) String() string

func (*Cmpr) Text

func (bn *Cmpr) Text() string

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

func (bn ColSelectorNode) AddChild(child Node) error

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 (bn ColSelectorNode) SetChildren(children []Node) error

func (ColSelectorNode) SetContext added in v0.26.0

func (bn ColSelectorNode) SetContext(ctx antlr.ParseTree) error

func (ColSelectorNode) SetParent added in v0.26.0

func (bn ColSelectorNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

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) AddChild added in v0.27.0

func (n *ExprNode) AddChild(child Node) error

AddChild implements Node.

func (*ExprNode) Children added in v0.27.0

func (bn *ExprNode) Children() []Node

Children implements Node.Children.

func (*ExprNode) Context added in v0.27.0

func (bn *ExprNode) Context() antlr.ParseTree

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

func (n *ExprNode) SetChildren(children []Node) error

SetChildren implements Node.

func (*ExprNode) SetContext added in v0.27.0

func (bn *ExprNode) SetContext(ctx antlr.ParseTree) error

func (*ExprNode) SetParent added in v0.27.0

func (bn *ExprNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*ExprNode) String added in v0.27.0

func (n *ExprNode) String() string

String returns a log/debug-friendly representation.

func (*ExprNode) Text added in v0.27.0

func (bn *ExprNode) Text() string

type FuncNode added in v0.27.0

type FuncNode struct {
	// contains filtered or unexported fields
}

FuncNode models a function. For example, "COUNT()".

func (*FuncNode) AddChild added in v0.27.0

func (fn *FuncNode) AddChild(child Node) error

AddChild implements Node.

func (*FuncNode) Alias added in v0.27.0

func (fn *FuncNode) Alias() string

Alias implements ResultColumn.

func (*FuncNode) Children added in v0.27.0

func (bn *FuncNode) Children() []Node

Children implements Node.Children.

func (*FuncNode) Context added in v0.27.0

func (bn *FuncNode) Context() antlr.ParseTree

func (*FuncNode) FuncName added in v0.27.0

func (fn *FuncNode) FuncName() string

FuncName returns the function name.

func (*FuncNode) IsColumn added in v0.27.0

func (fn *FuncNode) IsColumn() bool

IsColumn implements ResultColumn.

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

func (fn *FuncNode) SetChildren(children []Node) error

SetChildren implements Node.

func (*FuncNode) SetContext added in v0.27.0

func (bn *FuncNode) SetContext(ctx antlr.ParseTree) error

func (*FuncNode) SetParent added in v0.27.0

func (bn *FuncNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*FuncNode) String added in v0.27.0

func (fn *FuncNode) String() string

String returns a log/debug-friendly representation.

func (*FuncNode) Text added in v0.27.0

func (fn *FuncNode) Text() string

Text implements ResultColumn.

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) Context added in v0.27.0

func (bn *GroupByNode) Context() antlr.ParseTree

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) SetParent added in v0.27.0

func (bn *GroupByNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*GroupByNode) String added in v0.27.0

func (n *GroupByNode) String() string

String returns a log/debug-friendly representation.

func (*GroupByNode) Text added in v0.27.0

func (bn *GroupByNode) Text() string

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

func (bn *HandleNode) AddChild(child Node) error

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) Context added in v0.26.0

func (bn *HandleNode) Context() antlr.ParseTree

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 (bn *HandleNode) SetChildren(children []Node) error

func (*HandleNode) SetContext added in v0.26.0

func (bn *HandleNode) SetContext(ctx antlr.ParseTree) error

func (*HandleNode) SetParent added in v0.26.0

func (bn *HandleNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*HandleNode) String added in v0.26.0

func (d *HandleNode) String() string

func (*HandleNode) Text added in v0.26.0

func (bn *HandleNode) Text() string

type Inspector

type Inspector struct {
	// contains filtered or unexported fields
}

Inspector provides functionality for AST interrogation.

func NewInspector

func NewInspector(ast *AST) *Inspector

NewInspector returns an Inspector instance for ast.

func (*Inspector) CountNodes

func (in *Inspector) CountNodes(typ reflect.Type) int

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

func (in *Inspector) FindHandles() []string

FindHandles returns all handles mentioned in the AST.

func (*Inspector) FindNodes

func (in *Inspector) FindNodes(typ reflect.Type) []Node

FindNodes returns the nodes having typ.

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

func (in *Inspector) FindWhereClauses() ([]*WhereNode, error)

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) AddChild added in v0.26.0

func (jn *JoinNode) AddChild(node Node) error

func (*JoinNode) Children added in v0.26.0

func (jn *JoinNode) Children() []Node

func (*JoinNode) Context added in v0.26.0

func (jn *JoinNode) Context() antlr.ParseTree

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) Parent added in v0.26.0

func (jn *JoinNode) Parent() Node

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 (jn *JoinNode) SetChildren(children []Node) error

func (*JoinNode) SetContext added in v0.26.0

func (jn *JoinNode) SetContext(ctx antlr.ParseTree) error

func (*JoinNode) SetParent added in v0.26.0

func (jn *JoinNode) SetParent(parent Node) error

func (*JoinNode) String added in v0.26.0

func (jn *JoinNode) String() string

func (*JoinNode) Text added in v0.26.0

func (jn *JoinNode) Text() string

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

func (bn *LiteralNode) AddChild(child Node) error

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) Context added in v0.27.0

func (bn *LiteralNode) Context() antlr.ParseTree

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 (bn *LiteralNode) SetChildren(children []Node) error

func (*LiteralNode) SetContext added in v0.27.0

func (bn *LiteralNode) SetContext(ctx antlr.ParseTree) error

func (*LiteralNode) SetParent added in v0.27.0

func (bn *LiteralNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*LiteralNode) String added in v0.27.0

func (n *LiteralNode) String() string

String returns a log/debug-friendly representation.

func (*LiteralNode) Text added in v0.27.0

func (bn *LiteralNode) Text() string

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

func NodeNextSibling(node Node) Node

NodeNextSibling returns the node's next sibling, or nil.

func NodePrevSibling added in v0.31.0

func NodePrevSibling(node Node) Node

NodePrevSibling returns the node's previous sibling, or nil.

func NodesHavingText added in v0.31.0

func NodesHavingText(tree Node, text string) []Node

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

func (bn *OperatorNode) AddChild(child Node) error

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) Context added in v0.27.0

func (bn *OperatorNode) Context() antlr.ParseTree

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 (bn *OperatorNode) SetChildren(children []Node) error

func (*OperatorNode) SetContext added in v0.27.0

func (bn *OperatorNode) SetContext(ctx antlr.ParseTree) error

func (*OperatorNode) SetParent added in v0.27.0

func (bn *OperatorNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*OperatorNode) String added in v0.27.0

func (n *OperatorNode) String() string

String returns a log/debug-friendly representation.

func (*OperatorNode) Text added in v0.27.0

func (bn *OperatorNode) Text() string

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) Context added in v0.27.0

func (bn *OrderByNode) Context() antlr.ParseTree

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) SetParent added in v0.27.0

func (bn *OrderByNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

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.

func (*OrderByNode) Text added in v0.27.0

func (bn *OrderByNode) Text() string

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) SetParent added in v0.27.0

func (bn *OrderByTermNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*OrderByTermNode) String added in v0.27.0

func (n *OrderByTermNode) String() string

String returns a log/debug-friendly representation.

func (*OrderByTermNode) Text added in v0.27.0

func (bn *OrderByTermNode) Text() string

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

type RowRangeNode struct {
	Offset int
	Limit  int
	// contains filtered or unexported fields
}

RowRangeNode models a range, effectively {OFFSET,LIMIT}.

func (*RowRangeNode) AddChild added in v0.27.0

func (bn *RowRangeNode) AddChild(child Node) error

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) Context added in v0.27.0

func (bn *RowRangeNode) Context() antlr.ParseTree

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 (bn *RowRangeNode) SetChildren(children []Node) error

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

func (*RowRangeNode) Text added in v0.27.0

func (bn *RowRangeNode) Text() 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

func (bn *SelectorNode) AddChild(child Node) error

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) Context added in v0.26.0

func (bn *SelectorNode) Context() antlr.ParseTree

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 (bn *SelectorNode) SetChildren(children []Node) error

func (*SelectorNode) SetContext added in v0.26.0

func (bn *SelectorNode) SetContext(ctx antlr.ParseTree) error

func (*SelectorNode) SetParent added in v0.26.0

func (bn *SelectorNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*SelectorNode) String added in v0.26.0

func (s *SelectorNode) String() string

Strings returns a log/debug-friendly representation.

func (*SelectorNode) Text added in v0.26.0

func (bn *SelectorNode) Text() string

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

func (bn TblColSelectorNode) AddChild(child Node) error

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 (bn TblColSelectorNode) SetChildren(children []Node) error

func (TblColSelectorNode) SetContext added in v0.26.0

func (bn TblColSelectorNode) SetContext(ctx antlr.ParseTree) error

func (TblColSelectorNode) SetParent added in v0.26.0

func (bn TblColSelectorNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

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

func (bn *TblSelectorNode) AddChild(child Node) error

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 (bn *TblSelectorNode) SetChildren(children []Node) error

func (*TblSelectorNode) SetContext added in v0.26.0

func (bn *TblSelectorNode) SetContext(ctx antlr.ParseTree) error

func (*TblSelectorNode) SetParent added in v0.26.0

func (bn *TblSelectorNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

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.

func (*TblSelectorNode) Text added in v0.26.0

func (bn *TblSelectorNode) Text() string

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

func (bn *UniqueNode) AddChild(child Node) error

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) Context added in v0.30.0

func (bn *UniqueNode) Context() antlr.ParseTree

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 (bn *UniqueNode) SetChildren(children []Node) error

func (*UniqueNode) SetContext added in v0.30.0

func (bn *UniqueNode) SetContext(ctx antlr.ParseTree) error

func (*UniqueNode) SetParent added in v0.30.0

func (bn *UniqueNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*UniqueNode) String added in v0.30.0

func (n *UniqueNode) String() string

String returns a log/debug-friendly representation.

func (*UniqueNode) Text added in v0.30.0

func (bn *UniqueNode) Text() string

type Walker

type Walker struct {
	// contains filtered or unexported fields
}

Walker traverses a node tree (the AST, or a subset thereof).

func NewWalker

func NewWalker(node Node) *Walker

NewWalker returns a new Walker instance.

func (*Walker) AddVisitor

func (w *Walker) AddVisitor(typ reflect.Type, visitor nodeVisitorFn) *Walker

AddVisitor adds a visitor function for any node that is assignable to typ.

func (*Walker) Walk

func (w *Walker) Walk() error

Walk starts the walking process.

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) AddChild added in v0.27.0

func (n *WhereNode) AddChild(node Node) error

AddChild implements Node.

func (*WhereNode) Children added in v0.27.0

func (bn *WhereNode) Children() []Node

Children implements Node.Children.

func (*WhereNode) Context added in v0.27.0

func (bn *WhereNode) Context() antlr.ParseTree

func (*WhereNode) Expr added in v0.27.0

func (n *WhereNode) Expr() *ExprNode

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 (bn *WhereNode) SetChildren(children []Node) error

func (*WhereNode) SetContext added in v0.27.0

func (bn *WhereNode) SetContext(ctx antlr.ParseTree) error

func (*WhereNode) SetParent added in v0.27.0

func (bn *WhereNode) SetParent(parent Node) error

SetParent implements Node.SetParent.

func (*WhereNode) String added in v0.27.0

func (n *WhereNode) String() string

String returns a log/debug-friendly representation.

func (*WhereNode) Text added in v0.27.0

func (bn *WhereNode) Text() string

Directories

Path Synopsis
internal
slq
Package render provides the mechanism for rendering ast into SQL.
Package render provides the mechanism for rendering ast into SQL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL