Skip to content

Commit ef33e92

Browse files
committed
format result for easier extension
1 parent f568efe commit ef33e92

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

ast/mappers.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,30 @@ func (s *Mappers) GetStmts(skipErrorQuery bool) ([]string, error) {
4343
return stmts, nil
4444
}
4545

46-
func (s *Mappers) GetStmtsWithFilePath(skipErrorQuery bool) (map[string] /*file path*/ []string /*sqls*/, error) {
46+
type StmtsInfo struct {
47+
FilePath string
48+
SQLs []string
49+
}
50+
51+
func (s *Mappers) GetStmtsWithFilePath(skipErrorQuery bool) ([]StmtsInfo, error) {
4752
ctx := NewContext()
4853
for _, m := range s.mappers {
4954
for id, node := range m.SqlNodes {
5055
ctx.Sqls[fmt.Sprintf("%v.%v", m.NameSpace, id)] = node
5156
}
5257
}
5358

54-
stmts := make(map[string][]string, 0)
59+
var stmts []StmtsInfo
5560
for _, m := range s.mappers {
5661
ctx.DefaultNamespace = m.NameSpace
5762
stmt, err := m.GetStmts(ctx, skipErrorQuery)
5863
if err != nil {
5964
return nil, fmt.Errorf("get sqls from mapper failed, namespace: %v, err: %v", m.NameSpace, err)
6065
}
61-
stmts[m.FilePath] = append(stmts[m.FilePath], stmt...)
66+
stmts = append(stmts, StmtsInfo{
67+
FilePath: m.FilePath,
68+
SQLs: stmt,
69+
})
6270
}
6371
return stmts, nil
6472
}

parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type XmlFiles struct {
7676

7777
// ParseXMLsWithFilePath is a parser for parse all query in several XML files to map[string][]string one by one;
7878
// you can set `skipErrorQuery` true to ignore invalid query.
79-
func ParseXMLsWithFilePath(dataFromFiles []XmlFiles, skipErrorQuery bool) (map[string] /*file path*/ []string /*sqls*/, error) {
79+
func ParseXMLsWithFilePath(dataFromFiles []XmlFiles, skipErrorQuery bool) ([]ast.StmtsInfo, error) {
8080
ms := ast.NewMappers()
8181
for _, data := range dataFromFiles {
8282
r := strings.NewReader(data.Content)

0 commit comments

Comments
 (0)