Documentation ¶
Index ¶
- Constants
- Variables
- func AsInterface(node ValExpr) (interface{}, error)
- func EncodeValue(buf *bytes.Buffer, value interface{}) error
- func FetchBindVar(name string, bindVariables map[string]interface{}) (val interface{}, isList bool, err error)
- func GetColName(node Expr) string
- func GetTableName(node SimpleTableExpr) string
- func HasINClause(conditions []BoolExpr) bool
- func IsColName(node ValExpr) bool
- func IsNull(node ValExpr) bool
- func IsSimpleTuple(node ValExpr) bool
- func IsValue(node ValExpr) bool
- func String(node SQLNode) string
- func StringIn(str string, values ...string) bool
- type AliasedTableExpr
- type AndExpr
- type BinaryExpr
- type BoolExpr
- type BoolVal
- type CaseExpr
- type ColName
- type ColTuple
- type Columns
- type Comments
- type ComparisonExpr
- type DDL
- type Delete
- type ExistsExpr
- type Expr
- type FuncExpr
- type GroupBy
- type IndexHints
- type Insert
- type InsertRows
- type IsExpr
- type JoinTableExpr
- type KeyrangeExpr
- type Limit
- type ListArg
- type NonStarExpr
- type NotExpr
- type NullVal
- type NumVal
- type OnDup
- type OrExpr
- type Order
- type OrderBy
- type Other
- type ParenBoolExpr
- type ParenTableExpr
- type ParsedQuery
- type RangeCond
- type RowTuple
- type SQLName
- type SQLNode
- type Select
- type SelectExpr
- type SelectExprs
- type SelectStatement
- type Set
- type SimpleTableExpr
- type StarExpr
- type Statement
- type StrVal
- type Subquery
- type TableExpr
- type TableExprs
- type TableName
- type Tokenizer
- type TrackedBuffer
- type TupleEqualityList
- type UnaryExpr
- type Union
- type Update
- type UpdateExpr
- type UpdateExprs
- type ValArg
- type ValExpr
- type ValExprs
- type ValTuple
- type Values
- type When
- type Where
Constants ¶
const ( ForUpdateStr = " for update" )
Select.Lock
const ( UnionStr = "union" UnionAllStr = "union all" SetMinusStr = "minus" ExceptStr = "except" IntersectStr = "intersect" )
Union.Type
const ( CreateStr = "create" AlterStr = "alter" DropStr = "drop" RenameStr = "rename" )
DDL strings.
const ( JoinStr = "join" StraightJoinStr = "straight_join" LeftJoinStr = "left join" RightJoinStr = "right join" NaturalJoinStr = "natural join" NaturalLeftJoinStr = "natural left join" NaturalRightJoinStr = "natural right join" )
JoinTableExpr.Join
const ( UseStr = "use " IgnoreStr = "ignore " ForceStr = "force " )
Index hints.
const ( WhereStr = "where" HavingStr = "having" )
Where.Type
const ( EqualStr = "=" LessThanStr = "<" GreaterThanStr = ">" LessEqualStr = "<=" GreaterEqualStr = ">=" NotEqualStr = "!=" NullSafeEqualStr = "<=>" InStr = "in" NotInStr = "not in" LikeStr = "like" NotLikeStr = "not like" RegexpStr = "regexp" NotRegexpStr = "not regexp" )
ComparisonExpr.Operator
const ( BetweenStr = "between" NotBetweenStr = "not between" )
RangeCond.Operator
const ( IsNullStr = "is null" IsNotNullStr = "is not null" IsTrueStr = "is true" IsNotTrueStr = "is not true" IsFalseStr = "is false" IsNotFalseStr = "is not false" )
IsExpr.Operator
const ( BitAndStr = "&" BitOrStr = "|" BitXorStr = "^" PlusStr = "+" MinusStr = "-" MultStr = "*" DivStr = "/" ModStr = "%" ShiftLeftStr = "<<" ShiftRightStr = ">>" )
BinaryExpr.Operator
const ( UPlusStr = '+' UMinusStr = '-' TildaStr = '~' )
UnaryExpr.Operator
const ( AscScr = "asc" DescScr = "desc" )
Order.Direction
const ALL = 57363
const ALTER = 57419
const ANALYZE = 57422
const AND = 57399
const AS = 57365
const ASC = 57367
const BETWEEN = 57401
const BY = 57360
const CASE = 57402
const COMMENT = 57394
const CREATE = 57418
const CROSS = 57384
const DEFAULT = 57372
const DELETE = 57354
const DESC = 57368
const DESCRIBE = 57432
const DISTINCT = 57364
const DROP = 57420
const DUPLICATE = 57370
const (
DistinctStr = "distinct "
)
Select.Distinct
const ELSE = 57405
const END = 57417
const EXCEPT = 57349
const EXISTS = 57366
const EXPLAIN = 57433
const FALSE = 57397
const FOR = 57362
const FORCE = 57387
const FROM = 57355
const GE = 57407
const GROUP = 57357
const HAVING = 57358
const ID = 57389
const IF = 57428
const IGNORE = 57427
const IN = 57413
const INDEX = 57424
const INNER = 57382
const INSERT = 57352
const INTERSECT = 57350
const INTO = 57369
const IS = 57410
const JOIN = 57378
const KEY = 57371
const KEYRANGE = 57375
const LAST_INSERT_ID = 57377
const LE = 57406
const LEFT = 57380
const LEX_ERROR = 57346
const LIKE = 57411
const LIMIT = 57361
const LIST_ARG = 57393
const LOCK = 57374
const MINUS = 57348
const NATURAL = 57385
const NE = 57408
const NOT = 57400
const NULL = 57395
const NULL_SAFE_EQUAL = 57409
const NUMBER = 57391
const ON = 57388
const OR = 57398
const ORDER = 57359
const OUTER = 57383
const REGEXP = 57412
const RENAME = 57421
const RIGHT = 57381
const SELECT = 57351
const SET = 57373
const SHIFT_LEFT = 57414
const SHIFT_RIGHT = 57415
const SHOW = 57431
const STRAIGHT_JOIN = 57379
const STRING = 57390
const TABLE = 57423
const THEN = 57404
const TO = 57426
const TRUE = 57396
const UNARY = 57416
const UNION = 57347
const UNIQUE = 57429
const UPDATE = 57353
const USE = 57386
const USING = 57430
const VALUES = 57376
const VALUE_ARG = 57392
const VIEW = 57425
const WHEN = 57403
const WHERE = 57356
Variables ¶
var Aggregates = map[string]bool{ "avg": true, "bit_and": true, "bit_or": true, "bit_xor": true, "count": true, "group_concat": true, "max": true, "min": true, "std": true, "stddev_pop": true, "stddev_samp": true, "stddev": true, "sum": true, "var_pop": true, "var_samp": true, "variance": true, }
Aggregates is a map of all aggregate functions.
var AllExprs = []Expr{ &AndExpr{}, &OrExpr{}, &NotExpr{}, &ParenBoolExpr{}, &ComparisonExpr{}, &RangeCond{}, &IsExpr{}, &ExistsExpr{}, &KeyrangeExpr{}, StrVal(""), NumVal(""), ValArg(""), &NullVal{}, BoolVal(false), &ColName{}, ValTuple{}, &Subquery{}, ListArg(""), &BinaryExpr{}, &UnaryExpr{}, &FuncExpr{}, &CaseExpr{}, }
AllExprs must contain one variable for each AST type that satisfies Expr. This allows for external packages to verify that they're not missing on any types.
Functions ¶
func AsInterface ¶
AsInterface converts the ValExpr to an interface. It converts ValTuple to []interface{}, ValArg to string, StrVal to sqltypes.String, NumVal to sqltypes.Numeric, NullVal to nil. Otherwise, it returns an error.
func EncodeValue ¶
EncodeValue encodes one bind variable value into the query.
func FetchBindVar ¶
func FetchBindVar(name string, bindVariables map[string]interface{}) (val interface{}, isList bool, err error)
FetchBindVar resolves the bind variable by fetching it from bindVariables.
func GetColName ¶
GetColName returns the column name, only if it's a simple expression. Otherwise, it returns "".
func GetTableName ¶
func GetTableName(node SimpleTableExpr) string
GetTableName returns the table name from the SimpleTableExpr only if it's a simple expression. Otherwise, it returns "".
func HasINClause ¶
HasINClause returns true if any of the conditions has an IN clause.
func IsSimpleTuple ¶
IsSimpleTuple returns true if the ValExpr is a ValTuple that contains simple values or if it's a list arg.
func IsValue ¶
IsValue returns true if the ValExpr is a string, number or value arg. NULL is not considered to be a value.
Types ¶
type AliasedTableExpr ¶
type AliasedTableExpr struct { Expr SimpleTableExpr As SQLName Hints *IndexHints }
AliasedTableExpr represents a table expression coupled with an optional alias or index hint. If As is empty, no alias was used.
func (*AliasedTableExpr) Format ¶
func (node *AliasedTableExpr) Format(buf *TrackedBuffer)
Format formats the node.
type BinaryExpr ¶
BinaryExpr represents a binary value expression.
func (*BinaryExpr) Format ¶
func (node *BinaryExpr) Format(buf *TrackedBuffer)
Format formats the node.
type BoolExpr ¶
type BoolExpr interface { Expr // contains filtered or unexported methods }
BoolExpr represents a boolean expression.
type ColTuple ¶
type ColTuple interface { ValExpr // contains filtered or unexported methods }
ColTuple represents a list of column values. It can be ValTuple, Subquery, ListArg.
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.
type ComparisonExpr ¶
ComparisonExpr represents a two-value comparison expression.
func (*ComparisonExpr) Format ¶
func (node *ComparisonExpr) Format(buf *TrackedBuffer)
Format formats the node.
type DDL ¶
DDL represents a CREATE, ALTER, DROP or RENAME statement. Table is set for AlterStr, DropStr, RenameStr. NewName is set for AlterStr, CreateStr, RenameStr.
type ExistsExpr ¶
type ExistsExpr struct {
Subquery *Subquery
}
ExistsExpr represents an EXISTS expression.
func (*ExistsExpr) Format ¶
func (node *ExistsExpr) Format(buf *TrackedBuffer)
Format formats the node.
type Expr ¶
type Expr interface { SQLNode // 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) IsAggregate ¶
IsAggregate returns true if the function is an aggregate.
type IndexHints ¶
IndexHints represents a list of index hints.
func (*IndexHints) Format ¶
func (node *IndexHints) Format(buf *TrackedBuffer)
Format formats the node.
type Insert ¶
type Insert struct { Comments Comments Ignore string Table *TableName Columns Columns Rows InsertRows OnDup OnDup }
Insert represents an INSERT statement.
type InsertRows ¶
type InsertRows interface { SQLNode // contains filtered or unexported methods }
InsertRows represents the rows for an INSERT statement.
type JoinTableExpr ¶
JoinTableExpr represents a TableExpr that's a JOIN operation.
func (*JoinTableExpr) Format ¶
func (node *JoinTableExpr) Format(buf *TrackedBuffer)
Format formats the node.
type KeyrangeExpr ¶
type KeyrangeExpr struct {
Start, End ValExpr
}
KeyrangeExpr represents a KEYRANGE expression.
func (*KeyrangeExpr) Format ¶
func (node *KeyrangeExpr) Format(buf *TrackedBuffer)
Format formats the node.
type NonStarExpr ¶
NonStarExpr defines a non-'*' select expr.
func (*NonStarExpr) Format ¶
func (node *NonStarExpr) Format(buf *TrackedBuffer)
Format formats the node.
type Other ¶
type Other struct{}
Other represents a SHOW, DESCRIBE, or EXPLAIN statement. It should be used only as an indicator. It does not contain the full AST for the statement.
type ParenBoolExpr ¶
type ParenBoolExpr struct {
Expr BoolExpr
}
ParenBoolExpr represents a parenthesized boolean expression.
func (*ParenBoolExpr) Format ¶
func (node *ParenBoolExpr) Format(buf *TrackedBuffer)
Format formats the node.
type ParenTableExpr ¶
type ParenTableExpr struct {
Exprs TableExprs
}
ParenTableExpr represents a parenthesized list of TableExpr.
func (*ParenTableExpr) Format ¶
func (node *ParenTableExpr) Format(buf *TrackedBuffer)
Format formats the node.
type ParsedQuery ¶
type ParsedQuery struct { Query string // contains filtered or unexported fields }
ParsedQuery represents a parsed query where bind locations are precompued for fast substitutions.
func GenerateParsedQuery ¶
func GenerateParsedQuery(node SQLNode) *ParsedQuery
GenerateParsedQuery returns a ParsedQuery of the ast.
func (*ParsedQuery) GenerateQuery ¶
func (pq *ParsedQuery) GenerateQuery(bindVariables map[string]interface{}) ([]byte, error)
GenerateQuery generates a query by substituting the specified bindVariables.
func (*ParsedQuery) MarshalJSON ¶
func (pq *ParsedQuery) MarshalJSON() ([]byte, error)
MarshalJSON is a custom JSON marshaler for ParsedQuery.
type RangeCond ¶
RangeCond represents a BETWEEN or a NOT BETWEEN expression.
func (*RangeCond) Format ¶
func (node *RangeCond) Format(buf *TrackedBuffer)
Format formats the node.
type RowTuple ¶
type RowTuple interface { ValExpr // contains filtered or unexported methods }
RowTuple represents a row of values. It can be ValTuple, Subquery.
type SQLName ¶
type SQLName string
SQLName is an SQL identifier. It will be escaped with backquotes if it matches a keyword.
type SQLNode ¶
type SQLNode interface {
Format(buf *TrackedBuffer)
}
SQLNode defines the interface for all nodes generated by the parser.
type Select ¶
type Select struct { Comments Comments Distinct string SelectExprs SelectExprs From TableExprs Where *Where GroupBy GroupBy Having *Where OrderBy OrderBy Limit *Limit Lock string }
Select represents a SELECT statement.
type SelectExpr ¶
type SelectExpr interface { SQLNode // contains filtered or unexported methods }
SelectExpr represents a SELECT expression.
type SelectExprs ¶
type SelectExprs []SelectExpr
SelectExprs represents SELECT expressions.
func (SelectExprs) Format ¶
func (node SelectExprs) Format(buf *TrackedBuffer)
Format formats the node.
type SelectStatement ¶
type SelectStatement interface { SQLNode // contains filtered or unexported methods }
SelectStatement any SELECT statement.
type SimpleTableExpr ¶
type SimpleTableExpr interface { SQLNode // contains filtered or unexported methods }
SimpleTableExpr represents a simple table expression.
type StarExpr ¶
type StarExpr struct {
TableName SQLName
}
StarExpr defines a '*' or 'table.*' expression.
type Statement ¶
type Statement interface { SQLNode // contains filtered or unexported methods }
Statement represents a statement.
type TableExpr ¶
type TableExpr interface { SQLNode // contains filtered or unexported methods }
TableExpr represents a table expression.
type TableExprs ¶
type TableExprs []TableExpr
TableExprs represents a list of table expressions.
func (TableExprs) Format ¶
func (node TableExprs) Format(buf *TrackedBuffer)
Format formats the node.
type TableName ¶
type TableName struct {
Name, Qualifier SQLName
}
TableName represents a table name. Qualifier, if specified, represents a database. It's generally not supported because vitess has its own rules about which database to send a query to.
func (*TableName) Format ¶
func (node *TableName) Format(buf *TrackedBuffer)
Format formats the node.
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 ¶
NewStringTokenizer creates a new Tokenizer for the sql string.
type TrackedBuffer ¶
TrackedBuffer is used to rebuild a query from the ast. bindLocations keeps track of locations in the buffer that use bind variables for efficient future substitutions. nodeFormatter is the formatting function the buffer will use to format a node. By default(nil), it's FormatNode. But you can supply a different formatting function if you want to generate a query that's different from the default.
func NewTrackedBuffer ¶
func NewTrackedBuffer(nodeFormatter func(buf *TrackedBuffer, node SQLNode)) *TrackedBuffer
NewTrackedBuffer creates a new TrackedBuffer.
func (*TrackedBuffer) HasBindVars ¶
func (buf *TrackedBuffer) HasBindVars() bool
HasBindVars returns true if the parsed query uses bind vars.
func (*TrackedBuffer) Myprintf ¶
func (buf *TrackedBuffer) Myprintf(format string, values ...interface{})
Myprintf mimics fmt.Fprintf(buf, ...), but limited to Node(%v), Node.Value(%s) and string(%s). It also allows a %a for a value argument, in which case it adds tracking info for future substitutions.
The name must be something other than the usual Printf() to avoid "go vet" warnings due to our custom format specifiers.
func (*TrackedBuffer) ParsedQuery ¶
func (buf *TrackedBuffer) ParsedQuery() *ParsedQuery
ParsedQuery returns a ParsedQuery that contains bind locations for easy substitution.
func (*TrackedBuffer) WriteArg ¶
func (buf *TrackedBuffer) WriteArg(arg string)
WriteArg writes a value argument into the buffer along with tracking information for future substitutions. arg must contain the ":" or "::" prefix.
type TupleEqualityList ¶
TupleEqualityList is for generating equality constraints for tables that have composite primary keys.
type UnaryExpr ¶
UnaryExpr represents a unary value expression.
func (*UnaryExpr) Format ¶
func (node *UnaryExpr) Format(buf *TrackedBuffer)
Format formats the node.
type Union ¶
type Union struct { Type string Left, Right SelectStatement }
Union represents a UNION statement.
type Update ¶
type Update struct { Comments Comments Table *TableName Exprs UpdateExprs Where *Where OrderBy OrderBy Limit *Limit }
Update represents an UPDATE statement.
type UpdateExpr ¶
UpdateExpr represents an update expression.
func (*UpdateExpr) Format ¶
func (node *UpdateExpr) Format(buf *TrackedBuffer)
Format formats the node.
type UpdateExprs ¶
type UpdateExprs []*UpdateExpr
UpdateExprs represents a list of update expressions.
func (UpdateExprs) Format ¶
func (node UpdateExprs) Format(buf *TrackedBuffer)
Format formats the node.
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.