parser

package
v0.0.0-...-29fe790 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: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSQLList = []string{
		"*ast.CreateTableStmt",
		"*ast.AlterTableStmt",
		"*ast.DropTableStmt",
		"*ast.SelectStmt",
		"*ast.UnionStmt",
		"*ast.InsertStmt",
		"*ast.ReplaceStmt",
		"*ast.InsertStmt",
		"*ast.UpdateStmt",
		"*ast.DeleteStmt",
	}
	DefaultFuncList = []string{
		"*ast.FuncCallExpr",
		"*ast.AggregateFuncExpr",
		"*ast.WindowFuncExpr",
	}
)

Functions

This section is empty.

Types

type Parser

type Parser struct {
	Parser  *parser.Parser
	Visitor *Visitor
}

func NewParser

func NewParser() *Parser

NewParser returns a new *Parser

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"`
	ColumnComments map[string]string `json:"column_comments"`
	Tp             []int
}

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, columnComments map[string]string) *Result

NewResult returns a new *Result

func (*Result) Marshal

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

Marshal marshals result to json bytes

type Visitor

type Visitor struct {
	ToParse  bool
	SQLList  []string
	FuncList []string
	Result   *Result
}

func NewVisitor

func NewVisitor() *Visitor

func (*Visitor) AddColumn

func (v *Visitor) AddColumn(columnName string)

func (*Visitor) AddColumnComment

func (v *Visitor) AddColumnComment(columnName string, columnComment string)

func (*Visitor) AddDB

func (v *Visitor) AddDB(dbName string)

func (*Visitor) AddTable

func (v *Visitor) AddTable(tableName string)

func (*Visitor) AddTableComment

func (v *Visitor) AddTableComment(tableName string, tableComment string)

func (*Visitor) Enter

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

func (*Visitor) Leave

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

Jump to

Keyboard shortcuts

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