parser

package
v0.3.19 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CreateTableStmtString = "*ast.CreateTableStmt"
	AlterTableStmtString  = "*ast.AlterTableStmt"
	DropTableStmtString   = "*ast.DropTableStmt"
	SelectStmtString      = "*ast.SelectStmt"
	UnionStmtString       = "*ast.UnionStmt"
	InsertStmtString      = "*ast.InsertStmt"
	ReplaceStmtString     = "*ast.ReplaceStmt"
	UpdateStmtString      = "*ast.UpdateStmt"
	DeleteStmtString      = "*ast.DeleteStmt"

	FuncCallExprString      = "*ast.FuncCallExpr"
	AggregateFuncExprString = "*ast.AggregateFuncExpr"
	WindowFuncExprString    = "*ast.WindowFuncExpr"
)

Variables

Functions

This section is empty.

Types

type Parser

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

func NewParser

func NewParser(visitor *Visitor) *Parser

NewParser returns a new *Parser

func NewParserWithDefault added in v0.3.4

func NewParserWithDefault() *Parser

NewParserWithDefault returns a new *Parser with default visitor

func (*Parser) GetFingerprint added in v0.3.5

func (p *Parser) GetFingerprint(sql string) string

GetFingerprint returns fingerprint of the given sql

func (*Parser) GetSQLID added in v0.3.5

func (p *Parser) GetSQLID(sql string) string

GetSQLID returns the sql id of the given sql

func (*Parser) GetStatementNodes added in v0.3.8

func (p *Parser) GetStatementNodes(sql string) ([]ast.StmtNode, error)

GetStatementNodes gets the statement nodes of the given sql

func (*Parser) GetTiDBParser added in v0.3.6

func (p *Parser) GetTiDBParser() *parser.Parser

GetTiDBParser returns the TiDB parser

func (*Parser) GetVisitor added in v0.3.6

func (p *Parser) GetVisitor() *Visitor

GetVisitor returns the visitor

func (*Parser) MergeDDLStatements added in v0.3.8

func (p *Parser) MergeDDLStatements(sqls ...string) ([]string, error)

MergeDDLStatements merges ddl statements by table names. note that only alter table statement and create index statement will be merged, inputting other sql statements will return error, each argument in the input sqls could contain multiple sql statements

func (*Parser) Parse

func (p *Parser) Parse(sql string) (*Result, error)

Parse parses sql and returns the result, not that only some kinds of statements will be parsed, see the constants defined at the top of visitor.go file

func (*Parser) RemoveSQLComments added in v0.3.10

func (p *Parser) RemoveSQLComments(sql string) string

RemoveSQLComments removes comments of the sql

func (*Parser) Split

func (p *Parser) Split(multiSQL string) ([]string, error)

Split splits multiple sql statements into a slice

type Result

type Result struct {
	SQLType        string              `json:"sql_type"`
	TableDBListMap map[string][]string `json:"table_db_list_map"`
	DBNames        []string            `json:"db_names"`
	TableNames     []string            `json:"table_names"`
	TableComments  map[string]string   `json:"table_comments"`
	ColumnNames    []string            `json:"column_names"`
	ColumnTypes    map[string]string   `json:"column_types"`
	ColumnComments map[string]string   `json:"column_comments"`
}

func NewEmptyResult

func NewEmptyResult() *Result

NewEmptyResult returns an empty *Result

func NewResult

func NewResult(sqlType string, TableDBListMap map[string][]string, dbNames []string, tableNames []string,
	tableComments map[string]string, columnNames []string, columnTypes map[string]string,
	columnComments map[string]string) *Result

NewResult returns a new *Result

func (*Result) AddColumn added in v0.3.4

func (r *Result) AddColumn(columnName string)

AddColumn adds column name to the result

func (*Result) AddDBName added in v0.3.4

func (r *Result) AddDBName(dbName string)

AddDBName adds db name to the result

func (*Result) AddTableDBListMap added in v0.3.11

func (r *Result) AddTableDBListMap(tableName string, dbName string)

AddTableDBListMap adds db name to the result

func (*Result) AddTableName added in v0.3.4

func (r *Result) AddTableName(tableName string)

AddTableName adds table name to the result

func (*Result) GetColumnComments added in v0.3.4

func (r *Result) GetColumnComments() map[string]string

GetColumnComments returns the column comments

func (*Result) GetColumnNames added in v0.3.4

func (r *Result) GetColumnNames() []string

GetColumnNames returns the column names

func (*Result) GetColumnTypes added in v0.3.5

func (r *Result) GetColumnTypes() map[string]string

GetColumnTypes returns the column types

func (*Result) GetDBNames added in v0.3.4

func (r *Result) GetDBNames() []string

GetDBNames returns the db names

func (*Result) GetSQLType added in v0.3.4

func (r *Result) GetSQLType() string

GetSQLType returns the sql type

func (*Result) GetTableComments added in v0.3.4

func (r *Result) GetTableComments() map[string]string

GetTableComments returns the table comments

func (*Result) GetTableDBListMap added in v0.3.11

func (r *Result) GetTableDBListMap() map[string][]string

GetTableDBListMap returns table db list map

func (*Result) GetTableNames added in v0.3.4

func (r *Result) GetTableNames() []string

GetTableNames returns the table names

func (*Result) SetColumnComment added in v0.3.4

func (r *Result) SetColumnComment(columnName string, columnComment string)

SetColumnComment sets column comment of corresponding column

func (*Result) SetColumnType added in v0.3.5

func (r *Result) SetColumnType(columnName string, columnType string)

SetColumnType sets column type of corresponding column

func (*Result) SetSQLType added in v0.3.4

func (r *Result) SetSQLType(sqlType string)

SetSQLType sets the sql type

func (*Result) SetTableComment added in v0.3.4

func (r *Result) SetTableComment(tableName string, tableComment string)

SetTableComment sets table comment of corresponding table

type Visitor

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

func NewVisitor

func NewVisitor(sqlList, funcList []string) *Visitor

NewVisitor returns a new *Visitor

func NewVisitorWithDefault added in v0.3.4

func NewVisitorWithDefault() *Visitor

NewVisitorWithDefault returns a new *Visitor with default sql list and function list

func (*Visitor) Enter

func (v *Visitor) Enter(in ast.Node) (out ast.Node, skipChildren bool)

Enter enters into the given node, it will traverse each child node to find useful information such as table name, column name... note that it only traverses some kinds of node types, see the constants at the top of this file

func (*Visitor) GetFuncList added in v0.3.4

func (v *Visitor) GetFuncList() []string

GetFuncList returns the function list

func (*Visitor) GetResult added in v0.3.4

func (v *Visitor) GetResult() *Result

GetResult returns the result

func (*Visitor) GetSQLList added in v0.3.4

func (v *Visitor) GetSQLList() []string

GetSQLList returns the sql list

func (*Visitor) Leave

func (v *Visitor) Leave(in ast.Node) (out ast.Node, ok bool)

Leave leaves the given node, traversal is over

Jump to

Keyboard shortcuts

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