mirror of
https://github.com/google/uuid.git
synced 2024-11-24 08:32:23 +02:00
sql: Support nil values
This commit is contained in:
parent
c96242ef50
commit
3694829644
3
sql.go
3
sql.go
@ -14,6 +14,9 @@ import (
|
||||
// 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 == "" {
|
||||
|
11
sql_test.go
11
sql_test.go
@ -90,6 +90,17 @@ func TestScan(t *testing.T) {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user