@@ -105,19 +105,7 @@ var templateFunctions = template.FuncMap{
105105 "generateTags" : strmangle .GenerateTags ,
106106 "generateIgnoreTags" : strmangle .GenerateIgnoreTags ,
107107 "normalizeType" : NormalizeType ,
108- "enumVal" : func (val string ) string {
109- var newval strings.Builder
110- for _ , r := range val {
111- if r == '_' || unicode .IsLetter (r ) || unicode .IsDigit (r ) {
112- newval .WriteRune (r )
113- continue
114- }
115- newval .WriteString (fmt .Sprintf ("U%x" , r ))
116- }
117-
118- // Title case after doing unicode replacements or they will be stripped
119- return strmangle .TitleCase (newval .String ())
120- },
108+ "enumVal" : enumValToIdentifier ,
121109 "columnTagName" : func (casing , name , alias string ) string {
122110 switch casing {
123111 case "camel" :
@@ -149,6 +137,24 @@ var templateFunctions = template.FuncMap{
149137 "relQueryMethodName" : relQueryMethodName ,
150138}
151139
140+ func enumValToIdentifier (val string ) string {
141+ val = strings .ToLower (val )
142+ val = strings .ReplaceAll (val , "-" , "_" )
143+ val = strings .ReplaceAll (val , " " , "_" )
144+
145+ var newval strings.Builder
146+ for _ , r := range val {
147+ if r == '_' || unicode .IsLetter (r ) || unicode .IsDigit (r ) {
148+ newval .WriteRune (r )
149+ continue
150+ }
151+ newval .WriteString (fmt .Sprintf ("U%x" , r ))
152+ }
153+
154+ // Title case after doing unicode replacements or they will be stripped
155+ return strmangle .TitleCase (newval .String ())
156+ }
157+
152158func relQueryMethodName (tAlias drivers.TableAlias , relAlias string ) string {
153159 for _ , colAlias := range tAlias .Columns {
154160 // clash with field name
0 commit comments