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

omit_unused_structs ignores enum when used with sqlc.embed #2860

Closed
Andy-William opened this issue Oct 16, 2023 · 0 comments · Fixed by #2868
Closed

omit_unused_structs ignores enum when used with sqlc.embed #2860

Andy-William opened this issue Oct 16, 2023 · 0 comments · Fixed by #2868

Comments

@Andy-William
Copy link

Andy-William commented Oct 16, 2023

Version

1.22.0

What happened?

When omit_unused_structs is set to true, enums inside an sqlc.embed is ignored. This can cause invalid golang code due to undefined type on the model.

Can be circumvented by creating another query without embed just so the enum model exists in the generated code.

Relevant log output

check generated models.go

Database schema

CREATE TYPE enumtype AS ENUM('a','b');

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  e enumtype not null
);

SQL queries

-- name: GetAllAuthors :one
SELECT sqlc.embed(authors) FROM authors;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "postgresql",
      "schema": "query.sql",
      "queries": "query.sql",
      "omit_unused_structs": true
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/2203df48ffefbead62b4871ccb2269b8cdd425c64c27108b7857d79c89a5596d

What operating system are you using?

Linux, Windows

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@Andy-William Andy-William added bug Something isn't working triage New issues that hasn't been reviewed labels Oct 16, 2023
@andrewmbenton andrewmbenton added 🔧 golang and removed bug Something isn't working triage New issues that hasn't been reviewed labels Oct 16, 2023
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.

2 participants