Documentation
¶
Index ¶
- Constants
- Variables
- type BinaryOperation
- type CaseWhenExpr
- type Column
- type ColumnType
- type ExprField
- type MySQLSelectParser
- type PatternLike
- type SQL
- type SQLField
- func (f *SQLField) Copy(source *SQLField)
- func (f *SQLField) GetArgs() []ExprField
- func (f SQLField) GetAsName() string
- func (f *SQLField) GetColName() *Column
- func (f *SQLField) GetColType() ColumnType
- func (f *SQLField) GetDistinct() bool
- func (f *SQLField) GetFunc() string
- func (f SQLField) GetName() string
- func (f *SQLField) GetRawName() string
- func (f *SQLField) GetTable() string
- func (f *SQLField) GetType() SQLFieldType
- func (f *SQLField) GetValue() any
- func (f *SQLField) GetValueKind() byte
- func (f *SQLField) HasDistinct() bool
- func (f *SQLField) IsAllValue() bool
- func (f *SQLField) SetArgs(args []ExprField)
- func (f *SQLField) SetAsName(asName string)
- func (f *SQLField) SetDistinct(distinct bool)
- func (f *SQLField) SetFunc(fn string)
- func (f *SQLField) SetName(name *Column)
- func (f *SQLField) SetTable(table string)
- func (f *SQLField) SetType(fieldType SQLFieldType)
- func (f *SQLField) SetValue(val any)
- func (f *SQLField) SetValueKind(kind byte)
- type SQLFieldType
- type SQLLimit
- type SQLOrderBy
- type SQLSelect
- type SQLTable
- type SelectParser
- type WhenClause
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_Arr_Agg string = "JSON_ARRAYAGG" SQLFuncName_Date string = "DATE" 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_Round string = "ROUND" SQLFuncName_If string = "IF" SQLFuncName_Case string = "CASE" SQLFuncName_Now string = "NOW" SQLFuncName_To_Double string = "TO_DOUBLE" SQLFuncName_To_Floor string = "FLOOR" SQLFuncName_Substring_Index string = "SUBSTRING_INDEX" )
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, SQLFuncName_Json_Arr_Agg: SQLFuncName_Json_Arr_Agg, } 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, SQLFuncName_If: SQLFuncName_If, SQLFuncName_Now: SQLFuncName_Now, SQLFuncName_To_Double: SQLFuncName_To_Double, SQLFuncName_To_Floor: SQLFuncName_To_Floor, SQLFuncName_Substring_Index: SQLFuncName_Substring_Index, SQLFuncName_Date: SQLFuncName_Date, } )
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 ExprField Right ExprField Not bool }
func (*BinaryOperation) GetArgs ¶ added in v1.0.4
func (b *BinaryOperation) GetArgs() []ExprField
func (*BinaryOperation) IsAllValue ¶ added in v1.0.4
func (b *BinaryOperation) IsAllValue() bool
type CaseWhenExpr ¶ added in v1.0.4
type CaseWhenExpr struct { SQLField WhenClauses []*WhenClause Else ExprField }
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 ExprField ¶ added in v1.0.4
type ExprField interface { GetType() SQLFieldType GetTable() string GetFunc() string GetDistinct() bool GetArgs() []ExprField GetColName() *Column GetColType() ColumnType GetName() string GetRawName() string GetAsName() string GetValueKind() byte GetValue() any SetType(SQLFieldType) SetTable(string) SetFunc(string) SetDistinct(bool) SetArgs([]ExprField) SetName(*Column) SetAsName(string) SetValueKind(byte) SetValue(any) HasDistinct() bool IsAllValue() bool }
type MySQLSelectParser ¶
type MySQLSelectParser struct {
// contains filtered or unexported fields
}
func (*MySQLSelectParser) GetOriginalSQL ¶
func (parser *MySQLSelectParser) GetOriginalSQL() string
type PatternLike ¶ added in v1.0.5
type SQLField ¶
type SQLField struct { Type SQLFieldType Table *string Func *string Distinct bool Args []ExprField Name *Column AsName *string ValueKind *byte Value any }
func (*SQLField) GetColName ¶ added in v1.0.4
func (*SQLField) GetColType ¶ added in v1.0.4
func (f *SQLField) GetColType() ColumnType
func (*SQLField) GetDistinct ¶ added in v1.0.4
func (*SQLField) GetRawName ¶ added in v1.0.4
func (*SQLField) GetType ¶ added in v1.0.4
func (f *SQLField) GetType() SQLFieldType
func (*SQLField) GetValueKind ¶ added in v1.0.4
func (*SQLField) HasDistinct ¶
func (*SQLField) IsAllValue ¶
func (*SQLField) SetDistinct ¶ added in v1.0.4
func (*SQLField) SetType ¶ added in v1.0.4
func (f *SQLField) SetType(fieldType SQLFieldType)
func (*SQLField) SetValueKind ¶ added in v1.0.4
type SQLFieldType ¶
type SQLFieldType int
type SQLOrderBy ¶
type SQLSelect ¶
type SQLSelect struct { Distinct bool Fields []ExprField From *SQLTable Where ExprField GroupBy []ExprField Having ExprField 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
type WhenClause ¶ added in v1.0.4
Click to show internal directories.
Click to hide internal directories.