From be36a7e14b3e4f6938baa727139d6fa95f6ad1fe Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 14 Nov 2019 20:40:41 -0600 Subject: [PATCH] Fix test and avoid change to array signatures typed_array.go.erb was not updated back in a8802b16cc593842f5c69b0f7cfb0de11d5cd3a8 when Value, EncodeBinary, EncodeText, and MarshalJSON were changed to be defined on T instead of *T. This has been corrected. --- aclitem_array.go | 4 ++-- bool_array.go | 6 +++--- bpchar_array.go | 6 +++--- bytea_array.go | 6 +++--- cidr_array.go | 6 +++--- date_array.go | 6 +++--- enum_array.go | 4 ++-- float4_array.go | 6 +++--- float8_array.go | 6 +++--- hstore_array.go | 6 +++--- inet_array.go | 6 +++--- int2_array.go | 6 +++--- int4_array.go | 34 +++++++++++++++++++++++++++++++--- int8_array.go | 6 +++--- macaddr_array.go | 6 +++--- numeric_array.go | 6 +++--- text_array.go | 6 +++--- timestamp_array.go | 6 +++--- timestamptz_array.go | 6 +++--- tstzrange_array.go | 17 +++++------------ typed_array.go.erb | 8 ++++---- typed_array_gen.sh | 4 ++-- uuid_array.go | 6 +++--- varchar_array.go | 6 +++--- 24 files changed, 100 insertions(+), 79 deletions(-) diff --git a/aclitem_array.go b/aclitem_array.go index e41edaea..7b2e4dbc 100644 --- a/aclitem_array.go +++ b/aclitem_array.go @@ -136,7 +136,7 @@ func (dst *ACLItemArray) DecodeText(ci *ConnInfo, src []byte) error { return nil } -func (src *ACLItemArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src ACLItemArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -212,7 +212,7 @@ func (dst *ACLItemArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *ACLItemArray) Value() (driver.Value, error) { +func (src ACLItemArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/bool_array.go b/bool_array.go index 89fac9ec..3dbb4ca0 100644 --- a/bool_array.go +++ b/bool_array.go @@ -180,7 +180,7 @@ func (dst *BoolArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *BoolArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src BoolArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -237,7 +237,7 @@ func (src *BoolArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *BoolArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src BoolArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -300,7 +300,7 @@ func (dst *BoolArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *BoolArray) Value() (driver.Value, error) { +func (src BoolArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/bpchar_array.go b/bpchar_array.go index d974df16..b60ccc91 100644 --- a/bpchar_array.go +++ b/bpchar_array.go @@ -180,7 +180,7 @@ func (dst *BPCharArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *BPCharArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src BPCharArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -237,7 +237,7 @@ func (src *BPCharArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *BPCharArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src BPCharArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -300,7 +300,7 @@ func (dst *BPCharArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *BPCharArray) Value() (driver.Value, error) { +func (src BPCharArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/bytea_array.go b/bytea_array.go index a8a67368..fbebff24 100644 --- a/bytea_array.go +++ b/bytea_array.go @@ -180,7 +180,7 @@ func (dst *ByteaArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *ByteaArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src ByteaArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -237,7 +237,7 @@ func (src *ByteaArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *ByteaArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src ByteaArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -300,7 +300,7 @@ func (dst *ByteaArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *ByteaArray) Value() (driver.Value, error) { +func (src ByteaArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/cidr_array.go b/cidr_array.go index bddf74ec..dbc71bb5 100644 --- a/cidr_array.go +++ b/cidr_array.go @@ -209,7 +209,7 @@ func (dst *CIDRArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *CIDRArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src CIDRArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -266,7 +266,7 @@ func (src *CIDRArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *CIDRArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src CIDRArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -329,7 +329,7 @@ func (dst *CIDRArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *CIDRArray) Value() (driver.Value, error) { +func (src CIDRArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/date_array.go b/date_array.go index 95f52ac0..c97e83ee 100644 --- a/date_array.go +++ b/date_array.go @@ -181,7 +181,7 @@ func (dst *DateArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *DateArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src DateArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -238,7 +238,7 @@ func (src *DateArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *DateArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src DateArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -301,7 +301,7 @@ func (dst *DateArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *DateArray) Value() (driver.Value, error) { +func (src DateArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/enum_array.go b/enum_array.go index f32be61c..3e07eae9 100644 --- a/enum_array.go +++ b/enum_array.go @@ -136,7 +136,7 @@ func (dst *EnumArray) DecodeText(ci *ConnInfo, src []byte) error { return nil } -func (src *EnumArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src EnumArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -212,7 +212,7 @@ func (dst *EnumArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *EnumArray) Value() (driver.Value, error) { +func (src EnumArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/float4_array.go b/float4_array.go index a21e0a1f..07fac71a 100644 --- a/float4_array.go +++ b/float4_array.go @@ -180,7 +180,7 @@ func (dst *Float4Array) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *Float4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Float4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -237,7 +237,7 @@ func (src *Float4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *Float4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Float4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -300,7 +300,7 @@ func (dst *Float4Array) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *Float4Array) Value() (driver.Value, error) { +func (src Float4Array) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/float8_array.go b/float8_array.go index 6a44339a..2f65c736 100644 --- a/float8_array.go +++ b/float8_array.go @@ -180,7 +180,7 @@ func (dst *Float8Array) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *Float8Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Float8Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -237,7 +237,7 @@ func (src *Float8Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *Float8Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Float8Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -300,7 +300,7 @@ func (dst *Float8Array) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *Float8Array) Value() (driver.Value, error) { +func (src Float8Array) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/hstore_array.go b/hstore_array.go index a0a2b3a9..06a11c02 100644 --- a/hstore_array.go +++ b/hstore_array.go @@ -180,7 +180,7 @@ func (dst *HstoreArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *HstoreArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src HstoreArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -237,7 +237,7 @@ func (src *HstoreArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *HstoreArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src HstoreArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -300,7 +300,7 @@ func (dst *HstoreArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *HstoreArray) Value() (driver.Value, error) { +func (src HstoreArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/inet_array.go b/inet_array.go index d754fab3..88181739 100644 --- a/inet_array.go +++ b/inet_array.go @@ -209,7 +209,7 @@ func (dst *InetArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *InetArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src InetArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -266,7 +266,7 @@ func (src *InetArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *InetArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src InetArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -329,7 +329,7 @@ func (dst *InetArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *InetArray) Value() (driver.Value, error) { +func (src InetArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/int2_array.go b/int2_array.go index 59c05de3..27892b15 100644 --- a/int2_array.go +++ b/int2_array.go @@ -208,7 +208,7 @@ func (dst *Int2Array) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *Int2Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Int2Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -265,7 +265,7 @@ func (src *Int2Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *Int2Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Int2Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -328,7 +328,7 @@ func (dst *Int2Array) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *Int2Array) Value() (driver.Value, error) { +func (src Int2Array) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/int4_array.go b/int4_array.go index 08040955..e3819562 100644 --- a/int4_array.go +++ b/int4_array.go @@ -61,6 +61,25 @@ func (dst *Int4Array) Set(src interface{}) error { } } + case []int: + if value == nil { + *dst = Int4Array{Status: Null} + } else if len(value) == 0 { + *dst = Int4Array{Status: Present} + } else { + elements := make([]Int4, len(value)) + for i := range value { + if err := elements[i].Set(value[i]); err != nil { + return err + } + } + *dst = Int4Array{ + Elements: elements, + Dimensions: []ArrayDimension{{Length: int32(len(elements)), LowerBound: 1}}, + Status: Present, + } + } + case []Int4: if value == nil { *dst = Int4Array{Status: Null} @@ -117,6 +136,15 @@ func (src *Int4Array) AssignTo(dst interface{}) error { } return nil + case *[]int: + *v = make([]int, len(src.Elements)) + for i := range src.Elements { + if err := src.Elements[i].AssignTo(&((*v)[i])); err != nil { + return err + } + } + return nil + default: if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) @@ -208,7 +236,7 @@ func (dst *Int4Array) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *Int4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Int4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -265,7 +293,7 @@ func (src *Int4Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *Int4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Int4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -328,7 +356,7 @@ func (dst *Int4Array) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *Int4Array) Value() (driver.Value, error) { +func (src Int4Array) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/int8_array.go b/int8_array.go index 8cb446eb..a31a474a 100644 --- a/int8_array.go +++ b/int8_array.go @@ -208,7 +208,7 @@ func (dst *Int8Array) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *Int8Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Int8Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -265,7 +265,7 @@ func (src *Int8Array) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *Int8Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src Int8Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -328,7 +328,7 @@ func (dst *Int8Array) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *Int8Array) Value() (driver.Value, error) { +func (src Int8Array) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/macaddr_array.go b/macaddr_array.go index 88bc44fd..8382ea45 100644 --- a/macaddr_array.go +++ b/macaddr_array.go @@ -181,7 +181,7 @@ func (dst *MacaddrArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *MacaddrArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src MacaddrArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -238,7 +238,7 @@ func (src *MacaddrArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *MacaddrArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src MacaddrArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -301,7 +301,7 @@ func (dst *MacaddrArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *MacaddrArray) Value() (driver.Value, error) { +func (src MacaddrArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/numeric_array.go b/numeric_array.go index cbd2e93f..432cd96f 100644 --- a/numeric_array.go +++ b/numeric_array.go @@ -264,7 +264,7 @@ func (dst *NumericArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *NumericArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src NumericArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -321,7 +321,7 @@ func (src *NumericArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *NumericArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src NumericArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -384,7 +384,7 @@ func (dst *NumericArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *NumericArray) Value() (driver.Value, error) { +func (src NumericArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/text_array.go b/text_array.go index d6aa3cfb..653e41fc 100644 --- a/text_array.go +++ b/text_array.go @@ -180,7 +180,7 @@ func (dst *TextArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *TextArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src TextArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -237,7 +237,7 @@ func (src *TextArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *TextArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src TextArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -300,7 +300,7 @@ func (dst *TextArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *TextArray) Value() (driver.Value, error) { +func (src TextArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/timestamp_array.go b/timestamp_array.go index 18d54b38..072e01ac 100644 --- a/timestamp_array.go +++ b/timestamp_array.go @@ -181,7 +181,7 @@ func (dst *TimestampArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *TimestampArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src TimestampArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -238,7 +238,7 @@ func (src *TimestampArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) return buf, nil } -func (src *TimestampArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src TimestampArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -301,7 +301,7 @@ func (dst *TimestampArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *TimestampArray) Value() (driver.Value, error) { +func (src TimestampArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/timestamptz_array.go b/timestamptz_array.go index 98593305..9d0677c8 100644 --- a/timestamptz_array.go +++ b/timestamptz_array.go @@ -181,7 +181,7 @@ func (dst *TimestamptzArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *TimestamptzArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src TimestamptzArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -238,7 +238,7 @@ func (src *TimestamptzArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error return buf, nil } -func (src *TimestamptzArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src TimestamptzArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -301,7 +301,7 @@ func (dst *TimestamptzArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *TimestamptzArray) Value() (driver.Value, error) { +func (src TimestamptzArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/tstzrange_array.go b/tstzrange_array.go index 8180e4c2..f7c0121d 100644 --- a/tstzrange_array.go +++ b/tstzrange_array.go @@ -29,19 +29,12 @@ func (dst *TstzrangeArray) Set(src interface{}) error { } else if len(value) == 0 { *dst = TstzrangeArray{Status: Present} } else { - elements := make([]Tstzrange, len(value)) - for i := range value { - if err := elements[i].Set(value[i]); err != nil { - return err - } - } *dst = TstzrangeArray{ - Elements: elements, - Dimensions: []ArrayDimension{{Length: int32(len(elements)), LowerBound: 1}}, + Elements: value, + Dimensions: []ArrayDimension{{Length: int32(len(value)), LowerBound: 1}}, Status: Present, } } - default: if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) @@ -168,7 +161,7 @@ func (dst *TstzrangeArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *TstzrangeArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src TstzrangeArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -225,7 +218,7 @@ func (src *TstzrangeArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) return buf, nil } -func (src *TstzrangeArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src TstzrangeArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -288,7 +281,7 @@ func (dst *TstzrangeArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *TstzrangeArray) Value() (driver.Value, error) { +func (src TstzrangeArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/typed_array.go.erb b/typed_array.go.erb index 2279380b..72c0c381 100644 --- a/typed_array.go.erb +++ b/typed_array.go.erb @@ -23,7 +23,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { switch value := src.(type) { <% go_array_types.split(",").each do |t| %> - <% if t != pgtype_element_type %> + <% if t != "[]#{pgtype_element_type}" %> case <%= t %>: if value == nil { *dst = <%= pgtype_array_type %>{Status: Null} @@ -184,7 +184,7 @@ func (dst *<%= pgtype_array_type %>) DecodeBinary(ci *ConnInfo, src []byte) erro } <% end %> -func (src *<%= pgtype_array_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src <%= pgtype_array_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -242,7 +242,7 @@ func (src *<%= pgtype_array_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byt } <% if binary_format == "true" %> - func (src *<%= pgtype_array_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { + func (src <%= pgtype_array_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -306,7 +306,7 @@ func (dst *<%= pgtype_array_type %>) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *<%= pgtype_array_type %>) Value() (driver.Value, error) { +func (src <%= pgtype_array_type %>) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/typed_array_gen.sh b/typed_array_gen.sh index 76c174ef..6eca219d 100644 --- a/typed_array_gen.sh +++ b/typed_array_gen.sh @@ -1,10 +1,10 @@ erb pgtype_array_type=Int2Array pgtype_element_type=Int2 go_array_types=[]int16,[]uint16 element_type_name=int2 text_null=NULL binary_format=true typed_array.go.erb > int2_array.go -erb pgtype_array_type=Int4Array pgtype_element_type=Int4 go_array_types=[]int32,[]uint32 element_type_name=int4 text_null=NULL binary_format=true typed_array.go.erb > int4_array.go +erb pgtype_array_type=Int4Array pgtype_element_type=Int4 go_array_types=[]int32,[]uint32,[]int element_type_name=int4 text_null=NULL binary_format=true typed_array.go.erb > int4_array.go erb pgtype_array_type=Int8Array pgtype_element_type=Int8 go_array_types=[]int64,[]uint64 element_type_name=int8 text_null=NULL binary_format=true typed_array.go.erb > int8_array.go erb pgtype_array_type=BoolArray pgtype_element_type=Bool go_array_types=[]bool element_type_name=bool text_null=NULL binary_format=true typed_array.go.erb > bool_array.go erb pgtype_array_type=DateArray pgtype_element_type=Date go_array_types=[]time.Time element_type_name=date text_null=NULL binary_format=true typed_array.go.erb > date_array.go erb pgtype_array_type=TimestamptzArray pgtype_element_type=Timestamptz go_array_types=[]time.Time element_type_name=timestamptz text_null=NULL binary_format=true typed_array.go.erb > timestamptz_array.go -erb pgtype_array_type=TstzrangeArray pgtype_element_type=Tstzrange go_array_types=[]Tstzrange element_type_name=tstzrange text_null=NULL binary_format=true typed_array.go.erb > tstz_range_array.go +erb pgtype_array_type=TstzrangeArray pgtype_element_type=Tstzrange go_array_types=[]Tstzrange element_type_name=tstzrange text_null=NULL binary_format=true typed_array.go.erb > tstzrange_array.go erb pgtype_array_type=TimestampArray pgtype_element_type=Timestamp go_array_types=[]time.Time element_type_name=timestamp text_null=NULL binary_format=true typed_array.go.erb > timestamp_array.go erb pgtype_array_type=Float4Array pgtype_element_type=Float4 go_array_types=[]float32 element_type_name=float4 text_null=NULL binary_format=true typed_array.go.erb > float4_array.go erb pgtype_array_type=Float8Array pgtype_element_type=Float8 go_array_types=[]float64 element_type_name=float8 text_null=NULL binary_format=true typed_array.go.erb > float8_array.go diff --git a/uuid_array.go b/uuid_array.go index 25bf21a8..7c324e53 100644 --- a/uuid_array.go +++ b/uuid_array.go @@ -236,7 +236,7 @@ func (dst *UUIDArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *UUIDArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src UUIDArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -293,7 +293,7 @@ func (src *UUIDArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *UUIDArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src UUIDArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -356,7 +356,7 @@ func (dst *UUIDArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *UUIDArray) Value() (driver.Value, error) { +func (src UUIDArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err diff --git a/varchar_array.go b/varchar_array.go index aa505404..ac9af519 100644 --- a/varchar_array.go +++ b/varchar_array.go @@ -180,7 +180,7 @@ func (dst *VarcharArray) DecodeBinary(ci *ConnInfo, src []byte) error { return nil } -func (src *VarcharArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src VarcharArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -237,7 +237,7 @@ func (src *VarcharArray) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return buf, nil } -func (src *VarcharArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { +func (src VarcharArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil @@ -300,7 +300,7 @@ func (dst *VarcharArray) Scan(src interface{}) error { } // Value implements the database/sql/driver Valuer interface. -func (src *VarcharArray) Value() (driver.Value, error) { +func (src VarcharArray) Value() (driver.Value, error) { buf, err := src.EncodeText(nil, nil) if err != nil { return nil, err