Replies: 1 comment
-
|
Use Override the type mapping in version: "2"
sql:
- engine: "postgresql"
queries: ["query.sql"]
schema: ["schema.sql"]
gen:
go:
package: "model"
out: "model"
sql_package: "pgx/v5"
overrides:
- db_type: "jsonb"
go_type: "encoding/json.RawMessage"After regenerating, the field becomes: type Category struct {
SpecTemplate json.RawMessage `json:"spec_template"`
}
If you need the field to be nullable, use For |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Description
When using
sqlcwith PostgreSQL andpgx/v5, columns of typeJSONBare generated as[]bytein the Go model. This causes standard JSON marshaling (e.g., via Gin orencoding/json) to encode the field as a Base64 string instead of the expected raw JSON object.For example, a
spec_template JSONB NOT NULLcolumn becomes:When serialized:
how should i do?
here is all code:
Beta Was this translation helpful? Give feedback.
All reactions