-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrappers.go
86 lines (73 loc) · 1.21 KB
/
wrappers.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package datamapper
import (
"database/sql/driver"
"time"
)
type NullTime struct {
V *time.Time
}
func (t *NullTime) Scan(value interface{}) error {
if value == nil {
*t.V = time.Time{}
return nil
}
return convertAssign(t.V, value)
}
func (t *NullTime) Value() (driver.Value, error) {
if t.V.IsZero() {
return nil, nil
}
return *t.V, nil
}
type NullInt struct {
V *int
}
func (s *NullInt) Scan(value interface{}) error {
if value == nil {
*s.V = 0
return nil
}
return convertAssign(s.V, value)
}
func (s *NullInt) Value() (driver.Value, error) {
if *s.V == 0 {
return nil, nil
}
return *s.V, nil
}
type NullString struct {
V *string
}
func (s *NullString) Scan(value interface{}) error {
if value == nil {
*s.V = ""
return nil
}
return convertAssign(s.V, value)
}
func (s *NullString) Value() (driver.Value, error) {
if *s.V == "" {
return nil, nil
}
return *s.V, nil
}
type IntBool struct {
V *bool
}
func (b *IntBool) Scan(value interface{}) error {
if value == nil {
return nil
}
var i int
if err := convertAssign(&i, value); err != nil {
return err
}
*b.V = i != 0
return nil
}
func (b *IntBool) Value() (driver.Value, error) {
if *b.V {
return 1, nil
}
return 0, nil
}