Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Integrating generated code in existing package, customize db.go New() function name etc #3617

Unanswered
bmarinov asked this question in Q&A
Discussion options

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
  • 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.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /