Skip to content

Commit

Permalink
生SQLを出力に追加
Browse files Browse the repository at this point in the history
  • Loading branch information
mazrean committed Aug 24, 2024
1 parent f28c31b commit e634db3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dbdoc/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func AnalyzeSQL(ctx *Context, sql stringLiteral) []Query {
for _, sqlValue := range strQueries {
newQueries := analyzeSQLWithoutSubQuery(ctx, sqlValue, sql.pos)
for _, query := range newQueries {
fmt.Printf("%s(%s): %s\n", query.QueryType, query.Table, sqlValue)
fmt.Println(query)
}
queries = append(queries, newQueries...)
}
Expand Down Expand Up @@ -114,6 +114,7 @@ func analyzeSQLWithoutSubQuery(ctx *Context, sqlValue string, pos token.Pos) []Q
QueryType: QueryTypeSelect,
Table: tableName,
Pos: pos,
Raw: sqlValue,
})
}
break
Expand Down Expand Up @@ -144,6 +145,7 @@ func analyzeSQLWithoutSubQuery(ctx *Context, sqlValue string, pos token.Pos) []Q
QueryType: QueryTypeSelect,
Table: matches[i],
Pos: pos,
Raw: sqlValue,
})
}
}
Expand All @@ -157,6 +159,7 @@ func analyzeSQLWithoutSubQuery(ctx *Context, sqlValue string, pos token.Pos) []Q
QueryType: QueryTypeInsert,
Table: matches[i],
Pos: pos,
Raw: sqlValue,
})
}
}
Expand Down Expand Up @@ -185,6 +188,7 @@ func analyzeSQLWithoutSubQuery(ctx *Context, sqlValue string, pos token.Pos) []Q
QueryType: QueryTypeUpdate,
Table: matches[i],
Pos: pos,
Raw: sqlValue,
})
}
}
Expand All @@ -198,6 +202,7 @@ func analyzeSQLWithoutSubQuery(ctx *Context, sqlValue string, pos token.Pos) []Q
QueryType: QueryTypeDelete,
Table: matches[i],
Pos: pos,
Raw: sqlValue,
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions dbdoc/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dbdoc

import (
"fmt"
"go/token"
)

Expand Down Expand Up @@ -61,6 +62,11 @@ type Query struct {
QueryType QueryType
Table string
Pos token.Pos
Raw string
}

func (q Query) String() string {
return fmt.Sprintf("%s:%s:%s", q.QueryType, q.Table, q.Raw)
}

type QueryType uint8
Expand Down

0 comments on commit e634db3

Please sign in to comment.