Skip to content

Commit 52b6bb4

Browse files
authored
Prepend an underscore to a StructName if it starts with a digit. (#1554)
1 parent e088da7 commit 52b6bb4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/codegen/golang/struct.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package golang
22

33
import (
44
"strings"
5+
"unicode"
6+
"unicode/utf8"
57

68
"github.com/kyleconroy/sqlc/internal/plugin"
79
)
@@ -25,5 +27,12 @@ func StructName(name string, settings *plugin.Settings) string {
2527
out += strings.Title(p)
2628
}
2729
}
28-
return out
30+
31+
// If a name has a digit as its first char, prepand an underscore to make it a valid Go name.
32+
r, _ := utf8.DecodeRuneInString(out)
33+
if unicode.IsDigit(r) {
34+
return "_" + out
35+
} else {
36+
return out
37+
}
2938
}

0 commit comments

Comments
 (0)