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

Method batchImports

internal/codegen/golang/imports.go:447–495  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

445}
446
447func (i *importer) batchImports() fileImports {
448 batchQueries := make([]Query, 0, len(i.Queries))
449 for _, q := range i.Queries {
450 if usesBatch([]Query{q}) {
451 batchQueries = append(batchQueries, q)
452 }
453 }
454 std, pkg := buildImports(i.Options, batchQueries, func(name string) bool {
455 for _, q := range batchQueries {
456 if q.hasRetType() {
457 if q.Ret.EmitStruct() {
458 for _, f := range q.Ret.Struct.Fields {
459 if hasPrefixIgnoringSliceAndPointerPrefix(f.Type, name) {
460 return true
461 }
462 }
463 }
464 if hasPrefixIgnoringSliceAndPointerPrefix(q.Ret.Type(), name) {
465 return true
466 }
467 }
468 if q.Arg.EmitStruct() {
469 for _, f := range q.Arg.Struct.Fields {
470 if hasPrefixIgnoringSliceAndPointerPrefix(f.Type, name) {
471 return true
472 }
473 }
474 }
475 for _, f := range q.Arg.Pairs() {
476 if hasPrefixIgnoringSliceAndPointerPrefix(f.Type, name) {
477 return true
478 }
479 }
480 }
481 return false
482 })
483
484 std["context"] = struct{}{}
485 std["errors"] = struct{}{}
486 sqlpkg := parseDriver(i.Options.SqlPackage)
487 switch sqlpkg {
488 case opts.SQLDriverPGXV4:
489 pkg[ImportSpec{Path: "github.com/jackc/pgx/v4"}] = struct{}{}
490 case opts.SQLDriverPGXV5:
491 pkg[ImportSpec{Path: "github.com/jackc/pgx/v5"}] = struct{}{}
492 }
493
494 return sortedImports(std, pkg)
495}
496
497func trimSliceAndPointerPrefix(v string) string {
498 v = strings.TrimPrefix(v, "[]")

Callers 1

ImportsMethod · 0.95

Calls 9

usesBatchFunction · 0.85
buildImportsFunction · 0.85
parseDriverFunction · 0.85
sortedImportsFunction · 0.85
hasRetTypeMethod · 0.80
EmitStructMethod · 0.80
TypeMethod · 0.80
PairsMethod · 0.65

Tested by

no test coverage detected