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

Function validate

internal/codegen/golang/gen.go:139–164  ·  view source on GitHub ↗
(options *opts.Options, enums []Enum, structs []Struct, queries []Query)

Source from the content-addressed store, hash-verified

137}
138
139func validate(options *opts.Options, enums []Enum, structs []Struct, queries []Query) error {
140 enumNames := make(map[string]struct{})
141 for _, enum := range enums {
142 enumNames[enum.Name] = struct{}{}
143 enumNames["Null"+enum.Name] = struct{}{}
144 }
145 structNames := make(map[string]struct{})
146 for _, struckt := range structs {
147 if _, ok := enumNames[struckt.Name]; ok {
148 return fmt.Errorf("struct name conflicts with enum name: %s", struckt.Name)
149 }
150 structNames[struckt.Name] = struct{}{}
151 }
152 if !options.EmitExportedQueries {
153 return nil
154 }
155 for _, query := range queries {
156 if _, ok := enumNames[query.ConstantName]; ok {
157 return fmt.Errorf("query constant name conflicts with enum name: %s", query.ConstantName)
158 }
159 if _, ok := structNames[query.ConstantName]; ok {
160 return fmt.Errorf("query constant name conflicts with struct name: %s", query.ConstantName)
161 }
162 }
163 return nil
164}
165
166func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum, structs []Struct, queries []Query) (*plugin.GenerateResponse, error) {
167 i := &importer{

Callers 1

GenerateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected