Skip to content

Commit

Permalink
add constant
Browse files Browse the repository at this point in the history
  • Loading branch information
hasa1K committed Jul 25, 2023
1 parent 30f97c7 commit e69bd14
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions sqle/cmd/scannerd/scanners/common/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

mybatisParser "github.com/actiontech/mybatis-mapper-2-sql"
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
"github.com/actiontech/sqle/sqle/cmd/scannerd/scanners"
)

func GetSQLFromPath(pathName string, skipErrorQuery, skipErrorFile bool, fileExtenssion string) (allSQL []driverV2.Node, err error) {
Expand Down Expand Up @@ -54,7 +55,7 @@ func GetSQLFromFile(file string, skipErrorQuery bool, fileExtenssion string) (r
return nil, err
}
switch fileExtenssion {
case "xml":
case scanners.MybatisFileExtension:
sqls, err := mybatisParser.ParseXMLQuery(content, skipErrorQuery)
if err != nil {
return nil, err
Expand All @@ -66,7 +67,7 @@ func GetSQLFromFile(file string, skipErrorQuery bool, fileExtenssion string) (r
}
r = append(r, n...)
}
case "sql":
case scanners.SQLFileExtension:
n, err := Parse(context.TODO(), content)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion sqle/cmd/scannerd/scanners/common/interface_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/actiontech/sqle/sqle/pkg/scanner"
)

func Upload(ctx context.Context, sqls []scanners.SQL, c *scanner.Client, apName string, skipAudit bool) error {
func UploadAndAudit(ctx context.Context, sqls []scanners.SQL, c *scanner.Client, apName string, skipAudit bool) error {
// key=fingerPrint val=count
counterMap := make(map[string]uint, len(sqls))

Expand Down
4 changes: 2 additions & 2 deletions sqle/cmd/scannerd/scanners/mybatis/mybatis.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func New(params *Params, l *logrus.Entry, c *scanner.Client) (*MyBatis, error) {
}

func (mb *MyBatis) Run(ctx context.Context) error {
sqls, err := common.GetSQLFromPath(mb.xmlDir, mb.skipErrorQuery, mb.skipErrorXml, "xml")
sqls, err := common.GetSQLFromPath(mb.xmlDir, mb.skipErrorQuery, mb.skipErrorXml, scanners.MybatisFileExtension)
if err != nil {
return err
}
Expand Down Expand Up @@ -80,5 +80,5 @@ func (mb *MyBatis) SQLs() <-chan scanners.SQL {

func (mb *MyBatis) Upload(ctx context.Context, sqls []scanners.SQL) error {
mb.sqls = append(mb.sqls, sqls...)
return common.Upload(ctx, mb.sqls, mb.c, mb.apName, mb.skipAudit)
return common.UploadAndAudit(ctx, mb.sqls, mb.c, mb.apName, mb.skipAudit)
}
5 changes: 5 additions & 0 deletions sqle/cmd/scannerd/scanners/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"context"
)

const (
MybatisFileExtension = "xml"
SQLFileExtension = "sql"
)

type SQL struct {
Fingerprint string
RawText string
Expand Down
4 changes: 2 additions & 2 deletions sqle/cmd/scannerd/scanners/sqlfile/sqlfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func New(params *Params, l *logrus.Entry, c *scanner.Client) (*SQLFile, error) {
}

func (sf *SQLFile) Run(ctx context.Context) error {
sqls, err := common.GetSQLFromPath(sf.sqlDir, false, sf.skipErrorSqlFile, "sql")
sqls, err := common.GetSQLFromPath(sf.sqlDir, false, sf.skipErrorSqlFile, scanners.SQLFileExtension)
if err != nil {
return err
}
Expand Down Expand Up @@ -78,5 +78,5 @@ func (sf *SQLFile) SQLs() <-chan scanners.SQL {

func (sf *SQLFile) Upload(ctx context.Context, sqls []scanners.SQL) error {
sf.sqls = append(sf.sqls, sqls...)
return common.Upload(ctx, sf.sqls, sf.c, sf.apName, sf.skipAudit)
return common.UploadAndAudit(ctx, sf.sqls, sf.c, sf.apName, sf.skipAudit)
}

0 comments on commit e69bd14

Please sign in to comment.