From 672d4911b9fe84c1a33dd844abe84882e6ccd55a Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Mon, 10 Mar 2025 21:40:18 -0500 Subject: [PATCH 1/3] allow renaming function Params structs --- internal/codegen/golang/result.go | 2 +- internal/codegen/golang/struct.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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..596c883f9e 100644 --- a/internal/codegen/golang/struct.go +++ b/internal/codegen/golang/struct.go @@ -1,6 +1,7 @@ package golang import ( + "log/slog" "strings" "unicode" "unicode/utf8" @@ -16,6 +17,14 @@ type Struct struct { Comment string } +func CheckRename(name string, options *opts.Options) string { + if rename := options.Rename[name]; rename != "" { + slog.Info("CheckRename", slog.String("original", name), slog.String("rename", rename)) + return rename + } + return name +} + func StructName(name string, options *opts.Options) string { if rename := options.Rename[name]; rename != "" { return rename From 7ba1d6613d2fefea18046c01a3961fe112951cc6 Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Mon, 10 Mar 2025 21:46:56 -0500 Subject: [PATCH 2/3] remove debugging --- internal/codegen/golang/struct.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/codegen/golang/struct.go b/internal/codegen/golang/struct.go index 596c883f9e..f33af554b5 100644 --- a/internal/codegen/golang/struct.go +++ b/internal/codegen/golang/struct.go @@ -1,7 +1,6 @@ package golang import ( - "log/slog" "strings" "unicode" "unicode/utf8" @@ -19,7 +18,6 @@ type Struct struct { func CheckRename(name string, options *opts.Options) string { if rename := options.Rename[name]; rename != "" { - slog.Info("CheckRename", slog.String("original", name), slog.String("rename", rename)) return rename } return name From 567d8bd92eb4ebfdcb3354799059e8e43a38e1ec Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Mon, 10 Mar 2025 21:54:01 -0500 Subject: [PATCH 3/3] docs --- docs/howto/rename.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) 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.