MCPcopy
hub / github.com/sqlc-dev/sqlc / StructName

Function StructName

internal/codegen/golang/struct.go:19–49  ·  view source on GitHub ↗
(name string, options *opts.Options)

Source from the content-addressed store, hash-verified

17}
18
19func StructName(name string, options *opts.Options) string {
20 if rename := options.Rename[name]; rename != "" {
21 return rename
22 }
23 out := ""
24 name = strings.Map(func(r rune) rune {
25 if unicode.IsLetter(r) {
26 return r
27 }
28 if unicode.IsDigit(r) {
29 return r
30 }
31 return rune('_')
32 }, name)
33
34 for _, p := range strings.Split(name, "_") {
35 if _, found := options.InitialismsMap[p]; found {
36 out += strings.ToUpper(p)
37 } else {
38 out += strings.Title(p)
39 }
40 }
41
42 // If a name has a digit as its first char, prepand an underscore to make it a valid Go name.
43 r, _ := utf8.DecodeRuneInString(out)
44 if unicode.IsDigit(r) {
45 return "_" + out
46 } else {
47 return out
48 }
49}

Callers 6

buildEnumsFunction · 0.85
buildStructsFunction · 0.85
buildQueriesFunction · 0.85
columnsToStructFunction · 0.85
mysqlTypeFunction · 0.85
postgresTypeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected