Documentation
¶
Overview ¶
Package omitnull exposes a Val(ue) type that wraps a regular value with the ability to be 'omitted/unset' or 'null'.
Index ¶
- Constants
- func Equal[T comparable](a, b Val[T]) bool
- type Val
- func (v Val[T]) Get() (T, bool)
- func (v Val[T]) GetNull() (null.Val[T], bool)
- func (v Val[T]) GetOmit() (omit.Val[T], bool)
- func (v Val[T]) GetOr(fallback T) T
- func (v Val[T]) GetOrZero() T
- func (v Val[T]) IfNull(then func())
- func (v Val[T]) IfUnset(then func())
- func (v Val[T]) IfValue(then func(v T))
- func (v Val[T]) IfZero(then func())
- func (v Val[T]) IsNull() bool
- func (v Val[T]) IsUnset() bool
- func (v Val[T]) IsValue() bool
- func (v Val[T]) IsZero() bool
- func (v Val[T]) Map(fn func(T) T) Val[T]
- func (v Val[T]) MarshalBinary() ([]byte, error)
- func (v Val[T]) MarshalJSON() ([]byte, error)
- func (v Val[T]) MarshalJSONIsZero() booldeprecated
- func (v Val[T]) MarshalText() ([]byte, error)
- func (v Val[T]) MustGet() T
- func (v Val[T]) MustGetNull() null.Val[T]
- func (v Val[T]) MustGetOmit() omit.Val[T]
- func (v Val[T]) MustPtr() *T
- func (v *Val[T]) Null()
- func (v Val[T]) Or(other Val[T]) Val[T]
- func (v *Val[T]) Scan(value any) error
- func (v *Val[T]) Set(val T)
- func (v *Val[T]) SetPtr(val *T)
- func (v Val[T]) State() state
- func (v *Val[T]) UnmarshalBinary(b []byte) error
- func (v *Val[T]) UnmarshalJSON(data []byte) error
- func (v *Val[T]) UnmarshalText(text []byte) error
- func (v *Val[T]) Unset()
- func (v Val[T]) Value() (driver.Value, error)
Constants ¶
const ( StateUnset state = 0 StateNull state = 1 StateSet state = 2 )
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
func Equal[T comparable](a, b Val[T]) bool
Equal compares two nullable values and returns true if they are equal.
Types ¶
type Val ¶
type Val[T any] struct { // contains filtered or unexported fields }
Val allows representing a value with a state of "unset", "null", or "set". Its zero value is useful and initially "unset".
func FromNull ¶
FromNull constructs a value from a nullable value. This is a lossless conversion and cannot fail.
func FromOmit ¶
FromOmit constructs a value from a omittable value. This is a lossless conversion and cannot fail.
func FromPtr ¶
FromPtr creates a value from a pointer, if the pointer is null it will be 'null', if it has a value the deferenced value is stored.
func (Val[T]) GetOr ¶
func (v Val[T]) GetOr(fallback T) T
GetOr gets the value or returns a fallback if the value does not exist.
func (Val[T]) GetOrZero ¶
func (v Val[T]) GetOrZero() T
GetOrZero returns the zero value for T if the value was omitted or null.