Documentation
¶
Overview ¶
Package nullable provides nullable value types with SQL and JSON support.
Index ¶
- type Bool
- type Byte
- type Float32
- type Float64
- type Int
- type Int8
- type Int16
- type Int32
- type Int64
- type NullableBase
- func (nv NullableBase[T]) IsNull() bool
- func (nv NullableBase[T]) MarshalJSON() ([]byte, error)
- func (nv NullableBase[T]) RawValue() T
- func (nv *NullableBase[T]) Scan(src any) error
- func (nv *NullableBase[T]) SetNull()
- func (nv *NullableBase[T]) SetSqlNull(value sql.Null[T])
- func (nv *NullableBase[T]) SetValue(value T)
- func (nv NullableBase[T]) SqlNull() sql.Null[T]
- func (nv *NullableBase[T]) UnmarshalJSON(data []byte) error
- func (nv NullableBase[T]) Value() (driver.Value, error)
- func (nv NullableBase[T]) ValueOrZero() T
- type Rune
- type String
- type Time
- type UInt
- type UInt8
- type UInt16
- type UInt32
- type UInt64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Float32 ¶
type Float32 struct {
NullableBase[float32]
}
Float32 represents a nullable float32.
func NewFloat32 ¶
NewFloat32 returns a non-null Float32 containing value.
func (Float32) Equal ¶
Equal reports whether nv and value are both null or contain equal float32 values.
func (Float32) EqualBits ¶
EqualBits reports whether nv and value are both null or have the same float32 bit pattern.
func (Float32) EqualEpsilon ¶
EqualEpsilon reports whether nv and value are both null or differ by at most epsilon. NaN values never compare equal, while equal infinities do. Positive and negative zero are both accepted as epsilon. It panics unless epsilon is finite and non-negative.
type Float64 ¶
type Float64 struct {
NullableBase[float64]
}
Float64 represents a nullable float64.
func NewFloat64 ¶
NewFloat64 returns a non-null Float64 containing value.
func (Float64) Equal ¶
Equal reports whether nv and value are both null or contain equal float64 values.
func (Float64) EqualBits ¶
EqualBits reports whether nv and value are both null or have the same float64 bit pattern.
func (Float64) EqualEpsilon ¶
EqualEpsilon reports whether nv and value are both null or differ by at most epsilon. NaN values never compare equal, while equal infinities do. Positive and negative zero are both accepted as epsilon. It panics unless epsilon is finite and non-negative.
type Int16 ¶
type Int16 struct {
NullableBase[int16]
}
Int16 represents a nullable int16.
type Int32 ¶
type Int32 struct {
NullableBase[int32]
}
Int32 represents a nullable int32.
type Int64 ¶
type Int64 struct {
NullableBase[int64]
}
Int64 represents a nullable int64.
type NullableBase ¶
type NullableBase[T any] struct { // contains filtered or unexported fields }
NullableBase stores a nullable value and implements SQL and JSON interfaces.
func NewNullableBase ¶
func NewNullableBase[T any](value T) NullableBase[T]
NewNullableBase returns a non-null NullableBase containing value.
func (NullableBase[T]) IsNull ¶
func (nv NullableBase[T]) IsNull() bool
IsNull reports whether the receiver is null.
func (NullableBase[T]) MarshalJSON ¶
func (nv NullableBase[T]) MarshalJSON() ([]byte, error)
MarshalJSON encodes null when the receiver is null.
func (NullableBase[T]) RawValue ¶
func (nv NullableBase[T]) RawValue() T
RawValue returns the stored value without checking whether it is null.
func (*NullableBase[T]) Scan ¶
func (nv *NullableBase[T]) Scan(src any) error
Scan stores a database value using sql.Null scanning rules.
func (*NullableBase[T]) SetNull ¶
func (nv *NullableBase[T]) SetNull()
SetNull marks the receiver as null and clears the stored value.
func (*NullableBase[T]) SetSqlNull ¶
func (nv *NullableBase[T]) SetSqlNull(value sql.Null[T])
SetSqlNull stores the value and null state from sql.Null.
func (*NullableBase[T]) SetValue ¶
func (nv *NullableBase[T]) SetValue(value T)
SetValue stores value and marks the receiver as non-null.
func (NullableBase[T]) SqlNull ¶
func (nv NullableBase[T]) SqlNull() sql.Null[T]
SqlNull returns a sql.Null with the same value and null state.
func (*NullableBase[T]) UnmarshalJSON ¶
func (nv *NullableBase[T]) UnmarshalJSON(data []byte) error
UnmarshalJSON stores null for JSON null, otherwise stores the decoded value.
func (NullableBase[T]) Value ¶
func (nv NullableBase[T]) Value() (driver.Value, error)
Value returns nil for null values, otherwise the converted driver value. It returns nil and an error if the value cannot be converted.
func (NullableBase[T]) ValueOrZero ¶
func (nv NullableBase[T]) ValueOrZero() T
ValueOrZero returns the stored value, or the zero value when it is null.
type String ¶
type String struct {
NullableBase[string]
}
String represents a nullable string.
type UInt8 ¶
type UInt8 struct {
NullableBase[uint8]
}
UInt8 represents a nullable uint8.
type UInt16 ¶
type UInt16 struct {
NullableBase[uint16]
}
UInt16 represents a nullable uint16.
type UInt32 ¶
type UInt32 struct {
NullableBase[uint32]
}
UInt32 represents a nullable uint32.