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

sqlc.slice(): Generate code with unused imports #3065

Closed
flrossetto opened this issue Dec 17, 2023 · 1 comment · Fixed by #3073
Closed

sqlc.slice(): Generate code with unused imports #3065

flrossetto opened this issue Dec 17, 2023 · 1 comment · Fixed by #3073

Comments

@flrossetto
Copy link

flrossetto commented Dec 17, 2023

Version

1.24.0

What happened?

The code imports the unused "strings" package.

Relevant log output

// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.24.0
// source: query.sql

package tutorial

import (
	"context"
	"strings"
)

const getAuthor = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = any($1)
`

func (q *Queries) GetAuthor(ctx context.Context, idList []int64) (Author, error) {
	row := q.db.QueryRow(ctx, getAuthor, idList)
	var i Author
	err := row.Scan(&i.ID, &i.Name, &i.Bio)
	return i, err
}

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = any(sqlc.slice('id_list'));

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "tutorial"
        out: "tutorial"
        sql_package: "pgx/v5"

Playground URL

https://play.sqlc.dev/p/7f1ba3b245cc4cbdf50a7512c4a598d701d80eda56de8ef60fd26393e3ca1605

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@flrossetto flrossetto added bug Something isn't working triage New issues that hasn't been reviewed labels Dec 17, 2023
@andrewmbenton andrewmbenton added 📚 postgresql 🔧 golang pgx/v5 and removed triage New issues that hasn't been reviewed labels Dec 20, 2023
andrewmbenton added a commit that referenced this issue Dec 20, 2023
… pgx

Also fix the invalid test that should have caught this

Resolves #3065
kyleconroy pushed a commit that referenced this issue Dec 20, 2023
… pgx (#3073)

Also fix the invalid test that should have caught this

Resolves #3065
@Jille
Copy link
Contributor

Jille commented Dec 21, 2023

I think you might be better off using:

SELECT * FROM authors WHERE id = any(sqlc.arg('id_list')::integer[]);

This side-steps the bug and is probably better for statement caching done by the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants