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.
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.
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.
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.