Skip to content

Commit

Permalink
feat:extract table comments
Browse files Browse the repository at this point in the history
  • Loading branch information
WaterCool8258 committed Nov 14, 2024
1 parent 1c60357 commit 6c23f8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/generate/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (b *QueryStructMeta) ReviseDIYMethod() error {
}
if tableName == nil {
methods = append(methods, parser.DefaultMethodTableName(b.ModelStructName))
methods = append(methods, parser.DefaultMethodTableComment(b.ModelStructName, b.TableComment))
} else {
// e.g. return "@@table" => return TableNameUser
tableName.Body = strings.ReplaceAll(tableName.Body, "\"@@table\"", "TableName"+b.ModelStructName)
Expand Down
10 changes: 10 additions & 0 deletions internal/parser/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ func DefaultMethodTableName(structName string) *Method {
}
}

func DefaultMethodTableComment(structName, comment string) *Method {

Check failure on line 22 in internal/parser/method.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 exported: exported function DefaultMethodTableComment should have comment or be unexported (revive) Raw Output: internal/parser/method.go:22:1: exported: exported function DefaultMethodTableComment should have comment or be unexported (revive) func DefaultMethodTableComment(structName, comment string) *Method { ^
return &Method{
Receiver: Param{IsPointer: true, Type: structName},
MethodName: "TableComment",
Doc: fmt.Sprint("TableComment ", structName, "'s table comment "),
Result: []Param{{Type: "string"}},
Body: fmt.Sprintf("{\n\treturn `%s`\n} ", comment),
}
}

// Method Apply to query struct and base struct custom method
type Method struct {
Receiver Param
Expand Down

0 comments on commit 6c23f8a

Please sign in to comment.