Problem DescriptionWhen usingsqlc with PostgreSQL andpgx/v5, columns of typeJSONB are generated as[]byte in the Go model. This causes standard JSON marshaling (e.g., via Gin orencoding/json) to encode the field as aBase64 string instead of the expectedraw JSON object. For example, aspec_template JSONB NOT NULL column becomes: typeCategorystruct {SpecTemplate []byte`json:"spec_template"`}When serialized: { "spec_template": "eyJuYW1lIjogInRlc3QifQ==" // ← Base64, not {"name":"test"}}
how should i do? here is all code: version: "2"sql: - engine: "postgresql" queries: - "query.sql" schema: - "schema.sql" gen: go: package: "model" out: "model" sql_package: "pgx/v5"
CREATE TABLE category ( id BIGSERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, parent_id BIGINT REFERENCES category(id) DEFAULT NULL, spec_template JSONB NOT NULL, sort INT NOT NULL DEFAULT 0, created_at TIMESTAMP NOT NULL DEFAULT NOW());
const listCategories = `-- name: ListCategories :manySELECT id, name, parent_id, spec_template, sort, created_at FROM category ORDER BY sort ASC, created_at DESC`func (q *Queries) ListCategories(ctx context.Context) ([]Category, error) {rows, err := q.db.Query(ctx, listCategories)if err != nil {return nil, err}defer rows.Close()var items []Categoryfor rows.Next() {var i Categoryif err := rows.Scan(&i.ID,&i.Name,&i.ParentID,&i.SpecTemplate,&i.Sort,&i.CreatedAt,); err != nil {return nil, err}items = append(items, i)}if err := rows.Err(); err != nil {return nil, err}return items, nil}
{ "SpecTemplate": "eyLlhoXlrZgiOiBbIjRHQiIsICI2R0IiLCAiOEdCIiwgIjEyR0IiLCAiMTZHQiJdLCAi5a2Y5YKoIjogWyI2NEdCIiwgIjEyOEdCIiwgIjI1NkdCIiwgIjUxMkdCIiwgIjFUQiJdLCAi6aKc6ImyIjogWyLpu5HoibIiLCAi55m96ImyIiwgIuiTneiJsiIsICLnuqLoibIiLCAi6YeR6ImyIl19", },
|