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
Hey all, since I am outputting the generated models and files in an existing (functional) package, there is a slight naming conflict with the New function in the db.go file. Package-level New() functions are usually reserved for the instantiation of the primary struct in the package.
My package depends on the database models (them being the same as the domain models), so it also serves as the output dir of sqlc generate.
Proposed solutions / ideas:
allow for a separate output dir for models and the queries / db.go files
have separate package, declare the same (storage / domain) model twice and do a type conversion :(
Motivation:
I do not intend to use separate storage models, so what the application stores (model structs) is what the application will work with. While there certainly are cases where the storage and domain models differ for technical reasons, this is not really the norm and is not often necessary.
In my experience, separating storage completely in its own package usually leads to additional artificial layers, declaration of the same models twice, and the need for constant mapping back and forth.
I am aware of the advantages and disadvantages of both approaches and would like to have some additional flexibility.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey all, since I am outputting the generated models and files in an existing (functional) package, there is a slight naming conflict with the New function in the
db.go
file. Package-levelNew()
functions are usually reserved for the instantiation of the primary struct in the package.My package depends on the database models (them being the same as the domain models), so it also serves as the output dir of
sqlc generate
.Proposed solutions / ideas:
models
and the queries / db.go filesNewQueries() *Queries{ ... }
Workarounds:
package.New()
and keep things togetherMotivation:
I do not intend to use separate storage models, so what the application stores (model structs) is what the application will work with. While there certainly are cases where the storage and domain models differ for technical reasons, this is not really the norm and is not often necessary.
In my experience, separating storage completely in its own package usually leads to additional artificial layers, declaration of the same models twice, and the need for constant mapping back and forth.
I am aware of the advantages and disadvantages of both approaches and would like to have some additional flexibility.
Beta Was this translation helpful? Give feedback.
All reactions