Skip to content

SQL comments have one too many newlines for GoDocs #1393

Closed

Description

@danthegoodman1

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

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Jan 25, 2022
  2. kyleconroy commented on Jan 25, 2022

    @kyleconroy
    Collaborator

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

  3. danthegoodman1 commented on Jan 25, 2022

    @danthegoodman1
    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
    }
    
  4. danthegoodman1 commented on Jan 25, 2022

    @danthegoodman1
    Author

    I also added my config to the original message

  5. danthegoodman1 commented on Jan 25, 2022

    @danthegoodman1
    Author

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

  6. danthegoodman1 commented on Jan 25, 2022

    @danthegoodman1
    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.

  7. kyleconroy commented on Jan 26, 2022

    @kyleconroy
    Collaborator
  8. added and removed
    triageNew issues that hasn't been reviewed
    on Jan 26, 2022
  9. danthegoodman1 commented on Jan 26, 2022

    @danthegoodman1
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions