Documentation ¶
Index ¶
Constants ¶
View Source
const ( // 普通字段 SQLField_Type_Normal SQLFieldType = 1 // 取值函数 SQLField_Type_Func SQLFieldType = 2 // 聚合函数 SQLField_Type_Agg_Func SQLFieldType = 3 // 通配符* SQLField_Type_WildCard SQLFieldType = 4 // 显式值 SQLField_Type_Value SQLFieldType = 5 SQLField_Type_WildCard_Value string = "*" SQLFuncName_Sum string = "SUM" SQLFuncName_Avg string = "AVG" SQLFuncName_Count string = "COUNT" SQLFuncName_Max string = "MAX" SQLFuncName_Min string = "MIN" SQLFuncName_Json_Extract string = "JSON_EXTRACT" SQLFuncName_Year string = "YEAR" SQLFuncName_Month string = "MONTH" SQLFuncName_Day string = "DAY" SQLFuncName_Hour string = "HOUR" SQLFuncName_Minute string = "MINUTE" SQLFuncName_Second string = "SECOND" SQLFuncName_Date_Format string = "DATE_FORMAT" SQLFuncName_Plus string = "PLUS" SQLFuncName_Minus string = "MINUS" SQLFuncName_Mul string = "MUL" SQLFuncName_Div string = "DIV" SQLFuncName_Round string = "ROUND" )
Variables ¶
View Source
var ( SQLFunc_Agg_Map = map[string]string{ SQLFuncName_Sum: SQLFuncName_Sum, SQLFuncName_Avg: SQLFuncName_Avg, SQLFuncName_Count: SQLFuncName_Count, SQLFuncName_Max: SQLFuncName_Max, SQLFuncName_Min: SQLFuncName_Min, } SQLFunc_Map = map[string]string{ SQLFuncName_Json_Extract: SQLFuncName_Json_Extract, SQLFuncName_Year: SQLFuncName_Year, SQLFuncName_Month: SQLFuncName_Month, SQLFuncName_Day: SQLFuncName_Day, SQLFuncName_Hour: SQLFuncName_Hour, SQLFuncName_Minute: SQLFuncName_Minute, SQLFuncName_Second: SQLFuncName_Second, SQLFuncName_Date_Format: SQLFuncName_Date_Format, SQLFuncName_Round: SQLFuncName_Round, } SQLOperator_Map = map[opcode.Op]string{ opcode.Plus: SQLFuncName_Plus, opcode.Minus: SQLFuncName_Minus, opcode.Mul: SQLFuncName_Mul, opcode.Div: SQLFuncName_Div, } SQLOperator_Origin_Map = map[string]string{ SQLFuncName_Plus: "+", SQLFuncName_Minus: "-", SQLFuncName_Mul: "*", SQLFuncName_Div: "/", } )
View Source
var ( Func_Arg_Err_Msg = "func %v must contains %v arg,but got %v arg" Func_Arg_Type_Err_Msg = "func %v have unexpect arg,type=%v,name=%v" )
Functions ¶
This section is empty.
Types ¶
type BinaryOperation ¶
type BinaryOperation struct { SQLField Operator *opcode.Op Left *BinaryOperation Right *BinaryOperation }
type Column ¶
type Column struct { Type ColumnType Name string Array *Column Json map[string]*Column }
type ColumnType ¶
type ColumnType int
const ( Int ColumnType = 1 Float ColumnType = 2 Boolean ColumnType = 3 String ColumnType = 4 Datetime ColumnType = 5 Json ColumnType = 6 Array ColumnType = 7 WildCard ColumnType = 8 )
type MySQLSelectParser ¶
type MySQLSelectParser struct {
// contains filtered or unexported fields
}
func (*MySQLSelectParser) GetOriginalSQL ¶
func (parser *MySQLSelectParser) GetOriginalSQL() string
func (*MySQLSelectParser) GetStmt ¶
func (parser *MySQLSelectParser) GetStmt() (sqlSelect *SQLSelect, err error)
func (*MySQLSelectParser) Parse ¶
func (parser *MySQLSelectParser) Parse() (sql SQL, err error)
type SQLField ¶
type SQLField struct { Type SQLFieldType Table *string Func *string Distinct bool Args []*SQLField Name *Column AsName *string ValueKind *byte Value any }
func (SQLField) HasDistinct ¶
func (SQLField) IsAllValue ¶
type SQLFieldType ¶
type SQLFieldType int
type SQLOrderBy ¶
type SQLSelect ¶
type SQLSelect struct { Distinct bool Fields []*SQLField From *SQLTable Where *BinaryOperation GroupBy []*SQLField Having *BinaryOperation OrderBy []*SQLOrderBy Limit *SQLLimit SQL *string }
func (SQLSelect) OriginalSQL ¶
type SQLTable ¶
type SelectParser ¶
SQL解析器,包含:语法树解析、语法校验、优化改写
func NewMySQLSelectParser ¶
func NewMySQLSelectParser(sql string, tableSchema map[string][]*Column) SelectParser
Click to show internal directories.
Click to hide internal directories.