Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] copyfrom imports #1626

Merged
merged 1 commit into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions internal/codegen/golang/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,14 @@ func (i *importer) queryImports(filename string) fileImports {
}

func (i *importer) copyfromImports() fileImports {
std, pkg := buildImports(i.Settings, i.Queries, func(name string) bool {
for _, q := range i.Queries {
if q.Cmd != metadata.CmdCopyFrom {
continue
}
copyFromQueries := make([]Query, 0, len(i.Queries))
for _, q := range i.Queries {
if q.Cmd == metadata.CmdCopyFrom {
copyFromQueries = append(copyFromQueries, q)
}
}
std, pkg := buildImports(i.Settings, copyFromQueries, func(name string) bool {
for _, q := range copyFromQueries {
if q.hasRetType() {
if strings.HasPrefix(q.Ret.Type(), name) {
return true
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ INSERT INTO myschema.foo (a, b) VALUES ($1, $2);

-- name: InsertSingleValue :exec
INSERT INTO myschema.foo (a) VALUES ($1);

-- name: DeleteValues :execresult
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the main offender, any file generated from a query file with queries of type metadata.CmdExecResult would include the github.com/jackc/pgconn package

DELETE
FROM myschema.foo;