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

feat(Go):Add query_parameter_limit conf to codegen #1558

Merged
merged 6 commits into from Apr 7, 2023

Conversation

go-mez
Copy link
Contributor

@go-mez go-mez commented Apr 18, 2022

Related to: #1498.

I'm not sure about the approach I took, so just let me know if im solving it wrongly

@go-mez go-mez force-pushed the feat/query-parameter-limit branch from 04ab48f to f7c492c Compare April 18, 2022 16:11
@go-mez
Copy link
Contributor Author

go-mez commented Apr 20, 2022

@kyleconroy sorry, now its passing all the tests, i think... I was not aware of the dev guide (https://github.com/kyleconroy/sqlc/blob/main/docs/guides/development.md)... i was just running make but it wasnt throwing any error

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.

This looks good. Left a few comments about the new behavior we should support.

@@ -78,6 +79,8 @@ Each package document has the following keys:
- Customize the name of the querier file. Defaults to `querier.go`.
- `output_files_suffix`:
- If specified the suffix will be added to the name of the generated files.
- `query_parameter_limit`:
- Positional arguments that will be generated in go functions (>= `1` or `-1`). To always emit a parameter struct, you would need to set it to `-1`. `0` is invalid. Defaults to `1`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I changed my mind here. We should allow for zero to be a valid value. Anything less than zero should be an error.

internal/cmd/shim.go Show resolved Hide resolved
@kyleconroy
Copy link
Collaborator

@go-mez Sorry for taking so long to get you a review. I know you've resolved conflicts a few times. I can promise that you'll only need to do it one more time. Thanks again for understanding.

@polderudo
Copy link

Any chance, to merge this to master? I could help if needed.

@kyleconroy
Copy link
Collaborator

Not sure what's happened, but the tests haven't run for this PR. Maybe another rebase and push will fix things?

@polderudo
Copy link

@go-mez any chance to get this rebased and pushed? seems like only the docs were waiting... Would be cool to have that feature

@go-mez
Copy link
Contributor Author

go-mez commented Mar 9, 2023

@polderudo i'll do it. dont worry!

@go-mez
Copy link
Contributor Author

go-mez commented Mar 9, 2023

@kyleconroy i think it is okay now. could you approve the workflows please ?

@polderudo
Copy link

@polderudo i'll do it. dont worry!

Thanks man! I didn't want to push however, just asked because we are at the start of a project and that would save a lot of refactoring.

@go-mez
Copy link
Contributor Author

go-mez commented Mar 17, 2023

@kyleconroy could you please take a look at the PR and approve the workflows?

Copy link
Contributor

@josharian josharian left a comment

Choose a reason for hiding this comment

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

I left a few comments scattered about.

I really like this (and I would set the parameter to 3 or 4 myself), with one caveat.

I would personally prefer a struct in any case (no matter how few params) in which all the parameter types aren't distinct. That is, these are all good function signatures:

func SomeQuery(ctx context.Context, id int32)
func SomeQuery(ctx context.Context, id int32, s string)
func SomeQuery(ctx context.Context, id int32, s string, created time.Time, x SomeEnum, b bool)

But this one isn't:

func SomeQuery(ctx context.Context, id1 int32, id2 int32)

Even though it has only two params, they have the same type, which makes it easy to accidentally transpose them.

(It would be even better if each model's ID automatically had its own type, like type UserID int32, but that's a different topic. That can be achieved manually as needed.)

internal/codegen/golang/field.go Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
internal/codegen/golang/result.go Outdated Show resolved Hide resolved
protos/plugin/codegen.proto Outdated Show resolved Hide resolved
@go-mez
Copy link
Contributor Author

go-mez commented Mar 31, 2023

@josharian thank you for the review and the suggestion. i will try to address it

@go-mez go-mez requested a review from josharian March 31, 2023 21:19
Copy link
Contributor

@josharian josharian left a comment

Choose a reason for hiding this comment

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

lgtm, modulo on little comment and my larger design comment above.

guess it's back to @kyleconroy

@josharian
Copy link
Contributor

ping @kyleconroy

@kyleconroy kyleconroy added this to the 1.18.0 milestone Apr 7, 2023
@kyleconroy kyleconroy merged commit b4d2e91 into sqlc-dev:main Apr 7, 2023
6 checks passed
@go-mez
Copy link
Contributor Author

go-mez commented Apr 7, 2023

thankyou guys!

@go-mez go-mez deleted the feat/query-parameter-limit branch April 7, 2023 17:45
@polderudo
Copy link

Works nice. Thanks for the work, although there is a issue with pgx.
Using sql_package: "pgx/v5"
and building with
sqlc generate --experimental -f sqlc.yaml
will not add the import to
"github.com/jackc/pgx/v5/pgtype"
to the generated files.

@polderudo
Copy link

Did you find any time to look into this go-mez?

@go-mez
Copy link
Contributor Author

go-mez commented Apr 27, 2023

@polderudo do you know if this error was happening before? ill try to check it anytime soon.

could you also provide an example in the playground ? (https://play.sqlc.dev/)

@polderudo
Copy link

It's working, if i remove the new config
"query_parameter_limit": 999

Here is a palyground:
https://play.sqlc.dev/p/29a65ea348dd6ce7915b9106fc8e2eecb6ea83b53705ae72d9096ac4ac7c56d4

@polderudo
Copy link

ping. any update?

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.

None yet

4 participants