diff --git a/generator/template/file_templates.go b/generator/template/file_templates.go index 731b1af..f3aa505 100644 --- a/generator/template/file_templates.go +++ b/generator/template/file_templates.go @@ -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) { diff --git a/tests/postgres/generator_template_test.go b/tests/postgres/generator_template_test.go index 4d87295..65603cd 100644 --- a/tests/postgres/generator_template_test.go +++ b/tests/postgres/generator_template_test.go @@ -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,