Add initial ParamEncoder and ResultDecoder support to core types

query-exec-mode
Jack Christensen 2021-09-04 11:30:36 -05:00
parent 2226a5e14e
commit 8f454e4cd6
46 changed files with 1632 additions and 6 deletions

37
new_pg_value.erb Normal file
View File

@ -0,0 +1,37 @@
package pgtype
<% skip_binary ||= false %>
<% skip_text ||= false %>
<% prefer_text_format ||= false %>
func (<%= go_type %>) BinaryFormatSupported() bool {
return true
}
func (<%= go_type %>) TextFormatSupported() bool {
return true
}
func (<%= go_type %>) PreferredFormat() int16 {
return <%= prefer_text_format ? "Text" : "Binary" %>FormatCode
}
func (dst *<%= go_type %>) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
<% if skip_binary %> return fmt.Errorf("binary format not supported for %T", dst) <% else %> return dst.DecodeBinary(ci, src) <% end %>
case TextFormatCode:
<% if skip_text %> return fmt.Errorf("text format not supported for %T", dst) <% else %> return dst.DecodeText(ci, src) <% end %>
}
return fmt.Errorf("unknown format code %d", format)
}
func (src <%= go_type %>) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
<% if skip_binary %>return nil, fmt.Errorf("binary format not supported for %T", src)<% else %>return src.EncodeBinary(ci, buf)<% end %>
case TextFormatCode:
<% if skip_text %>return nil, fmt.Errorf("text format not supported for %T", src)<% else %>return src.EncodeText(ci, buf)<% end %>
}
return nil, fmt.Errorf("unknown format code %d", format)
}

45
new_pg_value_gen.sh Normal file
View File

@ -0,0 +1,45 @@
erb go_type=ACLItem skip_binary=true prefer_text_format=true new_pg_value.erb > zzz.aclitem.go
erb go_type=Bit new_pg_value.erb > zzz.bit.go
erb go_type=Bool new_pg_value.erb > zzz.bool.go
erb go_type=Box new_pg_value.erb > zzz.box.go
erb go_type=BPChar prefer_text_format=true new_pg_value.erb > zzz.bpchar.go
erb go_type=Bytea new_pg_value.erb > zzz.bytea.go
erb go_type=CID new_pg_value.erb > zzz.cid.go
erb go_type=CIDR new_pg_value.erb > zzz.cidr.go
erb go_type=Circle new_pg_value.erb > zzz.circle.go
erb go_type=Date new_pg_value.erb > zzz.date.go
erb go_type=Float4 new_pg_value.erb > zzz.float4.go
erb go_type=Float8 new_pg_value.erb > zzz.float8.go
erb go_type=GenericBinary skip_text=true new_pg_value.erb > zzz.generic_binary.go
erb go_type=GenericText skip_binary=true prefer_text_format=true new_pg_value.erb > zzz.generic_text.go
erb go_type=Hstore new_pg_value.erb > zzz.hstore.go
erb go_type=Inet new_pg_value.erb > zzz.inet.go
erb go_type=Int2 new_pg_value.erb > zzz.int2.go
erb go_type=Int4 new_pg_value.erb > zzz.int4.go
erb go_type=Int8 new_pg_value.erb > zzz.int8.go
erb go_type=Interval new_pg_value.erb > zzz.interval.go
erb go_type=JSON prefer_text_format=true new_pg_value.erb > zzz.json.go
erb go_type=JSONB prefer_text_format=true new_pg_value.erb > zzz.jsonb.go
erb go_type=Line new_pg_value.erb > zzz.line.go
erb go_type=Lseg new_pg_value.erb > zzz.lseg.go
erb go_type=Macaddr new_pg_value.erb > zzz.macadder.go
erb go_type=Name new_pg_value.erb > zzz.name.go
erb go_type=Numeric new_pg_value.erb > zzz.numeric.go
erb go_type=OIDValue new_pg_value.erb > zzz.oid_value.go
erb go_type=OID new_pg_value.erb > zzz.oid.go
erb go_type=Path new_pg_value.erb > zzz.path.go
erb go_type=pguint32 new_pg_value.erb > zzz.pguint32.go
erb go_type=Point new_pg_value.erb > zzz.point.go
erb go_type=Polygon new_pg_value.erb > zzz.polygon.go
erb go_type=QChar skip_text=true new_pg_value.erb > zzz.qchar.go
erb go_type=Text prefer_text_format=true new_pg_value.erb > zzz.text.go
erb go_type=TID new_pg_value.erb > zzz.tid.go
erb go_type=Time new_pg_value.erb > zzz.time.go
erb go_type=Timestamp new_pg_value.erb > zzz.timestamp.go
erb go_type=Timestamptz new_pg_value.erb > zzz.timestamptz.go
# erb go_type=Unknown new_pg_value.erb > zzz.unknown.go
erb go_type=UUID new_pg_value.erb > zzz.uuid.go
erb go_type=Varbit new_pg_value.erb > zzz.varbit.go
erb go_type=Varchar prefer_text_format=true new_pg_value.erb > zzz.varchar.go
erb go_type=XID new_pg_value.erb > zzz.xid.go
goimports -w zzz.*

View File

@ -153,6 +153,22 @@ type ValueTranscoder interface {
BinaryDecoder
}
type FormatSupport interface {
BinaryFormatSupported() bool
TextFormatSupported() bool
PreferredFormat() int16
}
type ParamEncoder interface {
FormatSupport
EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error)
}
type ResultDecoder interface {
FormatSupport
DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error
}
// ResultFormatPreferrer allows a type to specify its preferred result format instead of it being inferred from
// whether it is also a BinaryDecoder.
type ResultFormatPreferrer interface {
@ -210,6 +226,8 @@ func (e *nullAssignmentError) Error() string {
type DataType struct {
Value Value
resultDecoder ResultDecoder
textDecoder TextDecoder
binaryDecoder BinaryDecoder
@ -380,7 +398,9 @@ func (ci *ConnInfo) RegisterDataType(t DataType) {
{
var formatCode int16
if rfp, ok := t.Value.(ResultFormatPreferrer); ok {
if fs, ok := t.Value.(FormatSupport); ok {
formatCode = fs.PreferredFormat()
} else if rfp, ok := t.Value.(ResultFormatPreferrer); ok {
formatCode = rfp.PreferredResultFormat()
} else if _, ok := t.Value.(BinaryDecoder); ok {
formatCode = BinaryFormatCode
@ -388,6 +408,10 @@ func (ci *ConnInfo) RegisterDataType(t DataType) {
ci.oidToResultFormatCode[t.OID] = formatCode
}
if d, ok := t.Value.(ResultDecoder); ok {
t.resultDecoder = d
}
if d, ok := t.Value.(TextDecoder); ok {
t.textDecoder = d
}
@ -478,6 +502,17 @@ type ScanPlan interface {
Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error
}
type scanPlanDstResultDecoder struct{}
func (scanPlanDstResultDecoder) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
if d, ok := (dst).(ResultDecoder); ok {
return d.DecodeResult(ci, oid, formatCode, src)
}
newPlan := ci.PlanScan(oid, formatCode, dst)
return newPlan.Scan(ci, oid, formatCode, src, dst)
}
type scanPlanDstBinaryDecoder struct{}
func (scanPlanDstBinaryDecoder) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
@ -533,11 +568,15 @@ type scanPlanDataTypeAssignTo DataType
func (plan *scanPlanDataTypeAssignTo) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
dt := (*DataType)(plan)
var err error
switch formatCode {
case BinaryFormatCode:
err = dt.binaryDecoder.DecodeBinary(ci, src)
case TextFormatCode:
err = dt.textDecoder.DecodeText(ci, src)
if dt.resultDecoder != nil {
err = dt.resultDecoder.DecodeResult(ci, oid, formatCode, src)
} else {
switch formatCode {
case BinaryFormatCode:
err = dt.binaryDecoder.DecodeBinary(ci, src)
case TextFormatCode:
err = dt.textDecoder.DecodeText(ci, src)
}
}
if err != nil {
return err

35
zzz.aclitem.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (ACLItem) BinaryFormatSupported() bool {
return true
}
func (ACLItem) TextFormatSupported() bool {
return true
}
func (ACLItem) PreferredFormat() int16 {
return TextFormatCode
}
func (dst *ACLItem) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return fmt.Errorf("binary format not supported for %T", dst)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src ACLItem) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return nil, fmt.Errorf("binary format not supported for %T", src)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.bit.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Bit) BinaryFormatSupported() bool {
return true
}
func (Bit) TextFormatSupported() bool {
return true
}
func (Bit) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Bit) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Bit) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.bool.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Bool) BinaryFormatSupported() bool {
return true
}
func (Bool) TextFormatSupported() bool {
return true
}
func (Bool) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Bool) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Bool) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.box.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Box) BinaryFormatSupported() bool {
return true
}
func (Box) TextFormatSupported() bool {
return true
}
func (Box) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Box) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Box) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.bpchar.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (BPChar) BinaryFormatSupported() bool {
return true
}
func (BPChar) TextFormatSupported() bool {
return true
}
func (BPChar) PreferredFormat() int16 {
return TextFormatCode
}
func (dst *BPChar) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src BPChar) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.bytea.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Bytea) BinaryFormatSupported() bool {
return true
}
func (Bytea) TextFormatSupported() bool {
return true
}
func (Bytea) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Bytea) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Bytea) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.cid.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (CID) BinaryFormatSupported() bool {
return true
}
func (CID) TextFormatSupported() bool {
return true
}
func (CID) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *CID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src CID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.cidr.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (CIDR) BinaryFormatSupported() bool {
return true
}
func (CIDR) TextFormatSupported() bool {
return true
}
func (CIDR) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *CIDR) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src CIDR) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.circle.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Circle) BinaryFormatSupported() bool {
return true
}
func (Circle) TextFormatSupported() bool {
return true
}
func (Circle) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Circle) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Circle) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.date.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Date) BinaryFormatSupported() bool {
return true
}
func (Date) TextFormatSupported() bool {
return true
}
func (Date) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Date) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Date) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.float4.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Float4) BinaryFormatSupported() bool {
return true
}
func (Float4) TextFormatSupported() bool {
return true
}
func (Float4) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Float4) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Float4) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.float8.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Float8) BinaryFormatSupported() bool {
return true
}
func (Float8) TextFormatSupported() bool {
return true
}
func (Float8) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Float8) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Float8) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.generic_binary.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (GenericBinary) BinaryFormatSupported() bool {
return true
}
func (GenericBinary) TextFormatSupported() bool {
return true
}
func (GenericBinary) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *GenericBinary) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return fmt.Errorf("text format not supported for %T", dst)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src GenericBinary) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return nil, fmt.Errorf("text format not supported for %T", src)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.generic_text.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (GenericText) BinaryFormatSupported() bool {
return true
}
func (GenericText) TextFormatSupported() bool {
return true
}
func (GenericText) PreferredFormat() int16 {
return TextFormatCode
}
func (dst *GenericText) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return fmt.Errorf("binary format not supported for %T", dst)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src GenericText) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return nil, fmt.Errorf("binary format not supported for %T", src)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.hstore.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Hstore) BinaryFormatSupported() bool {
return true
}
func (Hstore) TextFormatSupported() bool {
return true
}
func (Hstore) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Hstore) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Hstore) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.inet.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Inet) BinaryFormatSupported() bool {
return true
}
func (Inet) TextFormatSupported() bool {
return true
}
func (Inet) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Inet) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Inet) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.int2.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Int2) BinaryFormatSupported() bool {
return true
}
func (Int2) TextFormatSupported() bool {
return true
}
func (Int2) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Int2) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Int2) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.int4.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Int4) BinaryFormatSupported() bool {
return true
}
func (Int4) TextFormatSupported() bool {
return true
}
func (Int4) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Int4) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Int4) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.int8.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Int8) BinaryFormatSupported() bool {
return true
}
func (Int8) TextFormatSupported() bool {
return true
}
func (Int8) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Int8) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Int8) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.interval.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Interval) BinaryFormatSupported() bool {
return true
}
func (Interval) TextFormatSupported() bool {
return true
}
func (Interval) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Interval) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Interval) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.json.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (JSON) BinaryFormatSupported() bool {
return true
}
func (JSON) TextFormatSupported() bool {
return true
}
func (JSON) PreferredFormat() int16 {
return TextFormatCode
}
func (dst *JSON) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src JSON) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.jsonb.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (JSONB) BinaryFormatSupported() bool {
return true
}
func (JSONB) TextFormatSupported() bool {
return true
}
func (JSONB) PreferredFormat() int16 {
return TextFormatCode
}
func (dst *JSONB) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src JSONB) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.line.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Line) BinaryFormatSupported() bool {
return true
}
func (Line) TextFormatSupported() bool {
return true
}
func (Line) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Line) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Line) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.lseg.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Lseg) BinaryFormatSupported() bool {
return true
}
func (Lseg) TextFormatSupported() bool {
return true
}
func (Lseg) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Lseg) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Lseg) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.macadder.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Macaddr) BinaryFormatSupported() bool {
return true
}
func (Macaddr) TextFormatSupported() bool {
return true
}
func (Macaddr) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Macaddr) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Macaddr) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.name.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Name) BinaryFormatSupported() bool {
return true
}
func (Name) TextFormatSupported() bool {
return true
}
func (Name) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Name) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Name) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.numeric.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Numeric) BinaryFormatSupported() bool {
return true
}
func (Numeric) TextFormatSupported() bool {
return true
}
func (Numeric) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Numeric) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Numeric) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.oid.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (OID) BinaryFormatSupported() bool {
return true
}
func (OID) TextFormatSupported() bool {
return true
}
func (OID) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *OID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src OID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.oid_value.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (OIDValue) BinaryFormatSupported() bool {
return true
}
func (OIDValue) TextFormatSupported() bool {
return true
}
func (OIDValue) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *OIDValue) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src OIDValue) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.path.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Path) BinaryFormatSupported() bool {
return true
}
func (Path) TextFormatSupported() bool {
return true
}
func (Path) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Path) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Path) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.pguint32.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (pguint32) BinaryFormatSupported() bool {
return true
}
func (pguint32) TextFormatSupported() bool {
return true
}
func (pguint32) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *pguint32) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src pguint32) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.point.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Point) BinaryFormatSupported() bool {
return true
}
func (Point) TextFormatSupported() bool {
return true
}
func (Point) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Point) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Point) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.polygon.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Polygon) BinaryFormatSupported() bool {
return true
}
func (Polygon) TextFormatSupported() bool {
return true
}
func (Polygon) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Polygon) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Polygon) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.qchar.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (QChar) BinaryFormatSupported() bool {
return true
}
func (QChar) TextFormatSupported() bool {
return true
}
func (QChar) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *QChar) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return fmt.Errorf("text format not supported for %T", dst)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src QChar) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return nil, fmt.Errorf("text format not supported for %T", src)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.text.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Text) BinaryFormatSupported() bool {
return true
}
func (Text) TextFormatSupported() bool {
return true
}
func (Text) PreferredFormat() int16 {
return TextFormatCode
}
func (dst *Text) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Text) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.tid.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (TID) BinaryFormatSupported() bool {
return true
}
func (TID) TextFormatSupported() bool {
return true
}
func (TID) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *TID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src TID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.time.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Time) BinaryFormatSupported() bool {
return true
}
func (Time) TextFormatSupported() bool {
return true
}
func (Time) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Time) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Time) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.timestamp.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Timestamp) BinaryFormatSupported() bool {
return true
}
func (Timestamp) TextFormatSupported() bool {
return true
}
func (Timestamp) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Timestamp) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Timestamp) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.timestamptz.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Timestamptz) BinaryFormatSupported() bool {
return true
}
func (Timestamptz) TextFormatSupported() bool {
return true
}
func (Timestamptz) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Timestamptz) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Timestamptz) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.uuid.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (UUID) BinaryFormatSupported() bool {
return true
}
func (UUID) TextFormatSupported() bool {
return true
}
func (UUID) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *UUID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src UUID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.varbit.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Varbit) BinaryFormatSupported() bool {
return true
}
func (Varbit) TextFormatSupported() bool {
return true
}
func (Varbit) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *Varbit) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Varbit) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.varchar.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (Varchar) BinaryFormatSupported() bool {
return true
}
func (Varchar) TextFormatSupported() bool {
return true
}
func (Varchar) PreferredFormat() int16 {
return TextFormatCode
}
func (dst *Varchar) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src Varchar) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}

35
zzz.xid.go Normal file
View File

@ -0,0 +1,35 @@
package pgtype
import "fmt"
func (XID) BinaryFormatSupported() bool {
return true
}
func (XID) TextFormatSupported() bool {
return true
}
func (XID) PreferredFormat() int16 {
return BinaryFormatCode
}
func (dst *XID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
switch format {
case BinaryFormatCode:
return dst.DecodeBinary(ci, src)
case TextFormatCode:
return dst.DecodeText(ci, src)
}
return fmt.Errorf("unknown format code %d", format)
}
func (src XID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
switch format {
case BinaryFormatCode:
return src.EncodeBinary(ci, buf)
case TextFormatCode:
return src.EncodeText(ci, buf)
}
return nil, fmt.Errorf("unknown format code %d", format)
}