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

Reuse queries struct #2624

Closed
wants to merge 0 commits into from
Closed

Reuse queries struct #2624

wants to merge 0 commits into from

Conversation

MartyHub
Copy link

Hello,

reading #2607, I can see that sqlc is able to reuse a table struct when generating queries output.
To fix #755, maybe the same process can be extended to allow a query output struct to be reused?

Regards

@andrewmbenton
Copy link
Collaborator

This is a nice solution I think, but we should have @kyleconroy weigh in as well.

It's a breaking change, so I think if we do merge this we'll want it behind a configuration parameter like reuse_query_structs or reuse_structs. But that brings up an interesting question I guess. Should we try to have sqlc reuse the query parameter structs as well? A quick search doesn't turn up anyone asking for this in GH issues, but I think it would make sense.

A minor suggestion would be to name the slice of query structs queryStructs instead of structsQueries.

And then one more question, after looking over the testdata output, are you certain that the choice of struct name is deterministic? That is, can we be sure that we're always iterating over the queries in the same order so that the reused struct will always have the same name? I think the answer is yes but just want to be sure.

@MartyHub
Copy link
Author

I agree a configuration parameter would be useful to keep compatibility!

Good point regarding deterministic structs iteration order, I'll try to have a look.

Since my PR, I also discovered that it does not play nicely with sqlc.embed, this needs more test cases.

@fnsne
Copy link

fnsne commented Sep 22, 2023

Hello, @MartyHub
The PR error looks like not add "reuse_structs": false in the internal/endtoend/testdata/process_plugin_sqlc_gen_json/gen/codegen.json.
But I don't know how to help to fixed that.

截圖 2023-09-22 上午9 52 07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for custom models
4 participants