[bug] Fix crash on generating enum sql builder files when enum contains numeric values.
This commit is contained in:
parent
f154701e60
commit
63c1fd6430
5 changed files with 42 additions and 5 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// ToGoIdentifier converts database to Go identifier.
|
||||
|
|
@ -17,6 +18,15 @@ func ToGoIdentifier(databaseIdentifier string) string {
|
|||
return snaker.SnakeToCamel(replaceInvalidChars(databaseIdentifier))
|
||||
}
|
||||
|
||||
func ToGoEnumValueIdentifier(enumName, enumValue string) string {
|
||||
enumValueIdentifier := ToGoIdentifier(enumValue)
|
||||
if !unicode.IsLetter([]rune(enumValueIdentifier)[0]) {
|
||||
return ToGoIdentifier(enumName) + enumValueIdentifier
|
||||
}
|
||||
|
||||
return enumValueIdentifier
|
||||
}
|
||||
|
||||
// ToGoFileName converts database identifier to Go file name.
|
||||
func ToGoFileName(databaseIdentifier string) string {
|
||||
return strings.ToLower(replaceInvalidChars(databaseIdentifier))
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ func TestToGoIdentifier(t *testing.T) {
|
|||
assert.Equal(t, ToGoIdentifier("My-Table"), "MyTable")
|
||||
}
|
||||
|
||||
func TestToGoEnumValueIdentifier(t *testing.T) {
|
||||
assert.Equal(t, ToGoEnumValueIdentifier("enum_name", "enum_value"), "EnumValue")
|
||||
assert.Equal(t, ToGoEnumValueIdentifier("NumEnum", "100"), "NumEnum100")
|
||||
}
|
||||
|
||||
func TestErrorCatchErr(t *testing.T) {
|
||||
var err error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue