From 8f454e4cd6966adecea27084d8d22ec1829a5911 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 4 Sep 2021 11:30:36 -0500 Subject: [PATCH] Add initial ParamEncoder and ResultDecoder support to core types --- new_pg_value.erb | 37 +++++++++++++++++++++++++++++++ new_pg_value_gen.sh | 45 ++++++++++++++++++++++++++++++++++++++ pgtype.go | 51 ++++++++++++++++++++++++++++++++++++++----- zzz.aclitem.go | 35 +++++++++++++++++++++++++++++ zzz.bit.go | 35 +++++++++++++++++++++++++++++ zzz.bool.go | 35 +++++++++++++++++++++++++++++ zzz.box.go | 35 +++++++++++++++++++++++++++++ zzz.bpchar.go | 35 +++++++++++++++++++++++++++++ zzz.bytea.go | 35 +++++++++++++++++++++++++++++ zzz.cid.go | 35 +++++++++++++++++++++++++++++ zzz.cidr.go | 35 +++++++++++++++++++++++++++++ zzz.circle.go | 35 +++++++++++++++++++++++++++++ zzz.date.go | 35 +++++++++++++++++++++++++++++ zzz.float4.go | 35 +++++++++++++++++++++++++++++ zzz.float8.go | 35 +++++++++++++++++++++++++++++ zzz.generic_binary.go | 35 +++++++++++++++++++++++++++++ zzz.generic_text.go | 35 +++++++++++++++++++++++++++++ zzz.hstore.go | 35 +++++++++++++++++++++++++++++ zzz.inet.go | 35 +++++++++++++++++++++++++++++ zzz.int2.go | 35 +++++++++++++++++++++++++++++ zzz.int4.go | 35 +++++++++++++++++++++++++++++ zzz.int8.go | 35 +++++++++++++++++++++++++++++ zzz.interval.go | 35 +++++++++++++++++++++++++++++ zzz.json.go | 35 +++++++++++++++++++++++++++++ zzz.jsonb.go | 35 +++++++++++++++++++++++++++++ zzz.line.go | 35 +++++++++++++++++++++++++++++ zzz.lseg.go | 35 +++++++++++++++++++++++++++++ zzz.macadder.go | 35 +++++++++++++++++++++++++++++ zzz.name.go | 35 +++++++++++++++++++++++++++++ zzz.numeric.go | 35 +++++++++++++++++++++++++++++ zzz.oid.go | 35 +++++++++++++++++++++++++++++ zzz.oid_value.go | 35 +++++++++++++++++++++++++++++ zzz.path.go | 35 +++++++++++++++++++++++++++++ zzz.pguint32.go | 35 +++++++++++++++++++++++++++++ zzz.point.go | 35 +++++++++++++++++++++++++++++ zzz.polygon.go | 35 +++++++++++++++++++++++++++++ zzz.qchar.go | 35 +++++++++++++++++++++++++++++ zzz.text.go | 35 +++++++++++++++++++++++++++++ zzz.tid.go | 35 +++++++++++++++++++++++++++++ zzz.time.go | 35 +++++++++++++++++++++++++++++ zzz.timestamp.go | 35 +++++++++++++++++++++++++++++ zzz.timestamptz.go | 35 +++++++++++++++++++++++++++++ zzz.uuid.go | 35 +++++++++++++++++++++++++++++ zzz.varbit.go | 35 +++++++++++++++++++++++++++++ zzz.varchar.go | 35 +++++++++++++++++++++++++++++ zzz.xid.go | 35 +++++++++++++++++++++++++++++ 46 files changed, 1632 insertions(+), 6 deletions(-) create mode 100644 new_pg_value.erb create mode 100644 new_pg_value_gen.sh create mode 100644 zzz.aclitem.go create mode 100644 zzz.bit.go create mode 100644 zzz.bool.go create mode 100644 zzz.box.go create mode 100644 zzz.bpchar.go create mode 100644 zzz.bytea.go create mode 100644 zzz.cid.go create mode 100644 zzz.cidr.go create mode 100644 zzz.circle.go create mode 100644 zzz.date.go create mode 100644 zzz.float4.go create mode 100644 zzz.float8.go create mode 100644 zzz.generic_binary.go create mode 100644 zzz.generic_text.go create mode 100644 zzz.hstore.go create mode 100644 zzz.inet.go create mode 100644 zzz.int2.go create mode 100644 zzz.int4.go create mode 100644 zzz.int8.go create mode 100644 zzz.interval.go create mode 100644 zzz.json.go create mode 100644 zzz.jsonb.go create mode 100644 zzz.line.go create mode 100644 zzz.lseg.go create mode 100644 zzz.macadder.go create mode 100644 zzz.name.go create mode 100644 zzz.numeric.go create mode 100644 zzz.oid.go create mode 100644 zzz.oid_value.go create mode 100644 zzz.path.go create mode 100644 zzz.pguint32.go create mode 100644 zzz.point.go create mode 100644 zzz.polygon.go create mode 100644 zzz.qchar.go create mode 100644 zzz.text.go create mode 100644 zzz.tid.go create mode 100644 zzz.time.go create mode 100644 zzz.timestamp.go create mode 100644 zzz.timestamptz.go create mode 100644 zzz.uuid.go create mode 100644 zzz.varbit.go create mode 100644 zzz.varchar.go create mode 100644 zzz.xid.go diff --git a/new_pg_value.erb b/new_pg_value.erb new file mode 100644 index 00000000..71a0da7f --- /dev/null +++ b/new_pg_value.erb @@ -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) +} diff --git a/new_pg_value_gen.sh b/new_pg_value_gen.sh new file mode 100644 index 00000000..3dad08de --- /dev/null +++ b/new_pg_value_gen.sh @@ -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.* diff --git a/pgtype.go b/pgtype.go index 4fa6eebe..b9067fab 100644 --- a/pgtype.go +++ b/pgtype.go @@ -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 diff --git a/zzz.aclitem.go b/zzz.aclitem.go new file mode 100644 index 00000000..6ac1f94a --- /dev/null +++ b/zzz.aclitem.go @@ -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) +} diff --git a/zzz.bit.go b/zzz.bit.go new file mode 100644 index 00000000..e95df74d --- /dev/null +++ b/zzz.bit.go @@ -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) +} diff --git a/zzz.bool.go b/zzz.bool.go new file mode 100644 index 00000000..e6ed52de --- /dev/null +++ b/zzz.bool.go @@ -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) +} diff --git a/zzz.box.go b/zzz.box.go new file mode 100644 index 00000000..5ca2df43 --- /dev/null +++ b/zzz.box.go @@ -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) +} diff --git a/zzz.bpchar.go b/zzz.bpchar.go new file mode 100644 index 00000000..c3178670 --- /dev/null +++ b/zzz.bpchar.go @@ -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) +} diff --git a/zzz.bytea.go b/zzz.bytea.go new file mode 100644 index 00000000..4da5ad4f --- /dev/null +++ b/zzz.bytea.go @@ -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) +} diff --git a/zzz.cid.go b/zzz.cid.go new file mode 100644 index 00000000..4cb9671d --- /dev/null +++ b/zzz.cid.go @@ -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) +} diff --git a/zzz.cidr.go b/zzz.cidr.go new file mode 100644 index 00000000..714908e0 --- /dev/null +++ b/zzz.cidr.go @@ -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) +} diff --git a/zzz.circle.go b/zzz.circle.go new file mode 100644 index 00000000..b111c06d --- /dev/null +++ b/zzz.circle.go @@ -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) +} diff --git a/zzz.date.go b/zzz.date.go new file mode 100644 index 00000000..66132082 --- /dev/null +++ b/zzz.date.go @@ -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) +} diff --git a/zzz.float4.go b/zzz.float4.go new file mode 100644 index 00000000..b600805e --- /dev/null +++ b/zzz.float4.go @@ -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) +} diff --git a/zzz.float8.go b/zzz.float8.go new file mode 100644 index 00000000..dd3ba0fa --- /dev/null +++ b/zzz.float8.go @@ -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) +} diff --git a/zzz.generic_binary.go b/zzz.generic_binary.go new file mode 100644 index 00000000..b50f1f45 --- /dev/null +++ b/zzz.generic_binary.go @@ -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) +} diff --git a/zzz.generic_text.go b/zzz.generic_text.go new file mode 100644 index 00000000..5ab771cf --- /dev/null +++ b/zzz.generic_text.go @@ -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) +} diff --git a/zzz.hstore.go b/zzz.hstore.go new file mode 100644 index 00000000..ebd7bdee --- /dev/null +++ b/zzz.hstore.go @@ -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) +} diff --git a/zzz.inet.go b/zzz.inet.go new file mode 100644 index 00000000..51daeee6 --- /dev/null +++ b/zzz.inet.go @@ -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) +} diff --git a/zzz.int2.go b/zzz.int2.go new file mode 100644 index 00000000..f2d959f9 --- /dev/null +++ b/zzz.int2.go @@ -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) +} diff --git a/zzz.int4.go b/zzz.int4.go new file mode 100644 index 00000000..bd7f9bda --- /dev/null +++ b/zzz.int4.go @@ -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) +} diff --git a/zzz.int8.go b/zzz.int8.go new file mode 100644 index 00000000..d6e98262 --- /dev/null +++ b/zzz.int8.go @@ -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) +} diff --git a/zzz.interval.go b/zzz.interval.go new file mode 100644 index 00000000..a34f2d59 --- /dev/null +++ b/zzz.interval.go @@ -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) +} diff --git a/zzz.json.go b/zzz.json.go new file mode 100644 index 00000000..40a736c9 --- /dev/null +++ b/zzz.json.go @@ -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) +} diff --git a/zzz.jsonb.go b/zzz.jsonb.go new file mode 100644 index 00000000..a07934b7 --- /dev/null +++ b/zzz.jsonb.go @@ -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) +} diff --git a/zzz.line.go b/zzz.line.go new file mode 100644 index 00000000..7365744b --- /dev/null +++ b/zzz.line.go @@ -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) +} diff --git a/zzz.lseg.go b/zzz.lseg.go new file mode 100644 index 00000000..1a95af09 --- /dev/null +++ b/zzz.lseg.go @@ -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) +} diff --git a/zzz.macadder.go b/zzz.macadder.go new file mode 100644 index 00000000..5758d68f --- /dev/null +++ b/zzz.macadder.go @@ -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) +} diff --git a/zzz.name.go b/zzz.name.go new file mode 100644 index 00000000..6949c337 --- /dev/null +++ b/zzz.name.go @@ -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) +} diff --git a/zzz.numeric.go b/zzz.numeric.go new file mode 100644 index 00000000..838bed40 --- /dev/null +++ b/zzz.numeric.go @@ -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) +} diff --git a/zzz.oid.go b/zzz.oid.go new file mode 100644 index 00000000..bc3ba7d2 --- /dev/null +++ b/zzz.oid.go @@ -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) +} diff --git a/zzz.oid_value.go b/zzz.oid_value.go new file mode 100644 index 00000000..6fba9e44 --- /dev/null +++ b/zzz.oid_value.go @@ -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) +} diff --git a/zzz.path.go b/zzz.path.go new file mode 100644 index 00000000..d761ac40 --- /dev/null +++ b/zzz.path.go @@ -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) +} diff --git a/zzz.pguint32.go b/zzz.pguint32.go new file mode 100644 index 00000000..c869da8f --- /dev/null +++ b/zzz.pguint32.go @@ -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) +} diff --git a/zzz.point.go b/zzz.point.go new file mode 100644 index 00000000..083ded95 --- /dev/null +++ b/zzz.point.go @@ -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) +} diff --git a/zzz.polygon.go b/zzz.polygon.go new file mode 100644 index 00000000..2bfdbbd4 --- /dev/null +++ b/zzz.polygon.go @@ -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) +} diff --git a/zzz.qchar.go b/zzz.qchar.go new file mode 100644 index 00000000..adc0f462 --- /dev/null +++ b/zzz.qchar.go @@ -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) +} diff --git a/zzz.text.go b/zzz.text.go new file mode 100644 index 00000000..e1a3908f --- /dev/null +++ b/zzz.text.go @@ -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) +} diff --git a/zzz.tid.go b/zzz.tid.go new file mode 100644 index 00000000..1a705277 --- /dev/null +++ b/zzz.tid.go @@ -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) +} diff --git a/zzz.time.go b/zzz.time.go new file mode 100644 index 00000000..be9a96a7 --- /dev/null +++ b/zzz.time.go @@ -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) +} diff --git a/zzz.timestamp.go b/zzz.timestamp.go new file mode 100644 index 00000000..ce6135c7 --- /dev/null +++ b/zzz.timestamp.go @@ -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) +} diff --git a/zzz.timestamptz.go b/zzz.timestamptz.go new file mode 100644 index 00000000..1147b257 --- /dev/null +++ b/zzz.timestamptz.go @@ -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) +} diff --git a/zzz.uuid.go b/zzz.uuid.go new file mode 100644 index 00000000..a0aefaf6 --- /dev/null +++ b/zzz.uuid.go @@ -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) +} diff --git a/zzz.varbit.go b/zzz.varbit.go new file mode 100644 index 00000000..2b090ebf --- /dev/null +++ b/zzz.varbit.go @@ -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) +} diff --git a/zzz.varchar.go b/zzz.varchar.go new file mode 100644 index 00000000..9771d412 --- /dev/null +++ b/zzz.varchar.go @@ -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) +} diff --git a/zzz.xid.go b/zzz.xid.go new file mode 100644 index 00000000..2754d98e --- /dev/null +++ b/zzz.xid.go @@ -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) +}