Skip to content

Commit c108471

Browse files
committed
Merge branch 'master' of github.com:nyaruka/null
2 parents 05165d3 + 5aff1dc commit c108471

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ type CustomID null.Int
1919

2020
const NullCustomID = CustomID(0)
2121

22+
// MarshalJSON marshals into JSON. 0 values will become null
2223
func (i CustomID) MarshalJSON() ([]byte, error) {
2324
return null.Int(i).MarshalJSON()
2425
}
2526

27+
// UnmarshalJSON unmarshals from JSON. null values become 0
2628
func (i *CustomID) UnmarshalJSON(b []byte) error {
2729
return null.UnmarshalInt(b, (*null.Int)(i))
2830
}
2931

32+
// Value returns the db value, null is returned for 0
3033
func (i CustomID) Value() (driver.Value, error) {
3134
return null.Int(i).Value()
3235
}
3336

37+
// Scan scans from the db value. null values become 0
3438
func (i *CustomID) Scan(value interface{}) error {
3539
return null.ScanInt(value, (*null.Int)(i))
3640
}
@@ -45,18 +49,22 @@ type CustomString null.String
4549

4650
type NullCustomString = CustomString("")
4751

52+
// MarshalJSON marshals into JSON. "" values will become null
4853
func (s CustomString) MarshalJSON() ([]byte, error) {
4954
return null.String(s).MarshalJSON()
5055
}
5156

57+
// UnmarshalJSON unmarshals from JSON. null values become ""
5258
func (s *CustomString) UnmarshalJSON(b []byte) error {
5359
return null.UnmarshalString(b, (*null.String)(s))
5460
}
5561

62+
// Value returns the db value, null is returned for ""
5663
func (s CustomString) Value() (driver.Value, error) {
5764
return null.String(s).Value()
5865
}
5966

67+
// Scan scans from the db value. null values become ""
6068
func (s *CustomString) Scan(value interface{}) error {
6169
return null.ScanString(value, (*null.String)(s))
6270
}

0 commit comments

Comments
 (0)