Skip to content

Consistent whitespace handling in Go query template #1301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 24, 2021

Conversation

wabain
Copy link
Contributor

@wabain wabain commented Nov 21, 2021

This PR reverts an extra line of whitespace in generated output which snuck in with #1279. This only applied to :execrows using prepared queries, where in one conditional branch there were two spots where whitespace wasn't removed, versus a single spot for the other branches.

…
{{end -}} // leading whitespace here
    {{- if $.EmitPreparedQueries}} // trailing whitespace here
    result, err := q.exec(ctx, q.{{.FieldName}}, {{.ConstantName}}, {{.Arg.Params}})
    {{- else if $.EmitMethodsWithDBArgument -}} // no trailing whitespace here

Rather than try to add tests for all of the possible configurations in this pull request, I've made sure all the branches in if/else constructs in the template use consistent whitespace escapes so that if there's extra whitespace it will show up in tests regardless of what branch is taken.

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for the execrows and prepared queries case?

@wabain
Copy link
Contributor Author

wabain commented Nov 21, 2021

Added a test which generates the different kinds of queries using emit_prepared_queries.

@wabain wabain requested a review from kyleconroy November 22, 2021 00:07
@kyleconroy kyleconroy merged commit 4bbe1ca into sqlc-dev:main Nov 24, 2021
@wabain wabain deleted the exec-whitespace branch November 24, 2021 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants