ast

package
v0.0.0-...-12a2bdb Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QueriesInTopologicalOrder

func QueriesInTopologicalOrder(queries []string, execQueryFunc ExecQueryFunc) ([]string, error)

func RunQueriesInTopologicalOrder

func RunQueriesInTopologicalOrder(queries []string, execQueryFunc ExecQueryFunc) error

Types

type Ast

type Ast struct {
	Root          *AstNode
	Query         string
	ParentAsts    []*Ast
	DependentAsts []*Ast
}

func NewFromExplainLines

func NewFromExplainLines(query string, lines []string) (*Ast, error)

func NewFromQuery

func NewFromQuery(query string, execQueryFunc ExecQueryFunc) (*Ast, error)

func PopulateAndSort

func PopulateAndSort(asts ...*Ast) ([]*Ast, error)

func (*Ast) AddColumnDeclarations

func (a *Ast) AddColumnDeclarations() []string

func (*Ast) AlterQueryStatements

func (a *Ast) AlterQueryStatements() []string

func (*Ast) CommentColumnIdentifiers

func (a *Ast) CommentColumnIdentifiers() []string

func (*Ast) CreateFunctionStatements

func (a *Ast) CreateFunctionStatements() []string

func (*Ast) CreateTableAndViewStatements

func (a *Ast) CreateTableAndViewStatements() []string

func (*Ast) CreateTableColumnDeclarations

func (a *Ast) CreateTableColumnDeclarations() []string

TODO: document node types of interest

func (*Ast) DropOrClearColumnIdentifiers

func (a *Ast) DropOrClearColumnIdentifiers() []string

alter table clear column also uses drop column as the command type

func (*Ast) DropTableOrViewStatements

func (a *Ast) DropTableOrViewStatements() []string

func (*Ast) FunctionCalls

func (a *Ast) FunctionCalls() []string

func (*Ast) MaterializeColumnIdentifiers

func (a *Ast) MaterializeColumnIdentifiers() []string

func (*Ast) ModifyColumnDeclarations

func (a *Ast) ModifyColumnDeclarations() []string

func (*Ast) NodesForMatch

func (a *Ast) NodesForMatch(matcher func(node *AstNode) bool) []*AstNode

func (*Ast) RenameColumnFromIdentifiers

func (a *Ast) RenameColumnFromIdentifiers() []string

func (*Ast) RenameColumnToIdentifiers

func (a *Ast) RenameColumnToIdentifiers() []string

func (*Ast) RenameIdentifiers

func (a *Ast) RenameIdentifiers() []string

must come after any create and before any drop

func (*Ast) SelectColumnIdentifiers

func (a *Ast) SelectColumnIdentifiers() []string

func (*Ast) SelectColumnNodes

func (a *Ast) SelectColumnNodes() []*AstNode

TODO: use this for matching against aliases. Special case single table select and always set valueIdentifier to table being selected from

func (*Ast) SelectColumnTableQualifiers

func (a *Ast) SelectColumnTableQualifiers() []string

func (*Ast) TableAndViewIdentifiers

func (a *Ast) TableAndViewIdentifiers() []string

func (*Ast) ValuesForMatch

func (a *Ast) ValuesForMatch(matcher func(node *AstNode) bool) []string

type AstNode

type AstNode struct {
	RawLine string
	Indent  int
	Type    string
	Value   string
	// Think table name, database name, etc.
	ValueQualifier string
	Alias          string
	Meta           string
	// Hash int64 // hash of the node and
	// children to quickly compare branches
	Parent   *AstNode
	Children []*AstNode
}

TODO: add hash

func Parse

func Parse(sourceQuery string, lines []string) (root *AstNode, err error)

func (*AstNode) Walk

func (n *AstNode) Walk(cb func(node *AstNode))

type ExecQueryFunc

type ExecQueryFunc func(query string) ([]map[string]interface{}, error)

TODO: return err instead of panicking

Jump to

Keyboard shortcuts

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