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:
commit
c3079288a2
8
sql.go
8
sql.go
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user