diff --git a/docs/howto/rename.md b/docs/howto/rename.md index dbc7f94aea..e76499bb9d 100644 --- a/docs/howto/rename.md +++ b/docs/howto/rename.md @@ -21,7 +21,7 @@ sql: queries: "postgresql/query.sql" engine: "postgresql" gen: - go: + go: package: "authors" out: "postgresql" rename: @@ -93,7 +93,29 @@ type Writer struct { } ``` +## Parameter Structure Names + +It is possible to rename the arguments a generated function would use. +For example, if you had a generated function called `FindWriter` +which used a generated name of `FindWriterParams`, you can choose to rename +this: + +```yaml +version: "2" +sql: + - engine: postgresql + queries: query.sql + schema: query.sql +overrides: + go: + rename: + FindWriterParams: SomeOtherNameParams +``` + +The target name must be unique, and even if multiple structures would +have the same fields, there will be a conflict. + ## Limitations Rename mappings apply to an entire package. Therefore, a column named `foo` and -a table name `foo` can't map to different rename values. \ No newline at end of file +a table name `foo` can't map to different rename values. diff --git a/internal/codegen/golang/result.go b/internal/codegen/golang/result.go index 515d0a654f..479e0675c4 100644 --- a/internal/codegen/golang/result.go +++ b/internal/codegen/golang/result.go @@ -353,7 +353,7 @@ func putOutColumns(query *plugin.Query) bool { // This is unlikely to happen, so don't fix it yet func columnsToStruct(req *plugin.GenerateRequest, options *opts.Options, name string, columns []goColumn, useID bool) (*Struct, error) { gs := Struct{ - Name: name, + Name: CheckRename(name, options), } seen := map[string][]int{} suffixes := map[int]int{} diff --git a/internal/codegen/golang/struct.go b/internal/codegen/golang/struct.go index ed9311800e..f33af554b5 100644 --- a/internal/codegen/golang/struct.go +++ b/internal/codegen/golang/struct.go @@ -16,6 +16,13 @@ type Struct struct { Comment string } +func CheckRename(name string, options *opts.Options) string { + if rename := options.Rename[name]; rename != "" { + return rename + } + return name +} + func StructName(name string, options *opts.Options) string { if rename := options.Rename[name]; rename != "" { return rename