Unclear on expected usage of pgtype JSONB #1332
-
Trying to transition an existing project over to using sqlc, and all was well until I needed to use a
version: 1
packages:
- path: "pkg/models"
engine: "postgresql"
schema: "sql/schema/"
queries: "sql/queries/"
sql_package: "pgx/v4"
emit_json_tags: true
emit_exported_queries: true
CREATE TABLE IF NOT EXISTS player (
...
skills jsonb
);
type Player struct {
...
Skills pgtype.JSONB `json:"skills"`
} I've gotten it to work by defining an internal struct and using the Set() method on the JSONB type..
type skillJSONB struct {
Name string `json:"name"`
Value int16 `json:"value"`
}
p := models.Player{}
p.Skills.Set(skillJSONB {
Name: "foo",
Value: 1,
}) And then I copy over the field to the return &models.CreatePlayerParams {
...
Skills: p.Skills,
} Is this the expected way to be handling this? I saw on #819 that a user is using the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You're using the pgx / jsonb support the correct way. Using overrides is only necessary if you want to map the Skills column to a specific Go type. |
Beta Was this translation helpful? Give feedback.
You're using the pgx / jsonb support the correct way. Using overrides is only necessary if you want to map the Skills column to a specific Go type.