Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nyaruka/null
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Feb 12, 2019
2 parents 05165d3 + 5aff1dc commit c108471
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ type CustomID null.Int

const NullCustomID = CustomID(0)

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

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

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

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

type NullCustomString = CustomString("")

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

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

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

// Scan scans from the db value. null values become ""
func (s *CustomString) Scan(value interface{}) error {
return null.ScanString(value, (*null.String)(s))
}
Expand Down

0 comments on commit c108471

Please sign in to comment.