-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.go
More file actions
38 lines (32 loc) · 869 Bytes
/
sql.go
File metadata and controls
38 lines (32 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package arn
import (
"database/sql/driver"
"fmt"
)
// Value converts the ResourceName into a SQL driver value which can be used to
// directly use the ResourceName as parameter to a SQL query.
func (n *ResourceName) Value() (driver.Value, error) {
if n == nil {
return nil, nil
}
return n.String(), nil
}
// Scan implements the sql.Scanner interface. It supports converting from
// string, []byte, or nil into a ResourceName value. Attempting to convert from
// another type will return an error.
func (n *ResourceName) Scan(src interface{}) error {
switch v := src.(type) {
case nil:
return nil
case []byte:
resourceName, err := Parse(string(v))
*n = *resourceName
return err
case string:
resourceName, err := Parse(v)
*n = *resourceName
return err
default:
return fmt.Errorf("scan: unable to scan type %T into ResourceName", v)
}
}