parser

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 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_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 (
	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 SQL

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

代表一个SQL对象

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

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

func (SQLField) GetAsName

func (f SQLField) GetAsName() string

func (SQLField) GetName

func (f SQLField) GetName() string

func (SQLField) HasDistinct

func (f SQLField) HasDistinct() bool

func (SQLField) IsAllValue

func (f SQLField) IsAllValue() bool

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   []*SQLField
	From     *SQLTable
	Where    *BinaryOperation
	GroupBy  []*SQLField
	Having   *BinaryOperation
	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          *BinaryOperation
}

func (SQLTable) GetAsName

func (t SQLTable) GetAsName() string

type SelectParser

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

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

func NewMySQLSelectParser

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

Jump to

Keyboard shortcuts

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