Merge pull request #387 from safaci2000/feature/enums

Adding support for enum model AllValues
This commit is contained in:
go-jet 2024-09-23 20:03:19 +02:00 committed by GitHub
commit 6a0798eb06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -156,6 +156,12 @@ const (
{{- end}}
)
var {{$enumTemplate.TypeName}}AllValues = []{{$enumTemplate.TypeName}} {
{{- range $_, $value := .Values}}
{{valueName $value}},
{{- end}}
}
func (e *{{$enumTemplate.TypeName}}) Scan(value interface{}) error {
var enumValue string
switch val := value.(type) {

View file

@ -171,6 +171,7 @@ func TestGeneratorTemplate_Model_RenameFilesAndTypes(t *testing.T) {
mpaaRating := file2.Exists(t, defaultModelPath, "mpaa_rating_enum.go")
require.Contains(t, mpaaRating, "type MpaaRatingEnum string")
require.Contains(t, mpaaRating, "MpaaRatingEnumAllValues")
}
func TestGeneratorTemplate_Model_SkipTableAndEnum(t *testing.T) {
@ -268,7 +269,6 @@ func UseSchema(schema string) {
FilmList = FilmList.FromSchema(schema)
}
`)
}
func TestGeneratorTemplate_SQLBuilder_ChangeTypeAndFileName(t *testing.T) {
@ -366,7 +366,6 @@ func TestGeneratorTemplate_SQLBuilder_DefaultAlias(t *testing.T) {
}
func TestGeneratorTemplate_Model_AddTags(t *testing.T) {
err := postgres.Generate(
tempTestDir,
dbConnection,