parser

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2021 License: Apache-2.0 Imports: 9 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 {
	Parser  *parser.Parser
	Visitor *Visitor
}

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 fo given sql

func (*Parser) GetSQLID added in v0.3.5

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

func (*Parser) Parse

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

Parse parses sql and returns the result

func (*Parser) Split

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

Split splits multiple sqls into a slice

type Result

type Result struct {
	SQLType        string            `json:"sql_type"`
	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, 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) 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) GetTableNames added in v0.3.4

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

GetTableNames returns the table names

func (*Result) Marshal

func (r *Result) Marshal() ([]byte, error)

Marshal marshals result to json bytes

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...

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 the given node, traversal is over

Jump to

Keyboard shortcuts

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