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

go_struct_tag is missing for generated result row struct (or how to configure it) #1867

Closed
avucic opened this issue Sep 28, 2022 · 1 comment · Fixed by #1887
Closed

go_struct_tag is missing for generated result row struct (or how to configure it) #1867

avucic opened this issue Sep 28, 2022 · 1 comment · Fixed by #1887

Comments

@avucic
Copy link

avucic commented Sep 28, 2022

Version

1.15.0

What happened?

When I use given configuration I can see generated tag in models file.

type Account struct {
	ID          uuid.UUID `sometagtype:"some_value"`
	State       sql.NullString
       # ... rest of the fields
}

However generated struct for my query doesn't contain mentioned tag;

type FindAccountByEmailRow struct {
	ID           uuid.UUID
	State        sql.NullString
       # ... rest of the fields
}

When I use option: emit_json_tags: true I can see json tag in both places

So my question is if this is a problem or if the generator needs to be configured differently.

Relevant log output

No response

Database schema

CREATE TABLE public.accounts (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    state character varying,
);

SQL queries

-- name: FindAccountByEmail :one
SELECT
    c.id AS credential_id,
    a.*,
    u.first_name,
    u.last_name,
    -- other fields
FROM
    accounts a
    INNER JOIN users_accounts ua ON a.id = ua.account_id
    INNER JOIN users u ON ua.user_id = u.id
    INNER JOIN credentials c ON c.account_id = a.id
WHERE
    c.email = @email;

Configuration

version: "2"
sql:
  - schema: "db/structure.sql"
    queries: "db/queries.sql"
    engine: "postgresql"
    gen:
      go:
        package: "db"
        out: "db"
        overrides:
          - column: accounts.id
            go_struct_tag: sometagtype:"some_value"

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@avucic avucic added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 28, 2022
akutschera added a commit to akutschera/sqlc that referenced this issue Oct 8, 2022
@akutschera
Copy link
Contributor

akutschera commented Oct 8, 2022

If I understand you correctly, you expect the following output

type FindAccountByEmailRow struct {
	ID           uuid.UUID `sometagtype:"some_value"`
	State        sql.NullString
       # ... rest of the fields
}

You want the field in the result struct to have the same annotation as the corresponding field in the models struct. Since this works with emit_json_tags: true as you stated, I would assume this is a bug.
The commit above would fix that.

@kyleconroy kyleconroy added 📚 postgresql 🔧 golang 💻 darwin and removed triage New issues that hasn't been reviewed labels Nov 9, 2022
kyleconroy added a commit that referenced this issue Jun 7, 2023
* fix: add override tags to result struct (#1867)

* Update test output for latest version

---------

Co-authored-by: Kyle Conroy <kyle@conroy.org>
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