Skip to content

Allow go_struct_tag to be applicable to aliases #4020

@dandee

Description

@dandee

What do you want to change?

I'd like to see go_struct_tag to be applicable to aliases to column names.

Version

1.29.0

What happened?

sqlc does not allow to apply custom struct tag to aliases in the generated structs returned by query functions.

In the provided Playground URL I'd like to see GetTestRow struct to be annotated as following in the "db.query.sql.go":

type GetTestRow struct {
	ID         int64
	Name       string `tstype:"SomeType"`
	CategoryID sql.NullInt64
	Count      int64 `tstype:"AnotherType"`
}

Database schema

CREATE TABLE parts (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  category_id BIGSERIAL
);

SQL queries

-- name: GetTest :many
SELECT *, count(*) AS count
FROM parts;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db",
        "overrides": [
          {
        	"go_struct_tag": "tstype:\"SomeType\"",
            "column": "*.name"
          },
          {
        	"go_struct_tag": "tstype:\"AnotherType\"",
            "column": "*.count"
          }
        ]
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/5c4dab574d896da3bab9fd3be11b7da097885ece239d574449ba98fd20da3e3e

BTW: Playground doesn't provide any version above 1.25 :(

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

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