Remove proposed v5 type system before Codec
This commit is contained in:
+11
-47
@@ -148,27 +148,6 @@ type TypeValue interface {
|
||||
TypeName() string
|
||||
}
|
||||
|
||||
type FormatSupport interface {
|
||||
BinaryFormatSupported() bool
|
||||
TextFormatSupported() bool
|
||||
PreferredFormat() int16
|
||||
}
|
||||
|
||||
type ParamEncoder interface {
|
||||
// EncodeParam should append the encoded value of self to buf. If self is the
|
||||
// SQL value NULL then append nothing and return (nil, nil). The caller of
|
||||
// EncodeText is responsible for writing the correct NULL value or the
|
||||
// length of the data written.
|
||||
EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error)
|
||||
}
|
||||
|
||||
type ResultDecoder interface {
|
||||
// DecodeResult decodes src into ResultDecoder. If src is nil then the
|
||||
// original SQL value is NULL. ResultDecoder takes ownership of src. The
|
||||
// caller MUST not use it again.
|
||||
DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error
|
||||
}
|
||||
|
||||
type Codec interface {
|
||||
// FormatSupported returns true if the format is supported.
|
||||
FormatSupported(int16) bool
|
||||
@@ -244,8 +223,6 @@ func (e *nullAssignmentError) Error() string {
|
||||
type DataType struct {
|
||||
Value Value
|
||||
|
||||
resultDecoder ResultDecoder
|
||||
|
||||
textDecoder TextDecoder
|
||||
binaryDecoder BinaryDecoder
|
||||
|
||||
@@ -402,18 +379,12 @@ func (ci *ConnInfo) RegisterDataType(t DataType) {
|
||||
var formatCode int16
|
||||
if t.Codec != nil {
|
||||
formatCode = t.Codec.PreferredFormat()
|
||||
} else if pfp, ok := t.Value.(FormatSupport); ok {
|
||||
formatCode = pfp.PreferredFormat()
|
||||
} else if _, ok := t.Value.(BinaryEncoder); ok {
|
||||
formatCode = BinaryFormatCode
|
||||
}
|
||||
ci.oidToFormatCode[t.OID] = formatCode
|
||||
}
|
||||
|
||||
if d, ok := t.Value.(ResultDecoder); ok {
|
||||
t.resultDecoder = d
|
||||
}
|
||||
|
||||
if d, ok := t.Value.(TextDecoder); ok {
|
||||
t.textDecoder = d
|
||||
}
|
||||
@@ -501,10 +472,6 @@ type ScanPlan interface {
|
||||
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)
|
||||
}
|
||||
@@ -571,21 +538,18 @@ type scanPlanDataTypeAssignTo DataType
|
||||
func (plan *scanPlanDataTypeAssignTo) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
dt := (*DataType)(plan)
|
||||
var err error
|
||||
if dt.resultDecoder != nil {
|
||||
err = dt.resultDecoder.DecodeResult(ci, oid, formatCode, src)
|
||||
} else {
|
||||
switch formatCode {
|
||||
case BinaryFormatCode:
|
||||
if dt.binaryDecoder == nil {
|
||||
return fmt.Errorf("dt.binaryDecoder is nil")
|
||||
}
|
||||
err = dt.binaryDecoder.DecodeBinary(ci, src)
|
||||
case TextFormatCode:
|
||||
if dt.textDecoder == nil {
|
||||
return fmt.Errorf("dt.textDecoder is nil")
|
||||
}
|
||||
err = dt.textDecoder.DecodeText(ci, src)
|
||||
|
||||
switch formatCode {
|
||||
case BinaryFormatCode:
|
||||
if dt.binaryDecoder == nil {
|
||||
return fmt.Errorf("dt.binaryDecoder is nil")
|
||||
}
|
||||
err = dt.binaryDecoder.DecodeBinary(ci, src)
|
||||
case TextFormatCode:
|
||||
if dt.textDecoder == nil {
|
||||
return fmt.Errorf("dt.textDecoder is nil")
|
||||
}
|
||||
err = dt.textDecoder.DecodeText(ci, src)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -71,16 +71,6 @@ func mustParseMacaddr(t testing.TB, s string) net.HardwareAddr {
|
||||
return addr
|
||||
}
|
||||
|
||||
func TestConnInfoFormatCodeForOID(t *testing.T) {
|
||||
ci := pgtype.NewConnInfo()
|
||||
|
||||
// pgtype.JSONB implements BinaryEncoder but also implements ParamFormatPreferrer to override it to text.
|
||||
assert.Equal(t, int16(pgtype.TextFormatCode), ci.FormatCodeForOID(pgtype.JSONBOID))
|
||||
|
||||
// pgtype.Int4 implements BinaryEncoder but does not implement ParamFormatPreferrer so it should be binary.
|
||||
assert.Equal(t, int16(pgtype.BinaryFormatCode), ci.FormatCodeForOID(pgtype.Int4OID))
|
||||
}
|
||||
|
||||
func TestConnInfoScanNilIsNoOp(t *testing.T) {
|
||||
ci := pgtype.NewConnInfo()
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
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)
|
||||
}
|
||||
@@ -252,9 +252,7 @@ func encodePreparedStatementArgument(ci *pgtype.ConnInfo, buf []byte, oid uint32
|
||||
// argument to a prepared statement. It defaults to TextFormatCode if no
|
||||
// determination can be made.
|
||||
func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid uint32, arg interface{}) int16 {
|
||||
switch arg := arg.(type) {
|
||||
case pgtype.FormatSupport:
|
||||
return arg.PreferredFormat()
|
||||
switch arg.(type) {
|
||||
case pgtype.BinaryEncoder:
|
||||
return BinaryFormatCode
|
||||
case string, *string, pgtype.TextEncoder:
|
||||
|
||||
Reference in New Issue
Block a user