MCPcopy
hub / github.com/google/uuid / Scan

Method Scan

sql.go:15–52  ·  sql.go::UUID.Scan

Scan implements sql.Scanner so UUIDs can be read from databases transparently. Currently, database types that map to string and []byte are supported. Please consult database-specific driver documentation for matching types.

(src interface{})

Source from the content-addressed store, hash-verified

13// Currently, database types that map to string and []byte are supported. Please
14// consult database-specific driver documentation for matching types.
15func (uuid *UUID) Scan(src interface{}) error {
16 switch src := src.(type) {
17 case nil:
18 return nil
19
20 case string:
21 // if an empty UUID comes from a table, we return a null UUID
22 if src == "" {
23 return nil
24 }
25
26 // see Parse for required string format
27 u, err := Parse(src)
28 if err != nil {
29 return fmt.Errorf("Scan: %v", err)
30 }
31
32 *uuid = u
33
34 case []byte:
35 // if an empty UUID comes from a table, we return a null UUID
36 if len(src) == 0 {
37 return nil
38 }
39
40 // assumes a simple slice of bytes if 16 bytes
41 // otherwise attempts to parse
42 if len(src) != 16 {
43 return uuid.Scan(string(src))
44 }
45 copy((*uuid)[:], src)
46
47 default:
48 return fmt.Errorf("Scan: unable to scan type %T into UUID", src)
49 }
50
51 return nil
52}
53
54// Value implements sql.Valuer so that UUIDs can be written to databases
55// transparently. Currently, UUIDs map to strings. Please consult

Callers 2

TestNullUUIDScanFunction · 0.95
TestScanFunction · 0.45

Calls 1

ParseFunction · 0.85

Tested by 2

TestNullUUIDScanFunction · 0.76
TestScanFunction · 0.36