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

Positional arguments in generated Go function #1496

Closed
brentd opened this issue Mar 19, 2022 · 3 comments · Fixed by #1499
Closed

Positional arguments in generated Go function #1496

brentd opened this issue Mar 19, 2022 · 3 comments · Fixed by #1499
Labels
documentation Improvements or additions to documentation enhancement New feature or request question Further information is requested 🔧 golang

Comments

@brentd
Copy link

brentd commented Mar 19, 2022

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. ❤️

@kyleconroy kyleconroy added documentation Improvements or additions to documentation question Further information is requested 🔧 golang labels Mar 19, 2022
@kyleconroy
Copy link
Collaborator

Is this just a matter of outdated docs, or am I missing something?

The documentation is out dated, I'll make sure to update it before the next release.

I prefer positional parameters in cases where there are 1-3 args; is there currently a way to get one vs. the other?

Positional arguments will be generated when there is a single argument. I'd be open to support a package-wide configuration parameter to pick this number.

@brentd
Copy link
Author

brentd commented Mar 19, 2022

Positional arguments will be generated when there is a single argument. I'd be open to support a package-wide configuration parameter to pick this number.

@kyleconroy thanks! Sounds like a great opportunity to contribute as I'd like to see this.

@kyleconroy
Copy link
Collaborator

Discussing a solution here! #1498

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request question Further information is requested 🔧 golang
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants