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

Type Alias in Code generation #3512

Unanswered
DawnKosmos asked this question in Feature Requests & Ideas
Discussion options

Hey, We would love to see following optional feature in Code Generation for Golang.
If a Struct that matches in FieldName, Type and Order should not generate a new Type but a Type alias

type InsertDailyParams struct {
 TickerID int32 `json:"ticker_id"`
 Open float64 `json:"open"`
 High float64 `json:"high"`
 Low float64 `json:"low"`
 Close float64 `json:"close"`
 Volume float64 `json:"volume"`
 Time int64 `json:"time"`
}
type InsertHourlyParams = InsertDailyParams
Instead of this
/*
type InsertHourlyParams struct {
 TickerID int32 `json:"ticker_id"`
 Open float64 `json:"open"`
 High float64 `json:"high"`
 Low float64 `json:"low"`
 Close float64 `json:"close"`
 Volume float64 `json:"volume"`
 Time int64 `json:"time"`
}
*/

I think it should be easy to implement

  1. Add an option to the yaml
  2. Add a map that hashes field.name + field.types of generated struct.
    If someone wants to help me with this feature, I really appreciate it.

I wrote a tool that does this, after a sqlc generation, and it did not break our codebase.

You must be logged in to vote

Replies: 1 comment

Comment options

https://github.com/cubular-io/sqlcube If someone want to play with it.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

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