Documentation ¶
Overview ¶
Package null provides generic nullable types.
Provided types are compatible with encoding/json (json.Marshaler and json.Unmarshaler) and sql/database (sql.Scanner and driver.Valuer)
Index ¶
- Variables
- type Nullable
- type Type
- func (s *Type[T]) CheckedValue() (T, bool)
- func (s *Type[T]) CheckedValuePtr() (*T, bool)
- func (s *Type[T]) DefaultValue() T
- func (s *Type[T]) IsNull() bool
- func (s *Type[T]) RawValue() T
- func (s *Type[T]) RawValuePtr() *T
- func (s *Type[T]) SetNull()
- func (s *Type[T]) SetValue(v T)
- func (s *Type[T]) SetValueFromPtr(valuePtr *T)
Constants ¶
This section is empty.
Variables ¶
var ( ErrScanningTypeMismatch = errors.New("scanning type mismatch") ErrTypeIsNotSupported = errors.New("type is not supported by driver.Valuer") )
Functions ¶
This section is empty.
Types ¶
type Nullable ¶ added in v1.2.3
Nullable is defined in order to implement default JSON marshaling and unmarshaling, and sql/database compatability
func NullableValue ¶ added in v1.2.3
NullableValue returns not null Nullable with value.
func NullableValueFromPtr ¶ added in v1.2.3
NullableValueFromPtr returns null Nullable if valuePtr is nil, Nullable with actual value otherwise.
func (Nullable[T]) MarshalJSON ¶ added in v1.2.3
func (*Nullable[T]) Scan ¶ added in v1.2.3
Scan implements sql.Scanner. Supported T are: int, int32, int64, uint, uint32, uint64, float32, float64, bool, []byte, string, time.Time
func (*Nullable[T]) UnmarshalJSON ¶ added in v1.2.3
type Type ¶
type Type[T any] struct { // contains filtered or unexported fields }
Type represents a nullable type. Default value is null.
func TypeValueFromPtr ¶ added in v1.2.3
TypeValueFromPtr returns null Type if valuePtr is nil, Type with actual value otherwise.
func (*Type[T]) CheckedValue ¶ added in v1.2.0
CheckedValue returns actual value and true if Type is not null, default value of T and false otherwise.
func (*Type[T]) CheckedValuePtr ¶ added in v1.2.0
CheckedValuePtr returns pointer to actual value and true if Type is not null, false otherwise
func (*Type[T]) DefaultValue ¶ added in v1.2.0
func (s *Type[T]) DefaultValue() T
DefaultValue returns default value of T
func (*Type[T]) RawValue ¶
func (s *Type[T]) RawValue() T
RawValue returns actual value if Type is not null, default value of T otherwise.
func (*Type[T]) RawValuePtr ¶ added in v1.2.0
func (s *Type[T]) RawValuePtr() *T
RawValuePtr returns pointer to actual value. Is useful only when Type is not null
func (*Type[T]) SetValueFromPtr ¶ added in v1.2.0
func (s *Type[T]) SetValueFromPtr(valuePtr *T)
SetValueFromPtr sets Type to not null value if valuePtr is not nil, null value otherwise.