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

Method queryImports

internal/codegen/golang/imports.go:299–410  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

297}
298
299func (i *importer) queryImports(filename string) fileImports {
300 var gq []Query
301 anyNonCopyFrom := false
302 for _, query := range i.Queries {
303 if usesBatch([]Query{query}) {
304 continue
305 }
306 if query.SourceName == filename {
307 gq = append(gq, query)
308 if query.Cmd != metadata.CmdCopyFrom {
309 anyNonCopyFrom = true
310 }
311 }
312 }
313
314 std, pkg := buildImports(i.Options, gq, func(name string) bool {
315 for _, q := range gq {
316 if q.hasRetType() {
317 if q.Ret.EmitStruct() {
318 for _, f := range q.Ret.Struct.Fields {
319 if hasPrefixIgnoringSliceAndPointerPrefix(f.Type, name) {
320 return true
321 }
322 }
323 }
324 if hasPrefixIgnoringSliceAndPointerPrefix(q.Ret.Type(), name) {
325 return true
326 }
327 }
328 // Check the fields of the argument struct if it's emitted
329 if q.Arg.EmitStruct() {
330 for _, f := range q.Arg.Struct.Fields {
331 if hasPrefixIgnoringSliceAndPointerPrefix(f.Type, name) {
332 return true
333 }
334 }
335 }
336 // Check the argument pairs inside the method definition
337 for _, f := range q.Arg.Pairs() {
338 if hasPrefixIgnoringSliceAndPointerPrefix(f.Type, name) {
339 return true
340 }
341 }
342 }
343 return false
344 })
345
346 sliceScan := func() bool {
347 for _, q := range gq {
348 if q.hasRetType() {
349 if q.Ret.IsStruct() {
350 for _, f := range q.Ret.Struct.Fields {
351 if strings.HasPrefix(f.Type, "[]") && f.Type != "[]byte" {
352 return true
353 }
354 for _, embed := range f.EmbedFields {
355 if strings.HasPrefix(embed.Type, "[]") && embed.Type != "[]byte" {
356 return true

Callers 1

ImportsMethod · 0.95

Calls 14

usesBatchFunction · 0.85
buildImportsFunction · 0.85
parseDriverFunction · 0.85
sortedImportsFunction · 0.85
hasRetTypeMethod · 0.80
EmitStructMethod · 0.80
TypeMethod · 0.80
IsStructMethod · 0.80
isEmptyMethod · 0.80
HasSqlcSliceMethod · 0.80
HasSqlcSlicesMethod · 0.80

Tested by

no test coverage detected