Documentation ¶
Overview ¶
Package zero contains SQL types that consider zero input and null input to be equivalent with convenient support for JSON and text marshaling. Types in this package will JSON marshal to their zero value, even if null. Use the null parent package if you don't want this.
Index ¶
- type Bool
- func (b Bool) GetBSON() (interface{}, error)
- func (b Bool) GetValue() reflect.Value
- func (b Bool) IsZero() bool
- func (b *Bool) LoremDecode(tag, example string) error
- func (b Bool) MarshalJSON() ([]byte, error)
- func (b Bool) MarshalText() ([]byte, error)
- func (b Bool) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (b Bool) Ptr() *bool
- func (b *Bool) SetBSON(raw bson.Raw) error
- func (b *Bool) SetValid(v bool)
- func (b *Bool) UnmarshalJSON(data []byte) error
- func (b *Bool) UnmarshalText(text []byte) error
- func (b *Bool) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Float
- func (f Float) GetBSON() (interface{}, error)
- func (f Float) GetValue() reflect.Value
- func (f Float) IsZero() bool
- func (f *Float) LoremDecode(tag, example string) error
- func (f Float) MarshalJSON() ([]byte, error)
- func (f Float) MarshalText() ([]byte, error)
- func (f Float) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (f Float) Ptr() *float64
- func (f *Float) SetBSON(raw bson.Raw) error
- func (f *Float) SetValid(v float64)
- func (f *Float) UnmarshalJSON(data []byte) error
- func (f *Float) UnmarshalText(text []byte) error
- func (f *Float) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Int32
- func (i Int32) GetBSON() (interface{}, error)
- func (i Int32) GetValue() reflect.Value
- func (i Int32) IsZero() bool
- func (i *Int32) LoremDecode(tag, example string) error
- func (i Int32) MarshalJSON() ([]byte, error)
- func (i Int32) MarshalText() ([]byte, error)
- func (i Int32) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (i Int32) Ptr() *int32
- func (i *Int32) SetBSON(raw bson.Raw) error
- func (i *Int32) SetValid(n int32)
- func (i *Int32) UnmarshalJSON(data []byte) error
- func (i *Int32) UnmarshalText(text []byte) error
- func (i *Int32) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Int64
- func (i Int64) GetBSON() (interface{}, error)
- func (i Int64) GetValue() reflect.Value
- func (i Int64) IsZero() bool
- func (i *Int64) LoremDecode(tag, example string) error
- func (i Int64) MarshalJSON() ([]byte, error)
- func (i Int64) MarshalText() ([]byte, error)
- func (i Int64) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (i Int64) Ptr() *int64
- func (i *Int64) SetBSON(raw bson.Raw) error
- func (i *Int64) SetValid(n int64)
- func (i *Int64) UnmarshalJSON(data []byte) error
- func (i *Int64) UnmarshalText(text []byte) error
- func (i *Int64) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type String
- func (s String) GetBSON() (interface{}, error)
- func (s String) GetValue() reflect.Value
- func (s String) IsZero() bool
- func (s *String) LoremDecode(tag, example string) error
- func (s String) MarshalText() ([]byte, error)
- func (s String) Ptr() *string
- func (s *String) SetBSON(raw bson.Raw) error
- func (s *String) SetValid(v string)
- func (s *String) UnmarshalJSON(data []byte) error
- func (s *String) UnmarshalText(text []byte) error
- func (s *String) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type Time
- func (t Time) AppendValue(b []byte, quote int) ([]byte, error)
- func (t Time) GetBSON() (interface{}, error)
- func (t Time) GetValue() reflect.Value
- func (t Time) IsZero() bool
- func (t *Time) LoremDecode(tag, example string) error
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) MarshalText() ([]byte, error)
- func (t Time) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (t Time) Ptr() *time.Time
- func (t *Time) Scan(value interface{}) error
- func (t *Time) SetBSON(raw bson.Raw) error
- func (t *Time) SetValid(v time.Time)
- func (t *Time) UnmarshalJSON(data []byte) error
- func (t *Time) UnmarshalText(text []byte) error
- func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (t Time) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
Bool is a nullable bool. False input is considered null. JSON marshals to false if null. Considered null to SQL unmarshaled from a false value.
func BoolFromPtr ¶
BoolFromPtr creates a new Bool that be null if b is nil.
func (Bool) IsZero ¶
IsZero returns true for null or zero Bools, for future omitempty support (Go 1.4?)
func (*Bool) LoremDecode ¶
LoremDecode implements lorem.Decoder
func (Bool) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode false if this Bool is null.
func (Bool) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a false if this Bool is null.
func (Bool) MarshalXML ¶
MarshalXML implements the xml.Marshaler interface
func (Bool) Ptr ¶
Ptr returns a poBooler to this Bool's value, or a nil poBooler if this Bool is null.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. "false" will be considered a null Bool. It also supports unmarshalling a sql.NullBool.
func (*Bool) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Bool if the input is a false or not a bool. It will return an error if the input is not a float, blank, or "null".
func (*Bool) UnmarshalXML ¶
UnmarshalXML implments the xml.Unmarshaler interface
type Float ¶
type Float struct {
sql.NullFloat64
}
Float is a nullable float64. Zero input will be considered null. JSON marshals to zero if null. Considered null to SQL if zero.
func FloatFromPtr ¶
FloatFromPtr creates a new Float that be null if f is nil.
func (Float) IsZero ¶
IsZero returns true for null or zero Floats, for future omitempty support (Go 1.4?)
func (*Float) LoremDecode ¶
LoremDecode implements lorem.Decoder
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 zero if this Float is null.
func (Float) MarshalXML ¶
MarshalXML implements the xml.Marshaler interface
func (Float) Ptr ¶
Ptr returns a poFloater to this Float's value, or a nil poFloater if this Float is null.
func (*Float) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Float. It also supports unmarshalling a sql.NullFloat64.
func (*Float) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Float if the input is a blank, zero, or not a float. It will return an error if the input is not a float, blank, or "null".
func (*Float) UnmarshalXML ¶
UnmarshalXML implments the xml.Unmarshaler interface
type Int32 ¶
Int32 is a nullable int32. JSON marshals to zero if null. Considered null to SQL if zero.
func Int32FromPtr ¶
Int32FromPtr creates a new Int32 that be null if i is nil.
func (Int32) IsZero ¶
IsZero returns true for null or zero Ints, for future omitempty support (Go 1.4?)
func (*Int32) LoremDecode ¶
LoremDecode implements lorem.Decoder
func (Int32) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Int32 is null.
func (Int32) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Int32 is null.
func (Int32) MarshalXML ¶
MarshalXML implements the xml.Marshaler interface
func (Int32) Ptr ¶
Ptr returns a pointer to this Int32's value, or a nil pointer if this Int32 is null.
func (*Int32) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Int32. It also supports unmarshalling a sql.NullInt32.
func (*Int32) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int32 if the input is a blank, zero, or not an integer. It will return an error if the input is not an integer, blank, or "null".
func (*Int32) UnmarshalXML ¶
UnmarshalXML implments the xml.Unmarshaler interface
type Int64 ¶
Int64 is a nullable int64. JSON marshals to zero if null. Considered null to SQL if zero.
func Int64FromPtr ¶
Int64FromPtr creates a new Int64 that be null if i is nil.
func (Int64) IsZero ¶
IsZero returns true for null or zero Ints, for future omitempty support (Go 1.4?)
func (*Int64) LoremDecode ¶
LoremDecode implements lorem.Decoder
func (Int64) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Int64 is null.
func (Int64) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Int64 is null.
func (Int64) MarshalXML ¶
MarshalXML implements the xml.Marshaler interface
func (Int64) Ptr ¶
Ptr returns a pointer to this Int64's value, or a nil pointer if this Int64 is null.
func (*Int64) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Int64. It also supports unmarshalling a sql.NullInt64.
func (*Int64) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int64 if the input is a blank, zero, or not an integer. It will return an error if the input is not an integer, blank, or "null".
func (*Int64) UnmarshalXML ¶
UnmarshalXML implments the xml.Unmarshaler interface
type String ¶
type String struct {
sql.NullString
}
String is a nullable string. JSON marshals to a blank string if null. Considered null to SQL if zero.
func StringFrom ¶
StringFrom creates a new String that will be null if s is blank.
func StringFromPtr ¶
StringFromPtr creates a new String that be null if s is nil or blank. It will make s point to the String's value.
func (String) IsZero ¶
IsZero returns true for null or empty strings, for potential future omitempty support.
func (*String) LoremDecode ¶
LoremDecode implements lorem.Decoder
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 produces a null String. It also supports unmarshalling a sql.NullString.
func (*String) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null String if the input is a blank string.
func (*String) UnmarshalXML ¶
UnmarshalXML implments the xml.Unmarshaler interface
type Time ¶
Time is a zeroable time.Time. JSON marshals to the zero value for time.Time if null. Considered to be null to SQL if zero.
func TimeFromPtr ¶
TimeFromPtr creates a new Time that will be null if t is nil or *t is the zero value.
func (Time) AppendValue ¶
AppendValue implements the types.ValueAppender interface
func (*Time) LoremDecode ¶
LoremDecode implements lorem.Decoder
func (Time) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode the zero value of time.Time if this time is invalid.
func (Time) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Time) MarshalXML ¶
MarshalXML implements the xml.Marshaler interface
func (Time) Ptr ¶
Ptr returns a pointer to this Time's value, or a nil pointer if this Time is zero.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports string, object (e.g. pq.NullTime and friends) and null input.
func (*Time) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
func (*Time) UnmarshalXML ¶
UnmarshalXML implments the xml.Unmarshaler interface