sql: Support nil values
diff --git a/sql.go b/sql.go
index 790080c..f326b54 100644
--- a/sql.go
+++ b/sql.go
@@ -14,6 +14,9 @@
// consult database-specific driver documentation for matching types.
func (uuid *UUID) Scan(src interface{}) error {
switch src := src.(type) {
+ case nil:
+ return nil
+
case string:
// if an empty UUID comes from a table, we return a null UUID
if src == "" {
diff --git a/sql_test.go b/sql_test.go
index c193196..4fbd01b 100644
--- a/sql_test.go
+++ b/sql_test.go
@@ -90,6 +90,17 @@
t.Error("UUID was not nil after scanning empty byte slice")
}
}
+
+ uuid = UUID{}
+ err = (&uuid).Scan(nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, v := range uuid {
+ if v != 0 {
+ t.Error("UUID was not nil after scanning nil")
+ }
+ }
}
func TestValue(t *testing.T) {