Jsonb codec
#1619
Replies: 1 comment 4 replies
-
You don't use |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
using v5 now the jsonb scan has changed somehow and I need to get help how to scan a marshalled json value into a struct field of type jsonbcodec, below is an example of what I'm trying to do in order to assign to jsonbcodec field a json value, but it does not work, so something for sure I'm doing wrong and need your help understanding the new api.
import "github.com/jackc/pgx/v5/pgtype"
type Example struct {
Field pgtype.JSONBCodec `json:"field"`
}
type Custom struct {
Field1 string `json:"field1"`
Field2 string `json:"field2"`
}
a := []Custom {
{
Field1: "test1",
Field2: "test2" ,
},
}
marshalledA, _:= json.Marshal(a)
example:=&Example{}
m:=pgtype.NewMap()
err:=pgtype.JSONBCodec{}.PlanScan(m, pgtype.JSONBArrayOID, pgx.TextFormatCode, &example.Field).Scan(marshalledA, &example.Field)
fmt.Println(err)
Beta Was this translation helpful? Give feedback.
All reactions