Skip to content

Commit

Permalink
Set will call Get on src if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jackc committed Feb 19, 2020
1 parent 666bd51 commit 55a56ad
Show file tree
Hide file tree
Showing 50 changed files with 341 additions and 0 deletions.
12 changes: 12 additions & 0 deletions aclitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ type ACLItem struct {
}

func (dst *ACLItem) Set(src interface{}) error {
if src == nil {
*dst = ACLItem{Status: Null}
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case string:
*dst = ACLItem{String: value, Status: Present}
Expand Down
7 changes: 7 additions & 0 deletions aclitem_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func (dst *ACLItemArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []string:
Expand Down
7 changes: 7 additions & 0 deletions bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func (dst *Bool) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case bool:
*dst = Bool{Bool: value, Status: Present}
Expand Down
7 changes: 7 additions & 0 deletions bool_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *BoolArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []bool:
Expand Down
7 changes: 7 additions & 0 deletions bpchar_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *BPCharArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []string:
Expand Down
7 changes: 7 additions & 0 deletions bytea.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ func (dst *Bytea) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case []byte:
if value != nil {
Expand Down
7 changes: 7 additions & 0 deletions bytea_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *ByteaArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case [][]byte:
Expand Down
7 changes: 7 additions & 0 deletions cidr_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func (dst *CIDRArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []*net.IPNet:
Expand Down
7 changes: 7 additions & 0 deletions date.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func (dst *Date) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case time.Time:
*dst = Date{Time: value, Status: Present}
Expand Down
7 changes: 7 additions & 0 deletions date_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func (dst *DateArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []time.Time:
Expand Down
7 changes: 7 additions & 0 deletions enum_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func (dst *EnumArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []string:
Expand Down
7 changes: 7 additions & 0 deletions ext/gofrs-uuid/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func (dst *UUID) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case uuid.UUID:
*dst = UUID{UUID: value, Status: pgtype.Present}
Expand Down
4 changes: 4 additions & 0 deletions ext/gofrs-uuid/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func TestUUIDSet(t *testing.T) {
source interface{}
result gofrs.UUID
}{
{
source: &gofrs.UUID{UUID: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Status: pgtype.Present},
result: gofrs.UUID{UUID: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Status: pgtype.Present},
},
{
source: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
result: gofrs.UUID{UUID: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, Status: pgtype.Present},
Expand Down
7 changes: 7 additions & 0 deletions ext/shopspring-numeric/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func (dst *Numeric) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case decimal.Decimal:
*dst = Numeric{Decimal: value, Status: pgtype.Present}
Expand Down
7 changes: 7 additions & 0 deletions float4.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *Float4) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case float32:
*dst = Float4{Float: value, Status: Present}
Expand Down
7 changes: 7 additions & 0 deletions float4_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *Float4Array) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []float32:
Expand Down
7 changes: 7 additions & 0 deletions float8.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *Float8) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case float32:
*dst = Float8{Float: float64(value), Status: Present}
Expand Down
7 changes: 7 additions & 0 deletions float8_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *Float8Array) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []float64:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.12
require (
github.com/gofrs/uuid v3.2.0+incompatible
github.com/jackc/pgio v1.0.0
github.com/jackc/pgx v3.6.2+incompatible
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186
github.com/lib/pq v1.2.0
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711 h1:vZp4
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
github.com/jackc/pgx v3.6.2+incompatible h1:2zP5OD7kiyR3xzRYMhOcXVvkDZsImVXfj+yIyTQf3/o=
github.com/jackc/pgx v3.6.2+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96 h1:ylEAOd688Duev/fxTmGdupsbyZfxNMdngIG14DoBKTM=
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912 h1:YuOWGsSK5L4Fz81Olx5TNlZftmDuNrfv4ip0Yos77Tw=
Expand Down
7 changes: 7 additions & 0 deletions hstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func (dst *Hstore) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case map[string]string:
m := make(map[string]Text, len(value))
Expand Down
7 changes: 7 additions & 0 deletions hstore_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *HstoreArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []map[string]string:
Expand Down
7 changes: 7 additions & 0 deletions inet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func (dst *Inet) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case net.IPNet:
*dst = Inet{IPNet: &value, Status: Present}
Expand Down
7 changes: 7 additions & 0 deletions inet_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func (dst *InetArray) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []*net.IPNet:
Expand Down
7 changes: 7 additions & 0 deletions int2.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *Int2) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case int8:
*dst = Int2{Int: int16(value), Status: Present}
Expand Down
7 changes: 7 additions & 0 deletions int2_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *Int2Array) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []int16:
Expand Down
7 changes: 7 additions & 0 deletions int4.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func (dst *Int4) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case int8:
*dst = Int4{Int: int32(value), Status: Present}
Expand Down
7 changes: 7 additions & 0 deletions int4_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (dst *Int4Array) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {

case []int16:
Expand Down
7 changes: 7 additions & 0 deletions int8.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func (dst *Int8) Set(src interface{}) error {
return nil
}

if value, ok := src.(interface{ Get() interface{} }); ok {
value2 := value.Get()
if value2 != value {
return dst.Set(value2)
}
}

switch value := src.(type) {
case int8:
*dst = Int8{Int: int64(value), Status: Present}
Expand Down
Loading

0 comments on commit 55a56ad

Please sign in to comment.