Documentation ¶
Index ¶
- Constants
- Variables
- type Parser
- func (p *Parser) GetFingerprint(sql string) string
- func (p *Parser) GetSQLID(sql string) string
- func (p *Parser) GetStatementNodes(sql string) ([]ast.StmtNode, error)
- func (p *Parser) GetTiDBParser() *parser.Parser
- func (p *Parser) GetVisitor() *Visitor
- func (p *Parser) MergeDDLStatements(sqls ...string) ([]string, error)
- func (p *Parser) Parse(sql string) (*Result, error)
- func (p *Parser) RemoveSQLComments(sql string) string
- func (p *Parser) Split(multiSQL string) ([]string, error)
- type Result
- func (r *Result) AddColumn(columnName string)
- func (r *Result) AddDBName(dbName string)
- func (r *Result) AddTableDBListMap(tableName string, dbName string)
- func (r *Result) AddTableName(tableName string)
- func (r *Result) GetColumnComments() map[string]string
- func (r *Result) GetColumnNames() []string
- func (r *Result) GetColumnTypes() map[string]string
- func (r *Result) GetDBNames() []string
- func (r *Result) GetSQLType() string
- func (r *Result) GetTableComments() map[string]string
- func (r *Result) GetTableDBListMap() map[string][]string
- func (r *Result) GetTableNames() []string
- func (r *Result) SetColumnComment(columnName string, columnComment string)
- func (r *Result) SetColumnType(columnName string, columnType string)
- func (r *Result) SetSQLType(sqlType string)
- func (r *Result) SetTableComment(tableName string, tableComment string)
- type Visitor
Constants ¶
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 ¶
var ( DefaultSQLList = []string{ CreateTableStmtString, AlterTableStmtString, DropTableStmtString, SelectStmtString, UnionStmtString, InsertStmtString, ReplaceStmtString, UpdateStmtString, DeleteStmtString, } DefaultFuncList = []string{ FuncCallExprString, AggregateFuncExprString, WindowFuncExprString, } )
Functions ¶
This section is empty.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
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
GetFingerprint returns fingerprint of the given sql
func (*Parser) GetStatementNodes ¶ added in v0.3.8
GetStatementNodes gets the statement nodes of the given sql
func (*Parser) GetTiDBParser ¶ added in v0.3.6
GetTiDBParser returns the TiDB parser
func (*Parser) GetVisitor ¶ added in v0.3.6
GetVisitor returns the visitor
func (*Parser) MergeDDLStatements ¶ added in v0.3.8
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 ¶
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
RemoveSQLComments removes comments of the sql
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 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) AddTableDBListMap ¶ added in v0.3.11
AddTableDBListMap adds db name to the result
func (*Result) AddTableName ¶ added in v0.3.4
AddTableName adds table name to the result
func (*Result) GetColumnComments ¶ added in v0.3.4
GetColumnComments returns the column comments
func (*Result) GetColumnNames ¶ added in v0.3.4
GetColumnNames returns the column names
func (*Result) GetColumnTypes ¶ added in v0.3.5
GetColumnTypes returns the column types
func (*Result) GetDBNames ¶ added in v0.3.4
GetDBNames returns the db names
func (*Result) GetSQLType ¶ added in v0.3.4
GetSQLType returns the sql type
func (*Result) GetTableComments ¶ added in v0.3.4
GetTableComments returns the table comments
func (*Result) GetTableDBListMap ¶ added in v0.3.11
GetTableDBListMap returns table db list map
func (*Result) GetTableNames ¶ added in v0.3.4
GetTableNames returns the table names
func (*Result) SetColumnComment ¶ added in v0.3.4
SetColumnComment sets column comment of corresponding column
func (*Result) SetColumnType ¶ added in v0.3.5
SetColumnType sets column type of corresponding column
func (*Result) SetSQLType ¶ added in v0.3.4
SetSQLType sets the sql type
func (*Result) SetTableComment ¶ added in v0.3.4
SetTableComment sets table comment of corresponding table
type Visitor ¶
type Visitor struct {
// contains filtered or unexported fields
}
func NewVisitor ¶
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 ¶
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
GetFuncList returns the function list
func (*Visitor) GetSQLList ¶ added in v0.3.4
GetSQLList returns the sql list