Skip to content

Commit 9a2554f

Browse files
kevinburke1kyleconroy
authored andcommitted
internal/dinosql: fix multiline comment rendering (#142)
Previously if a SQL comment spanned multiple lines they'd all be run together like this: // Comment line one// Comment line two //Comment line three Instead, print each comment line on its own Go line. Update the tests to expose the problem and also test that it's fixed properly.
1 parent dc74575 commit 9a2554f

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

internal/dinosql/gen.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,8 @@ type {{.Ret.Type}} struct { {{- range .Ret.Struct.Fields}}
894894
{{end}}
895895
896896
{{if eq .Cmd ":one"}}
897-
{{range .Comments}}//{{.}}{{end}}
897+
{{range .Comments}}//{{.}}
898+
{{end -}}
898899
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ({{.Ret.Type}}, error) {
899900
{{- if $.EmitPreparedQueries}}
900901
row := q.queryRow(ctx, q.{{.FieldName}}, {{.ConstantName}}, {{.Arg.Params}})
@@ -908,7 +909,8 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ({{.Ret.Ty
908909
{{end}}
909910
910911
{{if eq .Cmd ":many"}}
911-
{{range .Comments}}//{{.}}{{end}}
912+
{{range .Comments}}//{{.}}
913+
{{end -}}
912914
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([]{{.Ret.Type}}, error) {
913915
{{- if $.EmitPreparedQueries}}
914916
rows, err := q.query(ctx, q.{{.FieldName}}, {{.ConstantName}}, {{.Arg.Params}})
@@ -938,7 +940,8 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([]{{.Ret.
938940
{{end}}
939941
940942
{{if eq .Cmd ":exec"}}
941-
{{range .Comments}}//{{.}}{{end}}
943+
{{range .Comments}}//{{.}}
944+
{{end -}}
942945
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) error {
943946
{{- if $.EmitPreparedQueries}}
944947
_, err := q.exec(ctx, q.{{.FieldName}}, {{.ConstantName}}, {{.Arg.Params}})
@@ -950,7 +953,8 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) error {
950953
{{end}}
951954
952955
{{if eq .Cmd ":execrows"}}
953-
{{range .Comments}}//{{.}}{{end}}
956+
{{range .Comments}}//{{.}}
957+
{{end -}}
954958
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, error) {
955959
{{- if $.EmitPreparedQueries}}
956960
result, err := q.exec(ctx, q.{{.FieldName}}, {{.ConstantName}}, {{.Arg.Params}})

internal/dinosql/testdata/ondeck/city.sql.go

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

internal/dinosql/testdata/ondeck/prepared/city.sql.go

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

internal/dinosql/testdata/ondeck/query/city.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ FROM city
99
WHERE slug = $1;
1010

1111
-- name: CreateCity :one
12-
-- Create a new city. The slug must be unique
12+
-- Create a new city. The slug must be unique.
13+
-- This is the second line of the comment
14+
-- This is the third line
1315
INSERT INTO city (
1416
name,
1517
slug

0 commit comments

Comments
 (0)