MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / newCrudInfo

Function newCrudInfo

pkg/sql2code/parser/commonParser.go:74–120  ·  view source on GitHub ↗
(data tmplData)

Source from the content-addressed store, hash-verified

72}
73
74func newCrudInfo(data tmplData) *CrudInfo {
75 if len(data.Fields) == 0 {
76 return nil
77 }
78
79 var info *CrudInfo
80 for _, field := range data.Fields {
81 if field.IsPrimaryKey {
82 info = setCrudInfo(field)
83 break
84 }
85 }
86
87 // if not found primary key, find the first xxx_id column as primary key
88 if info == nil {
89 for _, field := range data.Fields {
90 if strings.HasSuffix(field.ColName, "_id") && isDesiredGoType(field.GoType) { // xxx_id
91 info = setCrudInfo(field)
92 break
93 }
94 }
95 }
96
97 // if not found xxx_id field, use the first field of integer or string type
98 if info == nil {
99 for _, field := range data.Fields {
100 if isDesiredGoType(field.GoType) {
101 info = setCrudInfo(field)
102 break
103 }
104 }
105 }
106
107 // use the first column as primary key
108 if info == nil {
109 info = setCrudInfo(data.Fields[0])
110 }
111
112 info.TableNameCamel = data.TableName
113 info.TableNameCamelFCL = data.TName
114
115 pluralName := inflection.Plural(data.TableName)
116 info.TableNamePluralCamel = customEndOfLetterToLower(data.TableName, pluralName)
117 info.TableNamePluralCamelFCL = customFirstLetterToLower(customEndOfLetterToLower(data.TableName, pluralName))
118
119 return info
120}
121
122func (info *CrudInfo) getCode() string {
123 if info == nil {

Callers 2

TestCrudInfoFunction · 0.85
makeCodeFunction · 0.85

Calls 4

setCrudInfoFunction · 0.85
isDesiredGoTypeFunction · 0.85
customFirstLetterToLowerFunction · 0.85
customEndOfLetterToLowerFunction · 0.70

Tested by 1

TestCrudInfoFunction · 0.68