Skip to content

Commit 72041b9

Browse files
kyleconroysbres
andauthored
feat(codegen): Insert comments in interfaces (#1458)
* feat(codegen): Insert comments in interfaces - Add docstring to interfaces to improve IDE method documentation * test: Update generated test code Co-authored-by: Stephane Bres <stephanejrbres@gmail.com>
1 parent 5842e84 commit 72041b9

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

examples/ondeck/postgresql/querier.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/codegen/golang/templates/pgx/interfaceCode.tmpl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,66 @@
33
{{- $dbtxParam := .EmitMethodsWithDBArgument -}}
44
{{- range .GoQueries}}
55
{{- if and (eq .Cmd ":one") ($dbtxParam) }}
6+
{{range .Comments}}//{{.}}
7+
{{end -}}
68
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error)
79
{{- else if eq .Cmd ":one" }}
10+
{{range .Comments}}//{{.}}
11+
{{end -}}
812
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error)
913
{{- end}}
1014
{{- if and (eq .Cmd ":many") ($dbtxParam) }}
15+
{{range .Comments}}//{{.}}
16+
{{end -}}
1117
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error)
1218
{{- else if eq .Cmd ":many" }}
19+
{{range .Comments}}//{{.}}
20+
{{end -}}
1321
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error)
1422
{{- end}}
1523
{{- if and (eq .Cmd ":exec") ($dbtxParam) }}
24+
{{range .Comments}}//{{.}}
25+
{{end -}}
1626
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) error
1727
{{- else if eq .Cmd ":exec" }}
28+
{{range .Comments}}//{{.}}
29+
{{end -}}
1830
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) error
1931
{{- end}}
2032
{{- if and (eq .Cmd ":execrows") ($dbtxParam) }}
33+
{{range .Comments}}//{{.}}
34+
{{end -}}
2135
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (int64, error)
2236
{{- else if eq .Cmd ":execrows" }}
37+
{{range .Comments}}//{{.}}
38+
{{end -}}
2339
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, error)
2440
{{- end}}
2541
{{- if and (eq .Cmd ":execresult") ($dbtxParam) }}
42+
{{range .Comments}}//{{.}}
43+
{{end -}}
2644
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (pgconn.CommandTag, error)
2745
{{- else if eq .Cmd ":execresult" }}
46+
{{range .Comments}}//{{.}}
47+
{{end -}}
2848
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (pgconn.CommandTag, error)
2949
{{- end}}
3050
{{- if and (eq .Cmd ":copyfrom") ($dbtxParam) }}
51+
{{range .Comments}}//{{.}}
52+
{{end -}}
3153
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.SlicePair}}) (int64, error)
3254
{{- else if eq .Cmd ":copyfrom" }}
55+
{{range .Comments}}//{{.}}
56+
{{end -}}
3357
{{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) (int64, error)
3458
{{- end}}
3559
{{- if and (or (eq .Cmd ":batchexec") (eq .Cmd ":batchmany") (eq .Cmd ":batchone")) ($dbtxParam) }}
60+
{{range .Comments}}//{{.}}
61+
{{end -}}
3662
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.SlicePair}}) *{{.MethodName}}BatchResults
3763
{{- else if or (eq .Cmd ":batchexec") (eq .Cmd ":batchmany") (eq .Cmd ":batchone") }}
64+
{{range .Comments}}//{{.}}
65+
{{end -}}
3866
{{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) *{{.MethodName}}BatchResults
3967
{{- end}}
4068

internal/codegen/golang/templates/stdlib/interfaceCode.tmpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,48 @@
33
{{- $dbtxParam := .EmitMethodsWithDBArgument -}}
44
{{- range .GoQueries}}
55
{{- if and (eq .Cmd ":one") ($dbtxParam) }}
6+
{{range .Comments}}//{{.}}
7+
{{end -}}
68
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error)
79
{{- else if eq .Cmd ":one"}}
10+
{{range .Comments}}//{{.}}
11+
{{end -}}
812
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error)
913
{{- end}}
1014
{{- if and (eq .Cmd ":many") ($dbtxParam) }}
15+
{{range .Comments}}//{{.}}
16+
{{end -}}
1117
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error)
1218
{{- else if eq .Cmd ":many"}}
19+
{{range .Comments}}//{{.}}
20+
{{end -}}
1321
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error)
1422
{{- end}}
1523
{{- if and (eq .Cmd ":exec") ($dbtxParam) }}
24+
{{range .Comments}}//{{.}}
25+
{{end -}}
1626
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) error
1727
{{- else if eq .Cmd ":exec"}}
28+
{{range .Comments}}//{{.}}
29+
{{end -}}
1830
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) error
1931
{{- end}}
2032
{{- if and (eq .Cmd ":execrows") ($dbtxParam) }}
33+
{{range .Comments}}//{{.}}
34+
{{end -}}
2135
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (int64, error)
2236
{{- else if eq .Cmd ":execrows"}}
37+
{{range .Comments}}//{{.}}
38+
{{end -}}
2339
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, error)
2440
{{- end}}
2541
{{- if and (eq .Cmd ":execresult") ($dbtxParam) }}
42+
{{range .Comments}}//{{.}}
43+
{{end -}}
2644
{{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (sql.Result, error)
2745
{{- else if eq .Cmd ":execresult"}}
46+
{{range .Comments}}//{{.}}
47+
{{end -}}
2848
{{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (sql.Result, error)
2949
{{- end}}
3050
{{- end}}

internal/endtoend/testdata/copyfrom/postgresql/pgx/go/querier.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)