@@ -34,10 +34,21 @@ func enumColumnValueName(colName, value string) string {
34
34
return strings .Join (items , "" )
35
35
}
36
36
37
+ func getTableLastPart (tableName string ) string {
38
+ tablePart := strings .Split (tableName , "_" )
39
+ lastTablePart := ""
40
+ if len (tablePart ) > 1 {
41
+ lastTablePart = tablePart [len (tablePart )- 1 ]
42
+ }
43
+ return lastTablePart
44
+ }
45
+
37
46
// Enums generates parser-agnostic GoEnum types
38
47
func (r * Result ) Enums (settings config.CombinedSettings ) []dinosql.GoEnum {
39
48
var enums []dinosql.GoEnum
40
49
for tableName , table := range r .Schema .tables {
50
+ lastTablePart := getTableLastPart (tableName )
51
+
41
52
for _ , col := range table {
42
53
if col .Type .Type == "enum" {
43
54
constants := []dinosql.GoConstant {}
@@ -49,7 +60,7 @@ func (r *Result) Enums(settings config.CombinedSettings) []dinosql.GoEnum {
49
60
if isCustomEnumName {
50
61
name = strings .Title (enumName ) + strings .Title (stripped )
51
62
} else {
52
- name = enumColumnValueName (col .Name .String (), stripped )
63
+ name = enumColumnValueName (lastTablePart + "_" + col .Name .String (), stripped )
53
64
}
54
65
constants = append (constants , dinosql.GoConstant {
55
66
// Name 常量名称
@@ -66,7 +77,7 @@ func (r *Result) Enums(settings config.CombinedSettings) []dinosql.GoEnum {
66
77
if isCustomEnumName {
67
78
name = strings .Title (enumName ) + strings .Title (stripped )
68
79
} else {
69
- name = enumColumnValueName (col .Name .String (), stripped )
80
+ name = enumColumnValueName (lastTablePart + "_" + col .Name .String (), stripped )
70
81
}
71
82
constants = append (constants , dinosql.GoConstant {
72
83
// TODO: maybe add the struct name call to capitalize the name here
@@ -104,8 +115,9 @@ func (pGen PackageGenerator) enumNameFromColDef(tableName string, col *sqlparser
104
115
return customName , true
105
116
}
106
117
}
118
+
107
119
return fmt .Sprintf ("%sType" ,
108
- dinosql .StructName (col .Name .String (), pGen .CombinedSettings )), false
120
+ dinosql .StructName (getTableLastPart ( tableName ) + "_" + col .Name .String (), pGen .CombinedSettings )), false
109
121
}
110
122
111
123
// Structs marshels each query into a go struct for generation
0 commit comments