@@ -67,40 +67,11 @@ func buildStructs(req *plugin.GenerateRequest, options *opts.Options) []Struct {
6767 continue
6868 }
6969 for _ , table := range schema .Tables {
70- var tableName string
71- if schema .Name == req .Catalog .DefaultSchema {
72- tableName = table .Rel .Name
73- } else {
74- tableName = schema .Name + "_" + table .Rel .Name
75- }
76- structName := tableName
77- if ! options .EmitExactTableNames {
78- structName = inflection .Singular (inflection.SingularParams {
79- Name : structName ,
80- Exclusions : options .InflectionExcludeTableNames ,
81- })
82- }
83- s := Struct {
84- Table : & plugin.Identifier {Schema : schema .Name , Name : table .Rel .Name },
85- Name : StructName (structName , options ),
86- Comment : table .Comment ,
87- }
88- for _ , column := range table .Columns {
89- tags := map [string ]string {}
90- if options .EmitDbTags {
91- tags ["db" ] = column .Name
92- }
93- if options .EmitJsonTags {
94- tags ["json" ] = JSONTagName (column .Name , options )
95- }
96- addExtraGoStructTags (tags , req , options , column )
97- s .Fields = append (s .Fields , Field {
98- Name : StructName (column .Name , options ),
99- Type : goType (req , options , column ),
100- Tags : tags ,
101- Comment : column .Comment ,
102- })
103- }
70+ s := buildStruct (req , options , schema , table .Rel .Name , table .Comment , table .Columns )
71+ structs = append (structs , s )
72+ }
73+ for _ , ty := range schema .CompositeTypes {
74+ s := buildStruct (req , options , schema , ty .Name , ty .Comment , ty .Columns )
10475 structs = append (structs , s )
10576 }
10677 }
@@ -110,6 +81,51 @@ func buildStructs(req *plugin.GenerateRequest, options *opts.Options) []Struct {
11081 return structs
11182}
11283
84+ func buildStruct (
85+ req * plugin.GenerateRequest ,
86+ options * opts.Options ,
87+ schema * plugin.Schema ,
88+ rawName string ,
89+ comment string ,
90+ columns []* plugin.Column ,
91+ ) Struct {
92+ var tableName string
93+ if schema .Name == req .Catalog .DefaultSchema {
94+ tableName = rawName
95+ } else {
96+ tableName = schema .Name + "_" + rawName
97+ }
98+ structName := tableName
99+ if ! options .EmitExactTableNames {
100+ structName = inflection .Singular (inflection.SingularParams {
101+ Name : structName ,
102+ Exclusions : options .InflectionExcludeTableNames ,
103+ })
104+ }
105+ s := Struct {
106+ Table : & plugin.Identifier {Schema : schema .Name , Name : rawName },
107+ Name : StructName (structName , options ),
108+ Comment : comment ,
109+ }
110+ for _ , column := range columns {
111+ tags := map [string ]string {}
112+ if options .EmitDbTags {
113+ tags ["db" ] = column .Name
114+ }
115+ if options .EmitJsonTags {
116+ tags ["json" ] = JSONTagName (column .Name , options )
117+ }
118+ addExtraGoStructTags (tags , req , options , column )
119+ s .Fields = append (s .Fields , Field {
120+ Name : StructName (column .Name , options ),
121+ Type : goType (req , options , column ),
122+ Tags : tags ,
123+ Comment : column .Comment ,
124+ })
125+ }
126+ return s
127+ }
128+
113129type goColumn struct {
114130 id int
115131 * plugin.Column
0 commit comments