Skip to content

Positional arguments in generated Go function #1496

@brentd

Description

@brentd

The docs have this example:

CREATE TABLE authors (
  id         SERIAL PRIMARY KEY,
  bio        text   NOT NULL
);

-- name: UpdateAuthor :exec
UPDATE authors SET bio = $2
WHERE id = $1;

Which is documented as generating the following function with positional parameters:

func (q *Queries) UpdateAuthor(ctx context.Context, id int, bio string) error {
	_, err := q.db.ExecContext(ctx, updateAuthor, id, bio)
	return err
}

However the latest version of sqlc (v1.12.0) generates this:

type UpdateAuthorParams struct {
	ID  int32
	Bio string
}

func (q *Queries) UpdateAuthor(ctx context.Context, arg UpdateAuthorParams) error {
	_, err := q.db.ExecContext(ctx, updateAuthor, arg.ID, arg.Bio)
	return err
}

playground

Is this just a matter of outdated docs, or am I missing something? I prefer positional parameters in cases where there are 1-3 args; is there currently a way to get one vs. the other?

Thank you for this useful and satisfying project. ❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔧 golangdocumentationImprovements or additions to documentationenhancementNew feature or requestquestionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions