pgtype
pgtype copied to clipboard
EnumArray does not implement ValueTranscoder
Not sure if this is on purpose or was just an oversight (if it is purpose please feel free to close this), but EnumArray
does not implement ValueTranscoder
so users must implement their own custom type with func's EncodeText
and DecodeText
utilizing EnumArray::DecodeText
and EnumArray::EncodeText
under the hood. This makes it much more difficult to do binary encoding/decoding (user's must fully implement everything for their custom types) or register data types in pgx
simply using a line like:
conn.ConnInfo().RegisterDataType(pgtype.DataType{Value: pgtype.NewArrayType("pg_enum_typname", 1234, func() pgtype.ValueTranscoder { return &pgtype.EnumArray{} }), Name: "pg_enum_typname", OID: oid})
I don't remember why EnumArray
doesn't implement the binary format because the binary format for an array requires knowing the OID of the element.
I think if you want to register an enum array type you would use NewArrayType
, but with GenericText
as the element. You don't need an array of arrays.
Ahh, that makes sense. So the ValueTranscoder
is meant to operate on a singular element of the array vs the entire array. Unfortunately it looks like GenericText
can't be used directly as a ValueTranscoder
as it also doesn't implement the binary format.
Unfortunately it looks like GenericText can't be used directly as a ValueTranscoder as it also doesn't implement the binary format.
Ah, true. Hmmm, the regular Text
type does implement the binary format. Could try that.