Skip to content

Commit

Permalink
Fixed nullable
Browse files Browse the repository at this point in the history
Writing fixed as null if not valid
  • Loading branch information
liepumartins authored Aug 19, 2024
1 parent d9f1828 commit 4aafc6e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ func (d *NullFixed) Scan(value interface{}) error {
str, err := unquoteIfQuoted(v)
if err != nil {
d.Valid = false
d.Fixed = fixed.ZERO
return err
}
d.Fixed, err = fixed.NewSErr(str)
if err != nil {
d.Fixed = fixed.ZERO
d.Valid = false
}
return err
Expand All @@ -53,14 +51,16 @@ func (d *NullFixed) Scan(value interface{}) error {

// Value implements the driver.Valuer interface for database serialization.
func (d NullFixed) Value() (driver.Value, error) {
if !d.Valid {
return nil, nil
}
return d.Fixed.String(), nil
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (d *NullFixed) UnmarshalJSON(decimalBytes []byte) error {
if string(decimalBytes) == "null" {
d.Valid = false
d.Fixed = fixed.ZERO
return nil
}
d.Valid = true
Expand Down

0 comments on commit 4aafc6e

Please sign in to comment.