parser

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 10 Imported by: 0

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_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 (
	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

func (*MySQLSelectParser) Parse

func (parser *MySQLSelectParser) Parse(strictMode bool) (sql SQL, err error)

type PatternLike added in v1.0.5

type PatternLike struct {
	SQLField
	Left  ExprField
	Right ExprField
	Not   bool
}

type SQL

type SQL interface {
	// 获取原始SQL
	OriginalSQL() string
}

代表一个SQL对象

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) Copy

func (f *SQLField) Copy(source *SQLField)

func (*SQLField) GetArgs added in v1.0.4

func (f *SQLField) GetArgs() []ExprField

func (SQLField) GetAsName

func (f SQLField) GetAsName() string

func (*SQLField) GetColName added in v1.0.4

func (f *SQLField) GetColName() *Column

func (*SQLField) GetColType added in v1.0.4

func (f *SQLField) GetColType() ColumnType

func (*SQLField) GetDistinct added in v1.0.4

func (f *SQLField) GetDistinct() bool

func (*SQLField) GetFunc added in v1.0.4

func (f *SQLField) GetFunc() string

func (SQLField) GetName

func (f SQLField) GetName() string

func (*SQLField) GetRawName added in v1.0.4

func (f *SQLField) GetRawName() string

func (*SQLField) GetTable added in v1.0.4

func (f *SQLField) GetTable() string

func (*SQLField) GetType added in v1.0.4

func (f *SQLField) GetType() SQLFieldType

func (*SQLField) GetValue added in v1.0.4

func (f *SQLField) GetValue() any

func (*SQLField) GetValueKind added in v1.0.4

func (f *SQLField) GetValueKind() byte

func (*SQLField) HasDistinct

func (f *SQLField) HasDistinct() bool

func (*SQLField) IsAllValue

func (f *SQLField) IsAllValue() bool

func (*SQLField) SetArgs added in v1.0.4

func (f *SQLField) SetArgs(args []ExprField)

func (*SQLField) SetAsName added in v1.0.4

func (f *SQLField) SetAsName(asName string)

func (*SQLField) SetDistinct added in v1.0.4

func (f *SQLField) SetDistinct(distinct bool)

func (*SQLField) SetFunc added in v1.0.4

func (f *SQLField) SetFunc(fn string)

func (*SQLField) SetName added in v1.0.4

func (f *SQLField) SetName(name *Column)

func (*SQLField) SetTable added in v1.0.4

func (f *SQLField) SetTable(table string)

func (*SQLField) SetType added in v1.0.4

func (f *SQLField) SetType(fieldType SQLFieldType)

func (*SQLField) SetValue added in v1.0.4

func (f *SQLField) SetValue(val any)

func (*SQLField) SetValueKind added in v1.0.4

func (f *SQLField) SetValueKind(kind byte)

type SQLFieldType

type SQLFieldType int

type SQLLimit

type SQLLimit struct {
	Limit  *int64
	Offset *int64
}

type SQLOrderBy

type SQLOrderBy struct {
	SQLField
	Desc bool
}

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

func (s SQLSelect) OriginalSQL() string

type SQLTable

type SQLTable struct {
	Name        *string
	AsName      *string
	TableSchema map[string][]*Column
	Ref         *SQLSelect
	Left        *SQLTable
	Right       *SQLTable
	On          ExprField
}

func (SQLTable) GetAsName

func (t SQLTable) GetAsName() string

type SelectParser

type SelectParser interface {
	// 返回SQL元数据
	Parse(strictMode bool) (SQL, error)
}

SQL解析器,包含:语法树解析、语法校验、优化改写

func NewMySQLSelectParser

func NewMySQLSelectParser(sql string, tableSchema map[string][]*Column) SelectParser

type WhenClause added in v1.0.4

type WhenClause struct {
	Expr   ExprField
	Result ExprField
}

Jump to

Keyboard shortcuts

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