Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion docs/howto/rename.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sql:
queries: "postgresql/query.sql"
engine: "postgresql"
gen:
go:
go:
package: "authors"
out: "postgresql"
rename:
Expand Down Expand Up @@ -116,6 +116,28 @@ type Publisher 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
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
7 changes: 7 additions & 0 deletions internal/codegen/golang/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading