sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

override for json not working in golang

Open julian-reactive opened this issue 6 months ago • 1 comments

Version

1.29.0

What happened?

set overrides for a field type json is not working

Image

Image

sqlc generate

Image

GetOrderProductsRow.Additionals should be json cutom type not []byte

Relevant log output


Database schema

CREATE TABLE public.order_products (
	id bigserial NOT NULL,
	product_amount int4 NULL,
	additionals json NULL,
	order_id uuid NOT NULL,
	product_id uuid NOT NULL,
	created_at timestamp(6) NOT NULL,
	updated_at timestamp(6) NOT NULL,
	deleted bool DEFAULT false NULL,
	product_price float8 NULL,
	CONSTRAINT order_products_order_id_product_id_key UNIQUE (order_id, product_id),
	CONSTRAINT order_products_pkey PRIMARY KEY (id),
	CONSTRAINT fk_rails_96c0709f78 FOREIGN KEY (product_id) REFERENCES public.products(id),
	CONSTRAINT fk_rails_f40b8ccee4 FOREIGN KEY (order_id) REFERENCES public.orders(id)
);

SQL queries

-- name: GetOrderProducts :many
SELECT
  op.id,
  op.product_amount,
  op.additionals,
  op.product_price,
  p.name AS product_name
FROM order_products op
JOIN products p ON op.product_id = p.id
WHERE op.order_id = $1;

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "db/queries"
    schema: "db/migrations"
    gen:
      go:
        package: "db"
        sql_package: "pgx/v5"
        out: "internal/db"
        overrides:
          - db_type: "json"
            go_type: "encoding/json.RawMessage"

Playground URL

No response

What operating system are you using?

mac and linux

What database engines are you using?

postgresql

What type of code are you generating?

No response

julian-reactive avatar Jun 03 '25 00:06 julian-reactive

I downgraded to version 1.28.0 and it works.

tuanvumaihuynh avatar Jun 16 '25 03:06 tuanvumaihuynh

I have a bunch of json/jsonb columns, functions and casts, doing exhaustive overrides got rid of all the []byte outputs

  overrides:
    - db_type: "pg_catalog.json"
      go_type: "encoding/json.RawMessage"

    - db_type: "pg_catalog.json"
      go_type: "encoding/json.RawMessage"
      nullable: true

    - db_type: "json"
      go_type: "encoding/json.RawMessage"

    - db_type: "json"
      go_type: "encoding/json.RawMessage"
      nullable: true

    - db_type: "jsonb"
      go_type: "encoding/json.RawMessage"

    - db_type: "jsonb"
      go_type: "encoding/json.RawMessage"
      nullable: true

    - db_type: "pg_catalog.jsonb"
      go_type: "encoding/json.RawMessage"

    - db_type: "pg_catalog.jsonb"
      go_type: "encoding/json.RawMessage"
      nullable: true

XMitja avatar Jun 30 '25 12:06 XMitja