You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.:
package models
//Product is a Postgres table, parts of which are imported from the remote ERP and another remote website.//All fields of ERPProduct and WebProduct are contained in the Postgres tabletypeProductstruct {
ERPProduct//note: embedded ERPProduct.ProductCode is primary key!WebProductCulturestring`json:"culture" pg:"culture"`IsEnabledbool`json:"isEnabled,omitempty" pg:"is_enabled"`
}
//ERPProduct represents an ERP product record from the remote SQL ServertypeERPProductstruct {
ProductCodestring`json:"productCode" db:"ProductCode" pg:"product_code"`//db tag is for ERP SQL ServerCategorystring`json:"categoryCode,omitempty" db:"Category" pg:"category"`//...other columns...
}
//Import will connect to the ERP and import an ERPProduct from an SQL Serverfunc (p*ERPProduct) Import() (error) {
//code to import and populate p using sqlxreturnnil
}
//WebProduct represents a web product typeWebProductstruct {
WebCodestring`json:"webcode,omitempty" pg:"web_code"`WebDescriptionstring`json:"webDescription,omitempty" pg:"web_description"`Slugstring`json:"slug,omitempty" pg:"slug"`//...other columns...
}
//Import will connect to another remote website and import a WebProduct via an APIfunc (p*WebProduct) Import() (error) {
//code to import and populate p returnnil
}
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.. :)
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?
Uh oh!
There was an error while loading. Please reload this page.
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...
The text was updated successfully, but these errors were encountered: