MCPcopy
hub / github.com/sqlc-dev/sqlc / buildStructs

Function buildStructs

internal/codegen/golang/result.go:63–111  ·  view source on GitHub ↗
(req *plugin.GenerateRequest, options *opts.Options)

Source from the content-addressed store, hash-verified

61}
62
63func buildStructs(req *plugin.GenerateRequest, options *opts.Options) []Struct {
64 var structs []Struct
65 for _, schema := range req.Catalog.Schemas {
66 if schema.Name == "pg_catalog" || schema.Name == "information_schema" {
67 continue
68 }
69 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 }
104 structs = append(structs, s)
105 }
106 }
107 if len(structs) > 0 {
108 sort.Slice(structs, func(i, j int) bool { return structs[i].Name < structs[j].Name })
109 }
110 return structs
111}
112
113type goColumn struct {
114 id int

Callers 1

GenerateFunction · 0.85

Calls 5

SingularFunction · 0.92
StructNameFunction · 0.85
JSONTagNameFunction · 0.85
addExtraGoStructTagsFunction · 0.85
goTypeFunction · 0.85

Tested by

no test coverage detected