Skip to content

The generated code does not import the required packages. #2459

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

Closed
J404J opened this issue Jul 14, 2023 · 1 comment · Fixed by #2597
Closed

The generated code does not import the required packages. #2459

J404J opened this issue Jul 14, 2023 · 1 comment · Fixed by #2597
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@J404J
Copy link

J404J commented Jul 14, 2023

Version

1.19.1

What happened?

  • What happened?
    When use query_parameter_limit config, the generated code does not import the package.
    And emit_interface=true, the generated Querier interface does not import the sql.NullTime or time package.

  • config:

query_parameter_limit: 2
emit_interface: true
  • SQL:
-- name: MarkNoticeDone :exec
UPDATE `notice`
SET `status`='done',
    `notice_at`=?
WHERE `id` = ?;

-- name: CreateNotice :exec
INSERT INTO `notice` (`cnt`, `created_at`)
VALUES (?, ?);
  • gen code:

notice.sql.go:

import (
	"context"
	"database/sql" // this line not gen
	"encoding/json"
	"time"
)

func (q *Queries) MarkNoticeDone(ctx context.Context, noticeAt sql.NullTime, iD uint64) error {
	_, err := q.exec(ctx, q.markNoticeDoneStmt, markNoticeDone, noticeAt, iD)
	return err
}

querier.go:

import (
	"context"
	"database/sql" // this line not gen
	"time" // this line not gen
)
type Querier interface {
	CreateNotice(ctx context.Context, cnt string, createdAt time.Time) error
	MarkNoticeDone(ctx context.Context, noticeAt sql.NullTime, iD uint64) error
}

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@J404J J404J added bug Something isn't working triage New issues that hasn't been reviewed labels Jul 14, 2023
@orisano
Copy link
Contributor

orisano commented Aug 8, 2023

playground link: https://play.sqlc.dev/p/b9e0761d640a923f653c42b2f4ea6577a922048fc55ca6183efbc4b8238cea70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants