Uh oh!
There was an error while loading. Please reload this page.
forked from jetify-com/typeid-go
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.go
More file actions
Latest commit
37 lines (33 loc) · 921 Bytes
/
Copy pathsql.go
File metadata and controls
37 lines (33 loc) · 921 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
package typeid
import (
"database/sql/driver"
"fmt"
)
// For nullable TypeID columns, use sql.Null[TypeID].
// Scan implements the sql.Scanner interface so the TypeIDs can be read from
// databases transparently. Currently database types that map to string are
// supported.
func (tid*TypeID) Scan(srcany) error {
switchobj:=src.(type) {
casenil:
return&validationError{
Message: "cannot scan NULL into TypeID",
}
casestring:
ifobj=="" {
return&validationError{
Message: "cannot scan empty string into TypeID",
}
}
returntid.UnmarshalText([]byte(obj))
default:
return&validationError{
Message: fmt.Sprintf("unsupported scan type %T", obj),
}
}
}
// Value implements the sql.Valuer interface so that TypeIDs can be written
// to databases transparently. Currently, TypeIDs map to strings.
func (tidTypeID) Value() (driver.Value, error) {
returntid.String(), nil
}