Documentation ¶
Overview ¶
Package nullable contains types that represent values that may be null. The Go standard library already has NullBool, NullFloat64, NullInt64 and NullString in the database/sql package. The types in this package add additional data types.
The types in this package also all implement the json.Marshaler and json.Unmarshaler interfaces, so they can be serialized to and from JSON. These types also have convience methods for converting to and from pointers.
Index ¶
- type Bool
- type Byte
- type Float32
- func (n *Float32) Assign(ptr *float32) Float32
- func (n Float32) MarshalJSON() ([]byte, error)
- func (n Float32) Normalized() Float32
- func (n Float32) Ptr() *float32
- func (n *Float32) Scan(value interface{}) error
- func (n *Float32) UnmarshalJSON(p []byte) error
- func (n Float32) Value() (driver.Value, error)
- type Float64
- func (n *Float64) Assign(ptr *float64) Float64
- func (n Float64) MarshalJSON() ([]byte, error)
- func (n Float64) Normalized() Float64
- func (n Float64) Ptr() *float64
- func (n *Float64) Scan(value interface{}) error
- func (n *Float64) UnmarshalJSON(p []byte) error
- func (n Float64) Value() (driver.Value, error)
- type Int
- type Int16
- type Int32
- type Int64
- type Int8
- type String
- type Time
- type Uint
- type Uint16
- type Uint32
- type Uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
Bool represents a bool value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func BoolFromPtr ¶
BoolFromPtr returns a Bool whose value matches ptr.
func (*Bool) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Bool) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Bool) Normalized ¶
Normalized returns a Bool that can be compared with another Bool for equality.
func (Bool) Ptr ¶
Ptr returns a pointer to bool. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Byte ¶
Byte represents a byte value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func ByteFromPtr ¶
ByteFromPtr returns a Byte whose value matches ptr.
func (*Byte) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Byte) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Byte) Normalized ¶
Normalized returns a Byte that can be compared with another Byte for equality.
func (Byte) Ptr ¶
Ptr returns a pointer to byte. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Byte) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Float32 ¶
Float32 represents a float32 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Float32FromPtr ¶
Float32FromPtr returns a Float32 whose value matches ptr.
func (*Float32) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Float32) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Float32) Normalized ¶
Normalized returns a Float32 that can be compared with another Float32 for equality.
func (Float32) Ptr ¶
Ptr returns a pointer to float32. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Float32) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Float64 ¶
Float64 represents a float64 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Float64FromPtr ¶
Float64FromPtr returns a Float64 whose value matches ptr.
func (*Float64) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Float64) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Float64) Normalized ¶
Normalized returns a Float64 that can be compared with another Float64 for equality.
func (Float64) Ptr ¶
Ptr returns a pointer to float64. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Float64) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Int ¶
Int represents an int value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func (*Int) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Int) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Int) Normalized ¶
Normalized returns an Int that can be compared with another Int for equality.
func (Int) Ptr ¶
Ptr returns a pointer to int. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Int16 ¶
Int16 represents an int16 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Int16FromPtr ¶
Int16FromPtr returns a Int16 whose value matches ptr.
func (*Int16) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Int16) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Int16) Normalized ¶
Normalized returns an Int16 that can be compared with another Int16 for equality.
func (Int16) Ptr ¶
Ptr returns a pointer to int16. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Int16) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Int32 ¶
Int32 represents an int32 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Int32FromPtr ¶
Int32FromPtr returns a Int32 whose value matches ptr.
func (*Int32) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Int32) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Int32) Normalized ¶
Normalized returns an Int32 that can be compared with another Int32 for equality.
func (Int32) Ptr ¶
Ptr returns a pointer to int32. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Int32) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Int64 ¶
Int64 represents an int64 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Int64FromPtr ¶
Int64FromPtr returns a Int64 whose value matches ptr.
func (*Int64) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Int64) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Int64) Normalized ¶
Normalized returns an Int64 that can be compared with another Int64 for equality.
func (Int64) Ptr ¶
Ptr returns a pointer to int64. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Int64) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Int8 ¶
Int8 represents an int8 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Int8FromPtr ¶
Int8FromPtr returns a Int8 whose value matches ptr.
func (*Int8) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Int8) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Int8) Normalized ¶
Normalized returns an Int8 that can be compared with another Int8 for equality.
func (Int8) Ptr ¶
Ptr returns a pointer to int8. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Int8) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type String ¶
String represents a string value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func StringFromPtr ¶
StringFromPtr returns a String whose value matches ptr.
func (*String) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (String) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (String) Normalized ¶
Normalized returns a String that can be compared with another String for equality.
func (String) Ptr ¶
Ptr returns a pointer to string. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Time ¶
Time represents a time.Time value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func TimeFromPtr ¶
TimeFromPtr returns a Time whose value matches ptr.
func (*Time) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Time) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Time) Normalized ¶
Normalized returns a Time that can be compared with another Time for equality.
func (Time) Ptr ¶
Ptr returns a pointer to time.Time. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint ¶
Uint represents a uint value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func UintFromPtr ¶
UintFromPtr returns a Uint whose value matches ptr.
func (*Uint) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Uint) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Uint) Normalized ¶
Normalized returns a Uint that can be compared with another Uint for equality.
func (Uint) Ptr ¶
Ptr returns a pointer to uint. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Uint) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint16 ¶
Uint16 represents a uint16 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Uint16FromPtr ¶
Uint16FromPtr returns a Uint16 whose value matches ptr.
func (*Uint16) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Uint16) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Uint16) Normalized ¶
Normalized returns a Uint16 that can be compared with another Uint16 for equality.
func (Uint16) Ptr ¶
Ptr returns a pointer to uint16. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Uint16) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint32 ¶
Uint32 represents a uint32 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Uint32FromPtr ¶
Uint32FromPtr returns a Uint32 whose value matches ptr.
func (*Uint32) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Uint32) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Uint32) Normalized ¶
Normalized returns a Uint32 that can be compared with another Uint32 for equality.
func (Uint32) Ptr ¶
Ptr returns a pointer to uint32. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Uint32) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint64 ¶
Uint64 represents a uint64 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.
func Uint64FromPtr ¶
Uint64FromPtr returns a Uint64 whose value matches ptr.
func (*Uint64) Assign ¶
Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.
func (Uint64) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Uint64) Normalized ¶
Normalized returns a Uint64 that can be compared with another Uint64 for equality.
func (Uint64) Ptr ¶
Ptr returns a pointer to uint64. If Valid is false then the pointer is nil, otherwise it is non-nil.
func (*Uint64) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.