1 // Copyright 2016 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 // Scan implements sql.Scanner so UUIDs can be read from databases transparently
13 // Currently, database types that map to string and []byte are supported. Please
14 // consult database-specific driver documentation for matching types.
15 func (uuid *UUID) Scan(src interface{}) error {
16 switch src := src.(type) {
21 // if an empty UUID comes from a table, we return a null UUID
26 // see Parse for required string format
29 return fmt.Errorf("Scan: %v", err)
35 // if an empty UUID comes from a table, we return a null UUID
40 // assumes a simple slice of bytes if 16 bytes
41 // otherwise attempts to parse
43 return uuid.Scan(string(src))
48 return fmt.Errorf("Scan: unable to scan type %T into UUID", src)
54 // Value implements sql.Valuer so that UUIDs can be written to databases
55 // transparently. Currently, UUIDs map to strings. Please consult
56 // database-specific driver documentation for matching types.
57 func (uuid UUID) Value() (driver.Value, error) {
58 return uuid.String(), nil