Skip to content
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

SQL comments have one too many newlines for GoDocs #1393

Closed
danthegoodman1 opened this issue Jan 25, 2022 · 7 comments · Fixed by #1395
Closed

SQL comments have one too many newlines for GoDocs #1393

danthegoodman1 opened this issue Jan 25, 2022 · 7 comments · Fixed by #1395
Labels
📚 postgresql bug Something isn't working

Comments

@danthegoodman1
Copy link

danthegoodman1 commented Jan 25, 2022

Version

1.11.0

What happened?

For example, if I have the table with the comment

-- name: IncrementPlayerTokens :exec
-- This function will increment the tokens and the rollover (will set roll0ver to 0 if it would be negative)
UPDATE players
SET tokens = tokens + $1,
rollover = (
  CASE
    WHEN rollover + $1 >= 0 THEN rollover + $1
    ELSE 0
  END
)
WHERE id = $2;

The following go code is generated:

// This function will increment the tokens and the rollover (will set roll0ver to 0 if it would be negative)

func (q *Queries) IncrementPlayerTokens(ctx context.Context, arg IncrementPlayerTokensParams) error {
	_, err := q.db.Exec(ctx, incrementPlayerTokens, arg.Tokens, arg.ID)
	return err
}

You can see there is an extra line between the comment and the function, which does not allow the comments to appear as godocs.

It would be sublime if that newline was removed so the comment and function were touching, thus being able to write godocs in the SQL :)

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

version: 1
packages:
  - path: "query"
    name: "query"
    engine: "postgresql"
    schema: "sqlcSchema.sql"
    queries: "./queries/"
    sql_package: "pgx/v4"

Playground URL

https://play.sqlc.dev/p/19da31cef1e9d4ce1385c4d620f2bcfad53be81567e1df81551f59e9fb8b39b8

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@danthegoodman1 danthegoodman1 added bug Something isn't working triage New issues that hasn't been reviewed labels Jan 25, 2022
@kyleconroy
Copy link
Collaborator

I can't reproduce this on the playground (here's my example). Can you include your configuration in the ticket?

@danthegoodman1
Copy link
Author

@kyleconroy This is the output I got:

const getAuthor = `-- name: GetAuthor :exec
UPDATE authors
SET NAME = $1
`

// This function will increment the tokens and the rollover (will set roll0ver to 0 if it would be negative)

func (q *Queries) GetAuthor(ctx context.Context, name string) error {
	_, err := q.db.Exec(ctx, getAuthor, name)
	return err
}

@danthegoodman1
Copy link
Author

I also added my config to the original message

@danthegoodman1
Copy link
Author

Weirdly enough I had one function that did properly space the comments and generated go function...

@danthegoodman1
Copy link
Author

@kyleconroy I can confirm it only happens with :exec and :many functions. With :one it spaces them fine, but when using :exec or :many it adds the additional newline between.

@kyleconroy
Copy link
Collaborator

@danthegoodman1
Copy link
Author

@kyleconroy Awesome, would it wait for a 1.12 release or a 1.11.1?

rliebz added a commit to rliebz/sqlc that referenced this issue Feb 7, 2022
The original fix (sqlc-dev#1395) for sqlc-dev#1393 did not cover the case where
`emit_methods_with_db_argument` was set to `true`. This follows the same
pattern to handle that case as well.
kyleconroy pushed a commit that referenced this issue Feb 8, 2022
The original fix (#1395) for #1393 did not cover the case where
`emit_methods_with_db_argument` was set to `true`. This follows the same
pattern to handle that case as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 postgresql bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants