util

package
v1.2210.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColumnOptionMap = map[ast.ColumnOptionType]string{
	ast.ColumnOptionNotNull:       "NOT NULL",
	ast.ColumnOptionNull:          "NULL",
	ast.ColumnOptionAutoIncrement: "AUTO_INCREMENT",
	ast.ColumnOptionPrimaryKey:    "PRIMARY KEY",
	ast.ColumnOptionUniqKey:       "UNIQUE KEY",
}

Functions

func AlterTableSpecFormat

func AlterTableSpecFormat(stmt *ast.AlterTableSpec) string

func AlterTableStmtFormat

func AlterTableStmtFormat(stmt *ast.AlterTableStmt) string

func CheckWhereFuzzySearch

func CheckWhereFuzzySearch(where ast.ExprNode) bool

Check is exist a full fuzzy query or a left fuzzy query. E.g: %name% or %name

func ExprFormat

func ExprFormat(node ast.ExprNode) string

func ExtractIndexFromCreateTableStmt

func ExtractIndexFromCreateTableStmt(table *ast.CreateTableStmt) map[string][]string

ExtractIndexFromCreateTableStmt extract index from create table statement.

func Fingerprint

func Fingerprint(oneSql string, isCaseSensitive bool) (fingerprint string, err error)

func GetAlterTableSpecByTp

func GetAlterTableSpecByTp(specs []*ast.AlterTableSpec, ts ...ast.AlterTableType) []*ast.AlterTableSpec

func GetLimitCount

func GetLimitCount(limit *ast.Limit, _default int64) (int64, error)

func GetNumberOfJoinTables

func GetNumberOfJoinTables(stmt *ast.Join) int

func GetPrimaryKey

func GetPrimaryKey(stmt *ast.CreateTableStmt) (map[string]struct{}, bool)

func GetTableFromOnCondition added in v1.2208.0

func GetTableFromOnCondition(stmt *ast.Join) []*ast.OnCondition

func GetTableNameWithQuote

func GetTableNameWithQuote(stmt *ast.TableName) string

func GetTableSources

func GetTableSources(stmt *ast.Join) []*ast.TableSource

func GetTables

func GetTables(stmt *ast.Join) []*ast.TableName

func HasOneInOptions

func HasOneInOptions(Options []*ast.ColumnOption, opTp ...ast.ColumnOptionType) bool

func HasPrimaryKey

func HasPrimaryKey(stmt *ast.CreateTableStmt) bool

func HasUniqIndex

func HasUniqIndex(stmt *ast.CreateTableStmt) bool

func IndexOptionFormat

func IndexOptionFormat(op *ast.IndexOption) string

func IsAllInOptions

func IsAllInOptions(Options []*ast.ColumnOption, opTp ...ast.ColumnOptionType) bool

func IsColumnImplicitConversionInWhereStmt

func IsColumnImplicitConversionInWhereStmt(colTypeMap map[string]string, where ast.ExprNode) bool

func IsFuncUsedOnColumnInWhereStmt

func IsFuncUsedOnColumnInWhereStmt(cols map[string]struct{}, where ast.ExprNode) bool

func MergeAlterToTable

func MergeAlterToTable(oldTable *ast.CreateTableStmt, alterTable *ast.AlterTableStmt) (*ast.CreateTableStmt, error)

func MysqlDataTypeIsBlob

func MysqlDataTypeIsBlob(tp byte) bool

func NewTableName

func NewTableName(schema, table string) *ast.TableName

func ParseCreateTableStmt

func ParseCreateTableStmt(sql string) (*ast.CreateTableStmt, error)

func ParseOneSql

func ParseOneSql(sql string) (ast.StmtNode, error)

func ParseSql

func ParseSql(sql string) ([]ast.StmtNode, error)

func RemoveArrayRepeat

func RemoveArrayRepeat(input []string) (output []string)

func ScanWhereStmt

func ScanWhereStmt(fn func(expr ast.ExprNode) (skip bool), exprs ...ast.ExprNode)

func TableExistCol

func TableExistCol(table *ast.CreateTableStmt, colName string) bool

func WhereStmtExistNot

func WhereStmtExistNot(where ast.ExprNode) bool

func WhereStmtExistScalarSubQueries

func WhereStmtExistScalarSubQueries(where ast.ExprNode) bool

func WhereStmtHasOneColumn

func WhereStmtHasOneColumn(where ast.ExprNode) bool

func WhereStmtHasSubQuery

func WhereStmtHasSubQuery(where ast.ExprNode) bool

Types

type CapitalizeProcessor

type CapitalizeProcessor struct {
	// contains filtered or unexported fields
}

CapitalizeProcessor implements ast.Visitor interface.

CapitalizeProcessor capitalize identifiers as needed.

format.RestoreNameUppercase can not control name comparisons accurate. CASE: Database/Table/Table-alias names are case-insensitive when lower_case_table_names equals 1. Some identifiers, such as Tablespace names are case-sensitive which not affected by lower_case_table_names. ref: https://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html

func (*CapitalizeProcessor) Enter

func (cp *CapitalizeProcessor) Enter(in ast.Node) (node ast.Node, skipChildren bool)

func (*CapitalizeProcessor) Leave

func (cp *CapitalizeProcessor) Leave(in ast.Node) (node ast.Node, ok bool)

type FingerprintVisitor

type FingerprintVisitor struct{}

FingerprintVisitor implements ast.Visitor interface.

func (*FingerprintVisitor) Enter

func (f *FingerprintVisitor) Enter(n ast.Node) (node ast.Node, skipChildren bool)

func (*FingerprintVisitor) Leave

func (f *FingerprintVisitor) Leave(n ast.Node) (node ast.Node, ok bool)

type ParamMarkerChecker added in v1.2208.0

type ParamMarkerChecker struct {
	HasParamMarker bool
}

func (*ParamMarkerChecker) Enter added in v1.2208.0

func (p *ParamMarkerChecker) Enter(in ast.Node) (node ast.Node, skipChildren bool)

func (*ParamMarkerChecker) Leave added in v1.2208.0

func (p *ParamMarkerChecker) Leave(in ast.Node) (node ast.Node, skipChildren bool)

type SelectStmtExtractor

type SelectStmtExtractor struct {
	SelectStmts []*ast.SelectStmt
}

func (*SelectStmtExtractor) Enter

func (se *SelectStmtExtractor) Enter(in ast.Node) (node ast.Node, skipChildren bool)

func (*SelectStmtExtractor) Leave

func (se *SelectStmtExtractor) Leave(in ast.Node) (node ast.Node, ok bool)

type SubQueryMaxNestNumExtractor added in v1.2209.0

type SubQueryMaxNestNumExtractor struct {
	MaxNestNum     *int
	CurrentNestNum int
}

func (*SubQueryMaxNestNumExtractor) Enter added in v1.2209.0

func (se *SubQueryMaxNestNumExtractor) Enter(in ast.Node) (node ast.Node, skipChildren bool)

func (*SubQueryMaxNestNumExtractor) Leave added in v1.2209.0

func (se *SubQueryMaxNestNumExtractor) Leave(in ast.Node) (node ast.Node, ok bool)

type TableChecker

type TableChecker struct {
	// contains filtered or unexported fields
}

func NewTableChecker

func NewTableChecker() *TableChecker

func (*TableChecker) Add

func (t *TableChecker) Add(schemaName, tableName string, table *ast.CreateTableStmt)

func (*TableChecker) CheckColumnByName

func (t *TableChecker) CheckColumnByName(colNameStmt *ast.ColumnName) (bool, bool)

type TableNameExtractor

type TableNameExtractor struct {
	TableNames map[string]*ast.TableName
}

TableNameExtractor implements ast.Visitor interface.

func (*TableNameExtractor) Enter

func (te *TableNameExtractor) Enter(in ast.Node) (node ast.Node, skipChildren bool)

func (*TableNameExtractor) Leave

func (te *TableNameExtractor) Leave(in ast.Node) (node ast.Node, ok bool)

type TableSourceExtractor added in v1.2207.0

type TableSourceExtractor struct {
	TableSources map[string]*ast.TableSource
}

func (*TableSourceExtractor) Enter added in v1.2207.0

func (ts *TableSourceExtractor) Enter(in ast.Node) (node ast.Node, skipChildren bool)

func (*TableSourceExtractor) Leave added in v1.2207.0

func (ts *TableSourceExtractor) Leave(in ast.Node) (node ast.Node, ok bool)

Jump to

Keyboard shortcuts

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