1
0
mirror of https://github.com/google/uuid.git synced 2025-02-16 12:23:51 +02:00

Merge pull request #16 from theory/driver.Valuer

Add support for driver.Valuer.
This commit is contained in:
pborman 2016-02-09 11:06:20 -08:00
commit c3079288a2
2 changed files with 17 additions and 0 deletions

8
sql.go
View File

@ -5,6 +5,7 @@
package uuid
import (
"database/sql/driver"
"errors"
"fmt"
)
@ -56,3 +57,10 @@ func (uuid *UUID) Scan(src interface{}) error {
return nil
}
// Value implements sql.Valuer so that UUIDs can be written to databases
// transparently. Currently, UUIDs map to strings. Please consult
// database-specific driver documentation for matching types.
func (uuid UUID) Value() (driver.Value, error) {
return uuid.String(), nil
}

View File

@ -85,3 +85,12 @@ func TestScan(t *testing.T) {
t.Error("UUID was not nil after scanning empty string")
}
}
func TestValue(t *testing.T) {
stringTest := "f47ac10b-58cc-0372-8567-0e02b2c3d479"
uuid := Parse(stringTest)
val, _ := uuid.Value()
if val != stringTest {
t.Error("Value() did not return expected string")
}
}