2
0

Set will call Get on src if possible

This commit is contained in:
Jack Christensen
2020-02-19 11:58:49 -06:00
parent 666bd514e2
commit 55a56add23
50 changed files with 341 additions and 0 deletions
+7
View File
@@ -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}
+4
View File
@@ -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},
+7
View File
@@ -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}