sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
12.24k stars 778 forks source link

go_struct_tag is ignored for type override #3563

Open eduardomosko opened 2 weeks ago

eduardomosko commented 2 weeks ago

Version

1.27.0

What happened?

The config parameter go_struct_tag works as expected when overriding a column, but not when overriding a type.

With the attached config, I hoped that the generated type would be like:

type Author struct {
    ID   int64
    Name string
    Bio  *string `type_override:"doesnt_work"`
    Bio2 *string `column_override:"works!"`
}

but the actual type is:

type Author struct {
    ID   int64
    Name string
    Bio  *string
    Bio2 *string `column_override:"works!"`
}

Relevant log output

No response

Database schema

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

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1 LIMIT 1;

Configuration

{
  "version": "2",
  "sql": [
    {
      "schema": "schema.sql",
      "queries": "query.sql",
      "engine": "postgresql",
      "gen": {
        "go": {
          "out": "db",
          "overrides": [
            {
              "db_type": "text",
              "go_type": {
                "type": "string",
                "pointer": true
              },
              "nullable": true,
              "go_struct_tag": "type_override:\"doesnt_work\""
            },
            {
              "column": "authors.bio2",
              "go_type": {
                "type": "string",
                "pointer": true
              },
              "nullable": true,
              "go_struct_tag": "column_override:\"works!\""
            }
          ]
        }
      }
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/784492da14076cb054559e87ad78b0fdb311b7318db65b58564b8a5fa78b2469

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

eduardomosko commented 2 weeks ago

There seems to already be a PR addressing this issue: #3287 but I could take a look and try to simplify it