Documentation ¶
Overview ¶
Package null contains SQL types that consider zero input and null input as separate values, with convenient support for JSON and text marshaling. Types in this package will always encode to their null value if null. Use the zero subpackage if you want zero values and null to be treated the same.
Index ¶
- Variables
- type Bool
- func (b Bool) Equal(other Bool) bool
- func (b Bool) IsZero() bool
- func (b Bool) MarshalJSON() ([]byte, error)
- func (b Bool) MarshalText() ([]byte, error)
- func (b Bool) Ptr() *bool
- func (b *Bool) SetValid(v bool)
- func (b *Bool) UnmarshalJSON(data []byte) error
- func (b *Bool) UnmarshalText(text []byte) error
- func (b Bool) ValueOrZero() bool
- type DateString
- func (s DateString) Equal(other DateString) bool
- func (s DateString) IsZero() bool
- func (s DateString) MarshalJSON() ([]byte, error)
- func (s DateString) MarshalText() ([]byte, error)
- func (s DateString) Ptr() *string
- func (s *DateString) SetValid(v string)
- func (s *DateString) UnmarshalJSON(data []byte) error
- func (s *DateString) UnmarshalText(text []byte) error
- func (s DateString) ValueOrZero() string
- type Float
- func (f Float) Equal(other Float) bool
- func (f Float) IsZero() bool
- func (f Float) MarshalJSON() ([]byte, error)
- func (f Float) MarshalText() ([]byte, error)
- func (f Float) Ptr() *float64
- func (f *Float) SetValid(n float64)
- func (f *Float) UnmarshalJSON(data []byte) error
- func (f *Float) UnmarshalText(text []byte) error
- func (f Float) ValueOrZero() float64
- type Int
- func (i Int) Equal(other Int) bool
- func (i Int) IsZero() bool
- func (i Int) MarshalJSON() ([]byte, error)
- func (i Int) MarshalText() ([]byte, error)
- func (i Int) Ptr() *int64
- func (i *Int) SetValid(n int64)
- func (i *Int) UnmarshalJSON(data []byte) error
- func (i *Int) UnmarshalText(text []byte) error
- func (i Int) ValueOrZero() int64
- type String
- func (s String) Equal(other String) bool
- func (s String) IsZero() bool
- func (s String) MarshalJSON() ([]byte, error)
- func (s String) MarshalText() ([]byte, error)
- func (s String) Ptr() *string
- func (s *String) SetValid(v string)
- func (s *String) UnmarshalJSON(data []byte) error
- func (s *String) UnmarshalText(text []byte) error
- func (s String) ValueOrZero() string
- type Time
- func (t Time) Equal(other Time) bool
- func (t Time) ExactEqual(other Time) bool
- func (t Time) IsZero() bool
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) MarshalText() ([]byte, error)
- func (t Time) Ptr() *time.Time
- func (t *Time) SetValid(v time.Time)
- func (t *Time) UnmarshalJSON(data []byte) error
- func (t *Time) UnmarshalText(text []byte) error
- func (t Time) Value() (driver.Value, error)
- func (t Time) ValueOrZero() time.Time
Constants ¶
This section is empty.
Variables ¶
var (
// FormatDate Set default Format DateString
FormatDate = "2006-01-02"
)
Functions ¶
This section is empty.
Types ¶
type Bool ¶
Bool is a nullable bool. It does not consider false values to be null. It will decode to null, not false, if null.
func BoolFromPtr ¶
BoolFromPtr creates a new Bool that will be null if f is nil.
func (Bool) IsZero ¶
IsZero returns true for invalid Bools, for future omitempty support (Go 1.4?) A non-null Bool with a 0 value will not be considered zero.
func (Bool) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this Bool is null.
func (Bool) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Bool is null.
func (Bool) Ptr ¶
Ptr returns a pointer to this Bool's value, or a nil pointer if this Bool is null.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Bool.
func (*Bool) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Bool if the input is blank. It will return an error if the input is not an integer, blank, or "null".
func (Bool) ValueOrZero ¶
ValueOrZero returns the inner value if valid, otherwise false.
type DateString ¶
type DateString struct {
sql.NullString
}
DateString DateString string is a nullable string. It supports SQL and JSON serialization.
func DateStringFrom ¶
func DateStringFrom(s string) DateString
DateStringFrom creates a new String that will never be blank.
func DateStringFromPtr ¶
func DateStringFromPtr(s *string) DateString
DateStringFromPtr creates a new String that be null if s is nil.
func NewDateString ¶
func NewDateString(s string, valid bool) DateString
NewDateString creates a new String
func (DateString) Equal ¶
func (s DateString) Equal(other DateString) bool
Equal returns true if both strings have the same value or are both null.
func (DateString) IsZero ¶
func (s DateString) IsZero() bool
IsZero returns true for null strings, for potential future omitempty support.
func (DateString) MarshalJSON ¶
func (s DateString) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler. It will encode null if this String is null.
func (DateString) MarshalText ¶
func (s DateString) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler. It will encode a blank string when this String is null.
func (DateString) Ptr ¶
func (s DateString) Ptr() *string
Ptr returns a pointer to this String's value, or a nil pointer if this String is null.
func (*DateString) SetValid ¶
func (s *DateString) SetValid(v string)
SetValid changes this String's value and also sets it to be non-null.
func (*DateString) UnmarshalJSON ¶
func (s *DateString) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler. It supports string and null input. Blank string input does not produce a null String.
func (*DateString) UnmarshalText ¶
func (s *DateString) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null String if the input is a blank string.
func (DateString) ValueOrZero ¶
func (s DateString) ValueOrZero() string
ValueOrZero returns the inner value if valid, otherwise zero.
type Float ¶
type Float struct {
sql.NullFloat64
}
Float is a nullable float64. It does not consider zero values to be null. It will decode to null, not zero, if null.
func FloatFromPtr ¶
FloatFromPtr creates a new Float that be null if f is nil.
func (Float) Equal ¶
Equal returns true if both floats have the same value or are both null. Warning: calculations using floating point numbers can result in different ways the numbers are stored in memory. Therefore, this function is not suitable to compare the result of a calculation. Use this method only to check if the value has changed in comparison to some previous value.
func (Float) IsZero ¶
IsZero returns true for invalid Floats, for future omitempty support (Go 1.4?) A non-null Float with a 0 value will not be considered zero.
func (Float) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this Float is null.
func (Float) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Float is null.
func (Float) Ptr ¶
Ptr returns a pointer to this Float's value, or a nil pointer if this Float is null.
func (*Float) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Float.
func (*Float) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Float if the input is blank. It will return an error if the input is not an integer, blank, or "null".
func (Float) ValueOrZero ¶
ValueOrZero returns the inner value if valid, otherwise zero.
type Int ¶
Int is an nullable int64. It does not consider zero values to be null. It will decode to null, not zero, if null.
func IntFromPtr ¶
IntFromPtr creates a new Int that be null if i is nil.
func (Int) IsZero ¶
IsZero returns true for invalid Ints, for future omitempty support (Go 1.4?) A non-null Int with a 0 value will not be considered zero.
func (Int) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this Int is null.
func (Int) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Int is null.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number, string, and null input. 0 will not be considered a null Int.
func (*Int) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int if the input is blank. It will return an error if the input is not an integer, blank, or "null".
func (Int) ValueOrZero ¶
ValueOrZero returns the inner value if valid, otherwise zero.
type String ¶
type String struct {
sql.NullString
}
String is a nullable string. It supports SQL and JSON serialization. It will marshal to null if null. Blank string input will be considered null.
func StringFrom ¶
StringFrom creates a new String that will never be blank.
func StringFromPtr ¶
StringFromPtr creates a new String that be null if s is nil.
func (String) IsZero ¶
IsZero returns true for null strings, for potential future omitempty support.
func (String) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this String is null.
func (String) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a blank string when this String is null.
func (String) Ptr ¶
Ptr returns a pointer to this String's value, or a nil pointer if this String is null.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports string and null input. Blank string input does not produce a null String.
func (*String) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null String if the input is a blank string.
func (String) ValueOrZero ¶
ValueOrZero returns the inner value if valid, otherwise zero.
type Time ¶
Time is a nullable time.Time. It supports SQL and JSON serialization. It will marshal to null if null.
func TimeFromPtr ¶
TimeFromPtr creates a new Time that will be null if t is nil.
func (Time) Equal ¶
Equal returns true if both Time objects encode the same time or are both null. Two times can be equal even if they are in different locations. For example, 6:00 +0200 CEST and 4:00 UTC are Equal.
func (Time) ExactEqual ¶
ExactEqual returns true if both Time objects are equal or both null. ExactEqual returns false for times that are in different locations or have a different monotonic clock reading.
func (Time) IsZero ¶
IsZero returns true for invalid Times, hopefully for future omitempty support. A non-null Time with a zero value will not be considered zero.
func (Time) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this time is null.
func (Time) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It returns an empty string if invalid, otherwise time.Time's MarshalText.
func (Time) Ptr ¶
Ptr returns a pointer to this Time's value, or a nil pointer if this Time is null.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports string and null input.
func (*Time) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It has backwards compatibility with v3 in that the string "null" is considered equivalent to an empty string and unmarshaling will succeed. This may be removed in a future version.
func (Time) ValueOrZero ¶
ValueOrZero returns the inner value if valid, otherwise zero.
Directories ¶
Path | Synopsis |
---|---|
Package zero contains SQL types that consider zero input and null input to be equivalent with convenient support for JSON and text marshaling.
|
Package zero contains SQL types that consider zero input and null input to be equivalent with convenient support for JSON and text marshaling. |