- 
  Notifications
 You must be signed in to change notification settings 
- Fork 962
-
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 modelsand the queries / db.go files
- make db.go New() configurable / overridable - eg NewQueries() *Queries{ ... }
Workarounds:
- sacrifice package.New()and keep things together
- 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.
Beta Was this translation helpful? Give feedback.