jschaf / pggen

Generate type-safe Go for any Postgres query. If Postgres can run the query, pggen can generate code for it.
MIT License
281 stars 26 forks source link

Proposal: Configure struct generation capability #83

Closed farazfazli closed 1 year ago

farazfazli commented 1 year ago

First of all, I want to say thank you for creating this project, I love the concept. I also use Cornucopia which is a very similar project (also uses Docker and supports Postgres), but is written in Rust instead of Go.

I am trying out pggen and wanted to know if there's any way to have it always generate structs for the inputs and outputs - from a quick look at the source code it looks like https://github.com/jschaf/pggen/blob/main/internal/codegen/golang/templated_file.go#L114 is generating structs if there are at least 3 inputs.

I understand your motivation behind having the pggen tool have a minimal number of flags, but was wondering if a flag can be added to tweak this value?

Feel free to let me know your thoughts or if I'm missing something here. Thanks again!

farazfazli commented 1 year ago

@jschaf What are your thoughts on this?

jschaf commented 1 year ago

Pretty reasonable. This has bitten me a few times, going from 2 params to more. Any thoughts on flag names:

--inline-params-count # if 0, don't inline; defaults to 2

Also, I'd wager that most of the pain is inlining params, not the rows.

farazfazli commented 1 year ago

@jschaf That flag name is great.

jschaf commented 1 year ago

HI @farazfazli, this is live in the 2023-06-17 release.