From bb25ba9a698c908655b9a6231d86b4a416581c51 Mon Sep 17 00:00:00 2001 From: Stephane Bres Date: Mon, 21 Feb 2022 20:17:47 +0000 Subject: [PATCH] feat(codegen): Insert comments in interfaces - Add docstring to interfaces to improve IDE method documentation --- .../golang/templates/pgx/interfaceCode.tmpl | 28 +++++++++++++++++++ .../templates/stdlib/interfaceCode.tmpl | 20 +++++++++++++ 2 files changed, 48 insertions(+) diff --git a/internal/codegen/golang/templates/pgx/interfaceCode.tmpl b/internal/codegen/golang/templates/pgx/interfaceCode.tmpl index 705963b48d..cf7cd36cb9 100644 --- a/internal/codegen/golang/templates/pgx/interfaceCode.tmpl +++ b/internal/codegen/golang/templates/pgx/interfaceCode.tmpl @@ -3,38 +3,66 @@ {{- $dbtxParam := .EmitMethodsWithDBArgument -}} {{- range .GoQueries}} {{- if and (eq .Cmd ":one") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error) {{- else if eq .Cmd ":one" }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error) {{- end}} {{- if and (eq .Cmd ":many") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error) {{- else if eq .Cmd ":many" }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error) {{- end}} {{- if and (eq .Cmd ":exec") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) error {{- else if eq .Cmd ":exec" }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) error {{- end}} {{- if and (eq .Cmd ":execrows") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (int64, error) {{- else if eq .Cmd ":execrows" }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, error) {{- end}} {{- if and (eq .Cmd ":execresult") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (pgconn.CommandTag, error) {{- else if eq .Cmd ":execresult" }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (pgconn.CommandTag, error) {{- end}} {{- if and (eq .Cmd ":copyfrom") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.SlicePair}}) (int64, error) {{- else if eq .Cmd ":copyfrom" }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) (int64, error) {{- end}} {{- if and (or (eq .Cmd ":batchexec") (eq .Cmd ":batchmany") (eq .Cmd ":batchone")) ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.SlicePair}}) *{{.MethodName}}BatchResults {{- else if or (eq .Cmd ":batchexec") (eq .Cmd ":batchmany") (eq .Cmd ":batchone") }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) *{{.MethodName}}BatchResults {{- end}} diff --git a/internal/codegen/golang/templates/stdlib/interfaceCode.tmpl b/internal/codegen/golang/templates/stdlib/interfaceCode.tmpl index 67c31b817a..3b59479801 100644 --- a/internal/codegen/golang/templates/stdlib/interfaceCode.tmpl +++ b/internal/codegen/golang/templates/stdlib/interfaceCode.tmpl @@ -3,28 +3,48 @@ {{- $dbtxParam := .EmitMethodsWithDBArgument -}} {{- range .GoQueries}} {{- if and (eq .Cmd ":one") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error) {{- else if eq .Cmd ":one"}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error) {{- end}} {{- if and (eq .Cmd ":many") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error) {{- else if eq .Cmd ":many"}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error) {{- end}} {{- if and (eq .Cmd ":exec") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) error {{- else if eq .Cmd ":exec"}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) error {{- end}} {{- if and (eq .Cmd ":execrows") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (int64, error) {{- else if eq .Cmd ":execrows"}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, error) {{- end}} {{- if and (eq .Cmd ":execresult") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (sql.Result, error) {{- else if eq .Cmd ":execresult"}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (sql.Result, error) {{- end}} {{- end}}