/
dirty.go
143 lines (116 loc) · 2.37 KB
/
dirty.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Package dirty tracks when values have been unmarshalled in order to differentiate between values that are absent and values that are null.
package dirty
import (
"time"
"gopkg.in/guregu/null.v3"
)
type Bool struct {
null.Bool
Dirty bool
}
func BoolFrom(b bool) Bool {
return Bool{
Bool: null.BoolFrom(b),
Dirty: true,
}
}
func (b *Bool) Scan(value interface{}) error {
b.Dirty = true
return b.Bool.Scan(value)
}
func (b *Bool) UnmarshalJSON(data []byte) error {
b.Dirty = true
return b.Bool.UnmarshalJSON(data)
}
func (b *Bool) UnmarshalText(text []byte) error {
b.Dirty = true
return b.Bool.UnmarshalText(text)
}
type Float struct {
null.Float
Dirty bool
}
func FloatFrom(f float64) Float {
return Float{
Float: null.FloatFrom(f),
Dirty: true,
}
}
func (f *Float) Scan(value interface{}) error {
f.Dirty = true
return f.Float.Scan(value)
}
func (f *Float) UnmarshalJSON(data []byte) error {
f.Dirty = true
return f.Float.UnmarshalJSON(data)
}
func (f *Float) UnmarshalText(text []byte) error {
f.Dirty = true
return f.Float.UnmarshalText(text)
}
type Int struct {
null.Int
Dirty bool
}
func IntFrom(i int64) Int {
return Int{
Int: null.IntFrom(i),
Dirty: true,
}
}
func (i *Int) Scan(value interface{}) error {
i.Dirty = true
return i.Int.Scan(value)
}
func (i *Int) UnmarshalJSON(data []byte) error {
i.Dirty = true
return i.Int.UnmarshalJSON(data)
}
func (i *Int) UnmarshalText(text []byte) error {
i.Dirty = true
return i.Int.UnmarshalText(text)
}
type String struct {
null.String
Dirty bool
}
func StringFrom(s string) String {
return String{
String: null.StringFrom(s),
Dirty: true,
}
}
func (s *String) Scan(value interface{}) error {
s.Dirty = true
return s.String.Scan(value)
}
func (s *String) UnmarshalJSON(data []byte) error {
s.Dirty = true
return s.String.UnmarshalJSON(data)
}
func (s *String) UnmarshalText(text []byte) error {
s.Dirty = true
return s.String.UnmarshalText(text)
}
type Time struct {
null.Time
Dirty bool
}
func TimeFrom(t time.Time) Time {
return Time{
Time: null.TimeFrom(t),
Dirty: true,
}
}
func (t *Time) Scan(value interface{}) error {
t.Dirty = true
return t.Time.Scan(value)
}
func (t *Time) UnmarshalJSON(data []byte) error {
t.Dirty = true
return t.Time.UnmarshalJSON(data)
}
func (t *Time) UnmarshalText(text []byte) error {
t.Dirty = true
return t.Time.UnmarshalText(text)
}