()
| 445 | } |
| 446 | |
| 447 | func (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 | |
| 497 | func trimSliceAndPointerPrefix(v string) string { |
| 498 | v = strings.TrimPrefix(v, "[]") |
no test coverage detected