volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.66k stars 539 forks source link

Feature Request: make enums their own type #424

Open jstrohm-triller opened 5 years ago

jstrohm-triller commented 5 years ago

I'm new to Go and SQLBoiler but would it be possible to have enums be their own type like this?

type Workday 
const (
  WorkdayMonday Workday  = "monday"
  WorkdayTuesday Workday  = "tuesday"
  WorkdayWednesday Workday = "wednesday"
  WorkdayThursday Workday = "thursday"
  WorkdayFriday Workday  = "friday"
)
aarondl commented 5 years ago

This is definitely something that could be implemented but it requires a larger change to be useful.

In SQLBoiler there's still a few places where it's useful to build strings with + and this prevents that from happening because it requires a conversion from Workday to string for it to work.

aarondl commented 5 years ago

This could be done as part of #426 but it's a breaking change.

aarondl commented 5 years ago

This could possibly be done now as #426 is finished. Though it is a breaking change.

Atrox commented 5 years ago

I would love to see this in SQLBoiler. Maybe as an option in sqlboiler.toml?

aarondl commented 5 years ago

Since it is a breaking change yes, an opt-in flag in config would do until 4.0 at which point that'd be the only way. This really is only made possible by 426 though since those types will be pain to deal with in any other scenario.

aarondl commented 5 years ago

Happy to see a PR for this at some point.

tomscholz commented 4 years ago

I'd love to help. As far as I understood is #426 resolved and the feature should be behind a feature flag. Correct?

tomscholz commented 4 years ago

Okay, so I'm currently browsing the repo and making myself familiar with how the project is structured. The template for the boil_types.go is located under templates/singleton/boil_types.go.

There is templatebin/bindata.go which is the only place I could find where templates/singleton/boil_types.go is being used, but I'm unsure what bindata.go exactly does. Any guidance here would be helpful :)

Cheers, Tom

aarondl commented 4 years ago

@tomscholz take a look at the contributing guide. Talks about a tool called go-bindata and where to get it. The boil.sh build script has ways to take the modified templates and turn it into that bindata.go