@@ -19,18 +19,22 @@ type CustomID null.Int
19
19
20
20
const NullCustomID = CustomID (0 )
21
21
22
+ // MarshalJSON marshals into JSON. 0 values will become null
22
23
func (i CustomID ) MarshalJSON () ([]byte , error ) {
23
24
return null.Int (i).MarshalJSON ()
24
25
}
25
26
27
+ // UnmarshalJSON unmarshals from JSON. null values become 0
26
28
func (i *CustomID ) UnmarshalJSON (b []byte ) error {
27
29
return null.UnmarshalInt (b, (*null.Int )(i))
28
30
}
29
31
32
+ // Value returns the db value, null is returned for 0
30
33
func (i CustomID ) Value () (driver .Value , error ) {
31
34
return null.Int (i).Value ()
32
35
}
33
36
37
+ // Scan scans from the db value. null values become 0
34
38
func (i *CustomID ) Scan (value interface {}) error {
35
39
return null.ScanInt (value, (*null.Int )(i))
36
40
}
@@ -45,18 +49,22 @@ type CustomString null.String
45
49
46
50
type NullCustomString = CustomString (" " )
47
51
52
+ // MarshalJSON marshals into JSON. "" values will become null
48
53
func (s CustomString ) MarshalJSON () ([]byte , error ) {
49
54
return null.String (s).MarshalJSON ()
50
55
}
51
56
57
+ // UnmarshalJSON unmarshals from JSON. null values become ""
52
58
func (s *CustomString ) UnmarshalJSON (b []byte ) error {
53
59
return null.UnmarshalString (b, (*null.String )(s))
54
60
}
55
61
62
+ // Value returns the db value, null is returned for ""
56
63
func (s CustomString ) Value () (driver .Value , error ) {
57
64
return null.String (s).Value ()
58
65
}
59
66
67
+ // Scan scans from the db value. null values become ""
60
68
func (s *CustomString ) Scan (value interface {}) error {
61
69
return null.ScanString (value, (*null.String )(s))
62
70
}
0 commit comments