Skip to content

Unused imports generated in querier interfaces. #2707

Description

@coady

Version

1.21.0

What happened?

As of 1.21, querier interfaces are being generated with unused imports, breaking compilation. The configuration uses multiple packages, and of course emit_interface.

Relevant log output

// Code generated by sqlc. DO NOT EDIT.
 // versions:
-//   sqlc v1.20.0
+//   sqlc v1.21.0
 
 package testutilsql
 
 import (
 	"context"
+	"database/sql"
+	"time"
 
 	"github.com/google/uuid"
 )

Database schema

No response

SQL queries

No response

Configuration

- schema: "migrations"
  queries: "queries/testutil"
  engine: "postgresql"
  gen:
    go:
      out: "generated/testutilsql"
      emit_interface: true

Playground URL

No response

What operating system are you using?

No response

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Sep 6, 2023
  2. kyleconroy commented on Sep 6, 2023

    @kyleconroy
    Collaborator

    @coady Could you provide a bit more context here? In what files do the extra imports appear?

  3. verygoodsoftwarenotvirus commented on Sep 7, 2023

    @verygoodsoftwarenotvirus
    Contributor

    I also have this issue. For me, the file defined by output_querier_file_name in sqlc.yaml results in an extra import (in my case "time")

  4. iamwavecut commented on Sep 7, 2023

    @iamwavecut
    Contributor
    .../querier.go:11:2: "github.com/jackc/pgx/v5/pgtype" imported and not used) (typecheck)
    
  5. yangkenneth commented on Sep 7, 2023

    @yangkenneth

    Also seeing this problem, when setting emit_interface: true I'm getting a few extra import statements that aren't used.

    Unused Imports in db/sqlc/querier.go:

    	"github.com/sqlc-dev/pqtype"
    	"database/sql"
    	"time"
    

    sqlc.yaml Configuration:

    version: '1'
    packages:
      - name: 'db'
        path: './sqlc'
        queries: './query/'
        schema: './migration/'
        engine: 'postgresql'
        emit_json_tags: true
        emit_prepared_queries: false
        emit_interface: true
        emit_exact_table_names: false
        emit_empty_slices: true
        emit_result_struct_pointers: true
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions