(req *plugin.GenerateRequest, options *opts.Options)
| 14 | ) |
| 15 | |
| 16 | func buildEnums(req *plugin.GenerateRequest, options *opts.Options) []Enum { |
| 17 | var enums []Enum |
| 18 | for _, schema := range req.Catalog.Schemas { |
| 19 | if schema.Name == "pg_catalog" || schema.Name == "information_schema" { |
| 20 | continue |
| 21 | } |
| 22 | for _, enum := range schema.Enums { |
| 23 | var enumName string |
| 24 | if schema.Name == req.Catalog.DefaultSchema { |
| 25 | enumName = enum.Name |
| 26 | } else { |
| 27 | enumName = schema.Name + "_" + enum.Name |
| 28 | } |
| 29 | |
| 30 | e := Enum{ |
| 31 | Name: StructName(enumName, options), |
| 32 | Comment: enum.Comment, |
| 33 | NameTags: map[string]string{}, |
| 34 | ValidTags: map[string]string{}, |
| 35 | } |
| 36 | if options.EmitJsonTags { |
| 37 | e.NameTags["json"] = JSONTagName(enumName, options) |
| 38 | e.ValidTags["json"] = JSONTagName("valid", options) |
| 39 | } |
| 40 | |
| 41 | seen := make(map[string]struct{}, len(enum.Vals)) |
| 42 | for i, v := range enum.Vals { |
| 43 | value := EnumReplace(v) |
| 44 | if _, found := seen[value]; found || value == "" { |
| 45 | value = fmt.Sprintf("value_%d", i) |
| 46 | } |
| 47 | e.Constants = append(e.Constants, Constant{ |
| 48 | Name: StructName(enumName+"_"+value, options), |
| 49 | Value: v, |
| 50 | Type: e.Name, |
| 51 | }) |
| 52 | seen[value] = struct{}{} |
| 53 | } |
| 54 | enums = append(enums, e) |
| 55 | } |
| 56 | } |
| 57 | if len(enums) > 0 { |
| 58 | sort.Slice(enums, func(i, j int) bool { return enums[i].Name < enums[j].Name }) |
| 59 | } |
| 60 | return enums |
| 61 | } |
| 62 | |
| 63 | func buildStructs(req *plugin.GenerateRequest, options *opts.Options) []Struct { |
| 64 | var structs []Struct |
no test coverage detected