parser

package
v0.0.0-...-a13ee55 Latest Latest
Warning

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

Go to latest
Published: May 31, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeSQLValue

func EncodeSQLValue(buf []byte, arg interface{}) ([]byte, error)

EncodeSQLValue ...

Types

type AliasedTableExpr

type AliasedTableExpr struct {
	Expr  SimpleTableExpr
	As    string
	Hints *IndexHints
}

AliasedTableExpr represents a table expression coupled with an optional alias or index hint.

func (*AliasedTableExpr) String

func (node *AliasedTableExpr) String() string

type AndExpr

type AndExpr struct {
	Op          string
	Left, Right BoolExpr
}

AndExpr represents an AND expression.

func (*AndExpr) String

func (node *AndExpr) String() string

type BinaryExpr

type BinaryExpr struct {
	Operator    byte
	Left, Right Expr
}

BinaryExpr represents a binary value expression.

func (*BinaryExpr) String

func (node *BinaryExpr) String() string

type BoolExpr

type BoolExpr interface {
	Expr
	// contains filtered or unexported methods
}

BoolExpr represents a boolean expression.

type BytesVal

type BytesVal string

BytesVal represents a string of unprintable value.

func (BytesVal) String

func (node BytesVal) String() string

type CaseExpr

type CaseExpr struct {
	Expr  ValExpr
	Whens []*When
	Else  ValExpr
}

CaseExpr represents a CASE expression.

func (*CaseExpr) String

func (node *CaseExpr) String() string

type ColName

type ColName struct {
	Name, Qualifier string
}

ColName represents a column name.

func (*ColName) String

func (node *ColName) String() string

type Columns

type Columns []SelectExpr

Columns represents an insert column list. The syntax for Columns is a subset of SelectExprs. So, it's castable to a SelectExprs and can be analyzed as such.

func (Columns) String

func (node Columns) String() string

type Comments

type Comments []string

Comments represents a list of comments.

func (Comments) String

func (node Comments) String() string

type ComparisonExpr

type ComparisonExpr struct {
	Operator    string
	Left, Right ValExpr
}

ComparisonExpr represents a two-value comparison expression.

func (*ComparisonExpr) String

func (node *ComparisonExpr) String() string

type DDL

type DDL struct {
	Action  string
	Name    string
	NewName string
}

DDL represents a CREATE, ALTER, DROP or RENAME statement. Table is set for astAlter, astDrop, astRename. NewName is set for astAlter, astCreate, astRename.

func (*DDL) String

func (node *DDL) String() string

type Delete

type Delete struct {
	Comments Comments
	Table    *TableName
	Where    *Where
	OrderBy  OrderBy
	Limit    *Limit
}

Delete represents a DELETE statement.

func (*Delete) String

func (node *Delete) String() string

type ErrVal

type ErrVal struct {
	Err error
}

ErrVal represents an error condition that occurred while constructing a tree.

func (ErrVal) String

func (v ErrVal) String() string

type ExistsExpr

type ExistsExpr struct {
	Subquery *Subquery
}

ExistsExpr represents an EXISTS expression.

func (*ExistsExpr) String

func (node *ExistsExpr) String() string

type Expr

type Expr interface {
	// contains filtered or unexported methods
}

Expr represents an expression.

type FuncExpr

type FuncExpr struct {
	Name     string
	Distinct bool
	Exprs    SelectExprs
}

FuncExpr represents a function call.

func (*FuncExpr) String

func (node *FuncExpr) String() string

type GroupBy

type GroupBy []ValExpr

GroupBy represents a GROUP BY clause.

func (GroupBy) String

func (node GroupBy) String() string

type IndexHints

type IndexHints struct {
	Type    string
	Indexes []string
}

IndexHints represents a list of index hints.

func (*IndexHints) String

func (node *IndexHints) String() string

type Insert

type Insert struct {
	Comments Comments
	Table    *TableName
	Columns  Columns
	Rows     InsertRows
	OnDup    OnDup
}

Insert represents an INSERT statement.

func (*Insert) String

func (node *Insert) String() string

type InsertRows

type InsertRows interface {
	// contains filtered or unexported methods
}

InsertRows represents the rows for an INSERT statement.

type JoinCond

type JoinCond interface {
	// contains filtered or unexported methods
}

JoinCond represents a join condition.

type JoinTableExpr

type JoinTableExpr struct {
	LeftExpr  TableExpr
	Join      string
	RightExpr TableExpr
	Cond      JoinCond
}

JoinTableExpr represents a TableExpr that's a JOIN operation.

func (*JoinTableExpr) String

func (node *JoinTableExpr) String() string

type Limit

type Limit struct {
	Offset, Rowcount ValExpr
}

Limit represents a LIMIT clause.

func (*Limit) String

func (node *Limit) String() string

type NonStarExpr

type NonStarExpr struct {
	Expr Expr
	As   string
}

NonStarExpr defines a non-'*' select expr.

func (*NonStarExpr) String

func (node *NonStarExpr) String() string

type NotExpr

type NotExpr struct {
	Op   string
	Expr BoolExpr
}

NotExpr represents a NOT expression.

func (*NotExpr) String

func (node *NotExpr) String() string

type NullCheck

type NullCheck struct {
	Operator string
	Expr     ValExpr
}

NullCheck represents an IS NULL or an IS NOT NULL expression.

func (*NullCheck) String

func (node *NullCheck) String() string

type NullVal

type NullVal struct{}

NullVal represents a NULL value.

func (*NullVal) String

func (node *NullVal) String() string

type NumVal

type NumVal string

NumVal represents a number.

func (NumVal) String

func (node NumVal) String() string

type OnDup

type OnDup UpdateExprs

OnDup represents an ON DUPLICATE KEY clause.

func (OnDup) String

func (node OnDup) String() string

type OnJoinCond

type OnJoinCond struct {
	Expr BoolExpr
}

OnJoinCond represents an ON join condition.

func (*OnJoinCond) String

func (node *OnJoinCond) String() string

type OrExpr

type OrExpr struct {
	Op          string
	Left, Right BoolExpr
}

OrExpr represents an OR expression.

func (*OrExpr) String

func (node *OrExpr) String() string

type Order

type Order struct {
	Expr      ValExpr
	Direction string
}

Order represents an ordering expression.

func (*Order) String

func (node *Order) String() string

type OrderBy

type OrderBy []*Order

OrderBy represents an ORDER By clause.

func (OrderBy) String

func (node OrderBy) String() string

type ParenBoolExpr

type ParenBoolExpr struct {
	Expr BoolExpr
}

ParenBoolExpr represents a parenthesized boolean expression.

func (*ParenBoolExpr) String

func (node *ParenBoolExpr) String() string

type ParenTableExpr

type ParenTableExpr struct {
	Expr TableExpr
}

ParenTableExpr represents a parenthesized TableExpr.

func (*ParenTableExpr) String

func (node *ParenTableExpr) String() string

type RangeCond

type RangeCond struct {
	Operator string
	Left     ValExpr
	From, To ValExpr
}

RangeCond represents a BETWEEN or a NOT BETWEEN expression.

func (*RangeCond) String

func (node *RangeCond) String() string

type Select

type Select struct {
	Comments Comments
	Distinct string
	Exprs    SelectExprs
	From     TableExprs
	Where    *Where
	GroupBy  GroupBy
	Having   *Where
	OrderBy  OrderBy
	Limit    *Limit
	Lock     string
}

Select represents a SELECT statement.

func (*Select) String

func (node *Select) String() string

type SelectExpr

type SelectExpr interface {
	// contains filtered or unexported methods
}

SelectExpr represents a SELECT expression.

type SelectExprs

type SelectExprs []SelectExpr

SelectExprs represents SELECT expressions.

func (SelectExprs) String

func (node SelectExprs) String() string

type SelectStatement

type SelectStatement interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

SelectStatement any SELECT statement.

type Set

type Set struct {
	Comments Comments
	Exprs    UpdateExprs
}

Set represents a SET statement.

func (*Set) String

func (node *Set) String() string

type SimpleTableExpr

type SimpleTableExpr interface {
	// contains filtered or unexported methods
}

SimpleTableExpr represents a simple table expression.

type StarExpr

type StarExpr struct {
	TableName string
}

StarExpr defines a '*' or 'table.*' expression.

func (*StarExpr) String

func (node *StarExpr) String() string

type Statement

type Statement interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

Statement represents a statement.

func Parse

func Parse(sql string) (Statement, error)

Parse parses the sql and returns a Statement, which is the AST representation of the query.

type StrVal

type StrVal string

StrVal represents a string value.

func (StrVal) String

func (node StrVal) String() string

type Subquery

type Subquery struct {
	Select SelectStatement
}

Subquery represents a subquery.

func (*Subquery) String

func (node *Subquery) String() string

type TableExpr

type TableExpr interface {
	// contains filtered or unexported methods
}

TableExpr represents a table expression.

type TableExprs

type TableExprs []TableExpr

TableExprs represents a list of table expressions.

func (TableExprs) String

func (node TableExprs) String() string

type TableName

type TableName struct {
	Name, Qualifier string
}

TableName represents a table name.

func (*TableName) String

func (node *TableName) String() string

type Tokenizer

type Tokenizer struct {
	InStream      *strings.Reader
	AllowComments bool
	ForceEOF      bool

	Position int

	LastError string

	ParseTree Statement
	// contains filtered or unexported fields
}

Tokenizer is the struct used to generate SQL tokens for the parser.

func NewStringTokenizer

func NewStringTokenizer(sql string) *Tokenizer

NewStringTokenizer creates a new Tokenizer for the sql string.

func (*Tokenizer) Error

func (tkn *Tokenizer) Error(err string)

Error is called by go yacc if there's a parsing error.

func (*Tokenizer) Lex

func (tkn *Tokenizer) Lex(lval *yySymType) int

Lex returns the next token form the Tokenizer. This function is used by go yacc.

func (*Tokenizer) Scan

func (tkn *Tokenizer) Scan() (int, []byte)

Scan scans the tokenizer for the next token and returns the token type and an optional value.

type Tuple

type Tuple interface {
	ValExpr
	// contains filtered or unexported methods
}

Tuple represents a tuple. It can be ValTuple, Subquery.

type UnaryExpr

type UnaryExpr struct {
	Operator byte
	Expr     Expr
}

UnaryExpr represents a unary value expression.

func (*UnaryExpr) String

func (node *UnaryExpr) String() string

type Union

type Union struct {
	Type        string
	Left, Right SelectStatement
}

Union represents a UNION statement.

func (*Union) String

func (node *Union) String() string

type Update

type Update struct {
	Comments Comments
	Table    *TableName
	Exprs    UpdateExprs
	Where    *Where
	OrderBy  OrderBy
	Limit    *Limit
}

Update represents an UPDATE statement.

func (*Update) String

func (node *Update) String() string

type UpdateExpr

type UpdateExpr struct {
	Name *ColName
	Expr ValExpr
}

UpdateExpr represents an update expression.

func (*UpdateExpr) String

func (node *UpdateExpr) String() string

type UpdateExprs

type UpdateExprs []*UpdateExpr

UpdateExprs represents a list of update expressions.

func (UpdateExprs) String

func (node UpdateExprs) String() string

type Use

type Use struct {
	Comments Comments
	Name     string
}

Use represents a USE statement.

func (*Use) String

func (node *Use) String() string

type UsingJoinCond

type UsingJoinCond struct {
	Cols Columns
}

UsingJoinCond represents a USING join condition.

func (*UsingJoinCond) String

func (node *UsingJoinCond) String() string

type ValArg

type ValArg string

ValArg represents a named bind var argument.

func (ValArg) String

func (node ValArg) String() string

type ValExpr

type ValExpr interface {
	Expr
	// contains filtered or unexported methods
}

ValExpr represents a value expression.

type ValExprs

type ValExprs []ValExpr

ValExprs represents a list of value expressions. It's not a valid expression because it's not parenthesized.

func (ValExprs) String

func (node ValExprs) String() string

type ValTuple

type ValTuple ValExprs

ValTuple represents a tuple of actual values.

func (ValTuple) String

func (node ValTuple) String() string

type Values

type Values []Tuple

Values represents a VALUES clause.

func (Values) String

func (node Values) String() string

type When

type When struct {
	Cond BoolExpr
	Val  ValExpr
}

When represents a WHEN sub-expression.

func (*When) String

func (node *When) String() string

type Where

type Where struct {
	Type string
	Expr BoolExpr
}

Where represents a WHERE or HAVING clause.

func NewWhere

func NewWhere(typ string, expr BoolExpr) *Where

NewWhere creates a WHERE or HAVING clause out of a BoolExpr. If the expression is nil, it returns nil.

func (*Where) String

func (node *Where) String() string

Jump to

Keyboard shortcuts

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