@@ -19,7 +19,7 @@ type NullBool struct {
19
19
}
20
20
21
21
// MarshalJSON implements the json.Marshaler interface for a NullBool.
22
- func (r NullBool ) MarshalJSON () ([]byte , error ) {
22
+ func (r * NullBool ) MarshalJSON () ([]byte , error ) {
23
23
if r .Valid {
24
24
return json .Marshal (r .Bool )
25
25
}
@@ -44,6 +44,10 @@ func (r *NullBool) UnmarshalJSON(data []byte) error {
44
44
return nil
45
45
}
46
46
47
+ func (r NullBool ) Val () bool {
48
+ return r .Bool
49
+ }
50
+
47
51
// NewNullBool returns a valid new NullBool for a given boolean value.
48
52
func NewNullBool (b bool ) * NullBool {
49
53
return & NullBool {NullBool : sql.NullBool {Bool : b , Valid : true }}
@@ -80,6 +84,10 @@ func (r *NullFloat64) UnmarshalJSON(data []byte) error {
80
84
return nil
81
85
}
82
86
87
+ func (r * NullFloat64 ) Val () float64 {
88
+ return r .Float64
89
+ }
90
+
83
91
// NewNullFloat64 returns a valid new NullFloat64 for a given float64 value.
84
92
func NewNullFloat64 (f float64 ) * NullFloat64 {
85
93
return & NullFloat64 {NullFloat64 : sql.NullFloat64 {Float64 : f , Valid : true }}
@@ -116,6 +124,10 @@ func (r *NullInt64) UnmarshalJSON(data []byte) error {
116
124
return nil
117
125
}
118
126
127
+ func (r NullInt64 ) Val () int64 {
128
+ return r .Int64
129
+ }
130
+
119
131
// RedisArg implements redis.Argument.
120
132
//
121
133
// The caller should explicitly check the Valid field when putting NullString
@@ -185,6 +197,10 @@ func (r *NullString) UnmarshalJSON(data []byte) error {
185
197
return nil
186
198
}
187
199
200
+ func (r NullString ) Val () string {
201
+ return r .String
202
+ }
203
+
188
204
// RedisArg implements redis.Argument.
189
205
//
190
206
// The caller should explicitly check the Valid field when putting NullString
@@ -305,6 +321,10 @@ type NullDuration struct {
305
321
Valid bool
306
322
}
307
323
324
+ func (r NullDuration ) Val () time.Duration {
325
+ return time .Duration (r .Duration )
326
+ }
327
+
308
328
// MarshalJSON implements the json.Marshaler interface for a NullDuration.
309
329
func (r NullDuration ) MarshalJSON () ([]byte , error ) {
310
330
if r .Valid {
@@ -341,6 +361,11 @@ type NullTime struct {
341
361
sql.NullTime
342
362
}
343
363
364
+ // Val returns the time.Time value of the NullTime.
365
+ func (r NullTime ) Val () time.Time {
366
+ return r .Time
367
+ }
368
+
344
369
// MarshalJSON implements json.Marshaller.
345
370
func (r NullTime ) MarshalJSON () ([]byte , error ) {
346
371
if r .Valid && ! r .Time .IsZero () {
0 commit comments