Skip to content

Commit

Permalink
fix struct short name
Browse files Browse the repository at this point in the history
  • Loading branch information
fifsky committed Jul 13, 2018
1 parent 091171a commit c1ddc62
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type TableInfo struct {
Columns []*Attr
Len int
TableName string
ShortName string
StructName string
Database string
PrimaryKey string
Expand All @@ -36,16 +37,16 @@ type {{ .StructName }} struct {
{{ range $i,$v := .Columns }}{{ .StructField }} {{ .Type }} ` + "\u0060" + `json:"{{ .Field }}" db:"{{ .Field }}"` + "\u0060{{ if ne $i $.Len }}\n " + `{{ end }}{{ end }}
}
func (this *{{ .StructName }}) DbName() string {
return {{ .Database }}
func ({{ .ShortName }} *{{ .StructName }}) DbName() string {
return "{{ .Database }}"
}
func (this *{{ .StructName }}) TableName() string {
return {{ .TableName }}
func ({{ .ShortName }} *{{ .StructName }}) TableName() string {
return "{{ .TableName }}"
}
func (this *{{ .StructName }}) PK() string {
return {{ .PrimaryKey }}
func ({{ .ShortName }} *{{ .StructName }}) PK() string {
return "{{ .PrimaryKey }}"
}
`

Expand All @@ -66,6 +67,7 @@ func ShowStruct(cmd string) error {
info := &TableInfo{
Columns: make([]*Attr, 0),
TableName: cmd,
ShortName: cmd[0:1],
StructName: titleCasedName(cmd),
Database: databaseName,
}
Expand Down

0 comments on commit c1ddc62

Please sign in to comment.