Documentation ¶
Overview ¶
null makes it easier to deal with values that could be null or undefined. Armaria deals with databases and JSON a fair bit. Both of these things make use of NULL. The abstractions in this file allow us to support NULL robustly for both of them. The abstractions also keep track of whether a field was set at all which is useful for optional params. This is largely based on the excellent ideas in this package: https://github.com/guregu/null
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PtrFromNullInt64 ¶
PtrFromNullInt64 converts a NullInt64 to a *int64. If the NullInt64 is not Valid nil is returned.
func PtrFromNullString ¶
func PtrFromNullString(str NullString) *string
PtrFromNullString converts a NullString to a *string. If the NullString is not Valid nil is returned.
Types ¶
type NullInt64 ¶
type NullInt64 struct { sql.NullInt64 // allows use with sql/database and grants null support (null if Valid = false) Dirty bool // tracks if the argument has been provided at all (provided if Dirty = true) }
NullInt64 is an int64 that can be NULL.
func NullInt64From ¶
NullInt64From converts an int to a NullInt. If the int is zero it will be treated as null. The returned NullInt64 will have Dirty set to true.
func NullInt64FromPtr ¶
NullInt64FromPtr converts a *int64 to a NullInt64. If the int64 is nil it will be treated as null. The returned NullInt64 will have Dirty set to true.
func (NullInt64) MarshalJSON ¶
MarshalJSON marshalls a NullInt64 to JSON.
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON unmarshalls a NullInt64 from JSON.
type NullString ¶
type NullString struct { sql.NullString // allows use with sql/database and grants null support (null if Valid = false) Dirty bool // tracks if the argument has been provided at all (provided if Dirty = true) }
NullString is a string that can be NULL.
func NullStringFrom ¶
func NullStringFrom(str string) NullString
NullStringFrom converts a string to a NullString. The returned NullString will have Dirty set to true.
func NullStringFromPtr ¶
func NullStringFromPtr(str *string) NullString
NullStringFromPtr converts a *string to a NullString. If the string is nil it will be treated as null. The returned NullString will have Dirty set to true.
func (NullString) MarshalJSON ¶
func (s NullString) MarshalJSON() ([]byte, error)
MarshalJSON marshalls a NullString to JSON.
func (*NullString) UnmarshalJSON ¶
func (s *NullString) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshalls a NullString from JSON.