null

reasonable handling of nullable values

BSD-2-CLAUSE License

Downloads
225
Stars
1.9K
Committers
10

Bot releases are hidden (Show)

null - Generics & more Latest Release

Published by guregu 8 months ago

  • Now a Go module under the path github.com/guregu/null/v5
    • ⚠️ Please use this instead of from the former gopkg.in path.
    • Previously this package didn't use modules to support ancient pre-go mod environments, but now module support is required.
  • Added missing types from database/sql: Int32, Int16, Byte
  • Added generic Value[T] embedding sql.Null[T]
    • Note that zero.Value[T] requires that T is comparable. null.Value[T] supports any value.
    • This doesn't support TextMarshaler because there's no generic way to support all types (e.g. structs). We could support some types but I'm not sure if that's useful.
    • This type requires Go version ≥1.22, on lower versions it won't be present

Behavior from v4 is unchanged, so it should be an easy upgrade.
Thank you and enjoy.

null - Major brush-up

Published by guregu over 4 years ago

This is a new major release that improves performance and fixes an inconsistency that existed in v3.

  • null.Time and zero.Time now embed sql.NullTime.
  • null.Time and zero.Time's UnmarshalText returns a blank string if invalid, making them consistent with the rest of the package (see #47).
  • Errors returned by this package are now wrapped using Go 1.13-style errors.
  • Support for unmarshaling from the JSON representation of sql.NullXXX objects (ex. {"Int64": 123, "Valid": true}) has been dropped, significantly improving unmarshaling time and reducing allocations.
  • Unmarshaling errors no longer affect Valid. Always check for errors.

Support for Equal was added in the previous release.

null - Equal method

Published by guregu over 4 years ago

This release adds an Equal method to all types, for easy equality checks.
It also adds ValueOrZero to the zero package.
Types in the null package are considered Equal if they're either both invalid, or both valid and have the same value.
Types on the zero package are considered Equal if their ValueOrZero is the same, so an invalid string and a valid "" are equal.

This will be the last release before v4.

null - Time.IsZero

Published by guregu about 6 years ago

Adds IsZero methods for Time in line with the rest of the types.

null - ValueOrZero

Published by guregu almost 7 years ago

Added a new method ValueOrZero to every type in the null package. This method returns the inner value if valid, or the zero value if invalid (similar to the zero package). See #17.

null - Return error when JSON-marshaling NaN or Infinity floats

Published by guregu almost 7 years ago

If you try to JSON marshal Infinity or NaN, you'll get *encoding/json.UnsupportedValueError. This brings us in line with the standard library.

null - More flexible JSON parsing

Published by guregu about 7 years ago

Int and Float can now be read from JSON strings. #23

null - MarshalText for null.String

Published by guregu over 8 years ago

MarshalText was missing from null.String, but no longer!

null - Minor documentation fixes

Published by guregu over 8 years ago

This version updates the GoDoc to be consistent with the changes described in #10 and #14.

null - Consistency in the null package

Published by guregu about 9 years ago

Blank string input now produces a null null.String. Now the null package is consistent. Please use the zero.String type or v2 if you would like the old behavior.

Fixes #10.

null - Nullable Time!

Published by guregu about 9 years ago

Adds the long-awaited null.Time and zero.Time. These are nullable time.Time just like pq.NullTime.

null - Better invalid JSON handling

Published by guregu about 9 years ago

Enjoy proper errors from the json package.

null - more precise int unmarshaling

Published by guregu about 10 years ago

Fixes #3. Thanks @hasryan!

null - more thorough error checking

Published by guregu about 10 years ago

UnmarshalJSON returns an error given an unsupported type now. Thanks @joelkek!

null - update docs

Published by guregu about 10 years ago

v2 Changes

Change package names of nuller to null
and the previous null to zero.

This way zeroing types will be called zero.Type and nulling types will be called null.Type, so they are easier to understand at a glance.

v2.0.1 Changes

Update the docs

null - refactor package names

Published by guregu about 10 years ago

Change package names of nuller to null
and the previous null to zero.

This way zeroing types will be called zero.Type and nulling types will be called null.Type, so they are easier to understand at a glance.