Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:extract table comments #1235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
Loading