Open nkev opened 2 years ago
See a similar issue here: https://github.com/kyleconroy/sqlc/issues/755
Yes, I saw that and others too related to custom tags. I'm sure there will also be other issues in future related to customization of structs. For example, in my scenario above I thought about omitting product
in the schema file so the struct does not get generated by sqlc. But then I realized the product
table gets referenced in many queries so this means I cannot use sqlc at all, even though I would so love to.
To be fair, sqlc cannot possibly cater for all struct use cases, so I think allowing user overriden structs is the most flexible solution, don't you agree?
I can see quite a few unresolved issues related to the customization of sqlc generated structs.
I'm in a similar position where I have several custom struct tags and embedded structs in my product model that flattens out to a single Postgres table, e.g.:
As you can see, there are too many issues with this product model to port across to sqlc.
However, I have an idea that might solve all of those issues in one foul swoop.. :)
We can currently override fields like this:
Could we not do the same for structs? i.e. override the generation of the 'product' struct with my custom product struct like this:
The flattenned out 'product' definition would still be required in the sqlc schema file (only for validation in sqlc generated queries):
sqlc would then generate the struct of the 'product' schema but comment it out with an 'overriden by..' comment above it.
sqlc would then import
github.com/me/myproj/models
in thequery.sql.go
file and use theProduct
struct in there.Any product related query errors thereafter will be the responsibility of the developer...