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
- type Bytes
- type Float32
- type Float64
- type Int
- type Int16
- type Int32
- type Int64
- type Int8
- type JSON
- type NullBytes
- type NullFloat32
- type NullInt
- type NullInt16
- type NullInt32
- type NullInt8
- type NullJSON
- type NullUint
- type NullUint16
- type NullUint32
- type NullUint64
- type NullUint8
- type String
- type Time
- func (t Time) MarshalJSON() ([]byte, error)
- func (t Time) MarshalText() ([]byte, error)
- func (t Time) Ptr() *time.Time
- func (t *Time) Scan(value interface{}) 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) Value() (driver.Value, error)
- type Uint
- type Uint16
- type Uint32
- type Uint64
- type Uint8
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) 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 zero if this Bool is null.
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".
type Bytes ¶
type Bytes struct {
NullBytes
}
Bytes is a nullable []byte. JSON marshals to zero if null. Considered null to SQL if zero.
func BytesFromPtr ¶
BytesFromPtr creates a new Bytes that be null if len zero.
func (Bytes) IsZero ¶
IsZero returns true for null or zero Bytes's, for future omitempty support (Go 1.4?)
func (Bytes) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if the Bytes is nil.
func (Bytes) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode nil if the Bytes is invalid.
func (Bytes) Ptr ¶
Ptr returns a pointer to this Bytes's value, or a nil pointer if this Bytes is null.
func (*Bytes) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. If data is len 0 or nil, it will unmarshal to JSON null. If not, it will copy your data slice into Bytes.
func (*Bytes) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to nil if the text is nil or len 0.
type Float32 ¶
type Float32 struct {
NullFloat32
}
Float32 is a nullable float32. Zero input will be considered null. JSON marshals to zero if null. Considered null to SQL if zero.
func Float32From ¶
Float32From creates a new Float32 that will be null if zero.
func Float32FromPtr ¶
Float32FromPtr creates a new Float32 that be null if f is nil.
func (Float32) IsZero ¶
IsZero returns true for null or zero Float32's, for future omitempty support (Go 1.4?)
func (Float32) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this Float32 is null.
func (Float32) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Float32 is null.
func (Float32) Ptr ¶
Ptr returns a poFloater to this Float32's value, or a nil poFloater if this Float32 is null.
func (*Float32) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Float32. It also supports unmarshalling a sql.NullFloat32.
func (*Float32) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Float32 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".
type Float64 ¶
type Float64 struct {
sql.NullFloat64
}
Float64 is a nullable float64. Zero input will be considered null. JSON marshals to zero if null. Considered null to SQL if zero.
func Float64From ¶
Float64From creates a new Float64 that will be null if zero.
func Float64FromPtr ¶
Float64FromPtr creates a new Float64 that be null if f is nil.
func (Float64) IsZero ¶
IsZero returns true for null or zero Float64's, for future omitempty support (Go 1.4?)
func (Float64) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this Float64 is null.
func (Float64) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Float64 is null.
func (Float64) Ptr ¶
Ptr returns a poFloater to this Float64's value, or a nil poFloater if this Float64 is null.
func (*Float64) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Float64. It also supports unmarshalling a sql.NullFloat64.
func (*Float64) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Float64 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".
type Int ¶
type Int struct {
NullInt
}
Int is a nullable int. JSON marshals to zero if null. Considered null to SQL if zero.
func IntFromPtr ¶
IntFromPtr creates a new Int that be null if i is nil.
func (Int) IsZero ¶
IsZero returns true for null or zero Ints, for future omitempty support (Go 1.4?)
func (Int) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Int is null.
func (Int) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Int is null.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Int. It also supports unmarshalling a sql.NullInt.
func (*Int) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int 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".
type Int16 ¶
type Int16 struct {
NullInt16
}
Int16 is a nullable int16. JSON marshals to zero if null. Considered null to SQL if zero.
func Int16FromPtr ¶
Int16FromPtr creates a new Int16 that be null if i is nil.
func (Int16) IsZero ¶
IsZero returns true for null or zero Int16s, for future omitempty support (Go 1.4?)
func (Int16) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Int16 is null.
func (Int16) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Int16 is null.
func (Int16) Ptr ¶
Ptr returns a pointer to this Int16's value, or a nil pointer if this Int16 is null.
func (*Int16) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Int16. It also supports unmarshalling a sql.NullInt16.
func (*Int16) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int16 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".
type Int32 ¶
type Int32 struct {
NullInt32
}
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 Int32s, for future omitempty support (Go 1.4?)
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) 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".
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 Int64s, for future omitempty support (Go 1.4?)
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) 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".
type Int8 ¶
type Int8 struct {
NullInt8
}
Int8 is a nullable int8. JSON marshals to zero if null. Considered null to SQL if zero.
func Int8FromPtr ¶
Int8FromPtr creates a new Int8 that be null if i is nil.
func (Int8) IsZero ¶
IsZero returns true for null or zero Int8s, for future omitempty support (Go 1.4?)
func (Int8) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Int8 is null.
func (Int8) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Int8 is null.
func (Int8) Ptr ¶
Ptr returns a pointer to this Int8's value, or a nil pointer if this Int8 is null.
func (*Int8) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Int8. It also supports unmarshalling a sql.NullInt8.
func (*Int8) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int8 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".
type JSON ¶
type JSON struct {
NullJSON
}
JSON is a nullable []byte. JSON marshals to zero if null. Considered null to SQL if zero.
func JSONFromPtr ¶
JSONFromPtr creates a new JSON that be null if len zero.
func (JSON) IsZero ¶
IsZero returns true for null or zero JSON's, for future omitempty support (Go 1.4?)
func (JSON) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if the JSON is nil.
func (JSON) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode nil if the JSON is invalid.
func (JSON) Ptr ¶
Ptr returns a pointer to this JSON's value, or a nil pointer if this JSON is null.
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. If data is len 0 or nil, it will unmarshal to JSON null. If not, it will copy your data slice into JSON.
func (*JSON) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to nil if the text is nil or len 0.
type NullBytes ¶
NullBytes is a nullable byte slice.
type NullFloat32 ¶
func (*NullFloat32) Scan ¶
func (n *NullFloat32) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullJSON ¶
NullJSON is a nullable byte slice.
type NullUint16 ¶
func (*NullUint16) Scan ¶
func (n *NullUint16) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullUint32 ¶
func (*NullUint32) Scan ¶
func (n *NullUint32) Scan(value interface{}) error
Scan implements the Scanner interface.
type NullUint64 ¶
NullUint64 is a replica of sql.NullInt64 for uint64 types.
func (*NullUint64) Scan ¶
func (n *NullUint64) Scan(value interface{}) error
Scan implements the Scanner 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) 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.
type Time ¶
Time is a nullable 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) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode the zero value of time.Time if this time is invalid.
func (Time) MarshalText ¶
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 ¶
type Uint ¶
type Uint struct {
NullUint
}
Uint is a nullable uint. JSON marshals to zero if null. Considered null to SQL if zero.
func UintFromPtr ¶
UintFromPtr creates a new Uint that be null if i is nil.
func (Uint) IsZero ¶
IsZero returns true for null or zero Uints, for future omitempty support (Go 1.4?)
func (Uint) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Uint is null.
func (Uint) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Uint is null.
func (Uint) Ptr ¶
Ptr returns a pointer to this Uint's value, or a nil pointer if this Uint is null.
func (*Uint) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Uint. It also supports unmarshalling a sql.NullUint.
func (*Uint) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Uint 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".
type Uint16 ¶
type Uint16 struct {
NullUint16
}
Uint16 is a nullable uint16. JSON marshals to zero if null. Considered null to SQL if zero.
func Uint16From ¶
Uint16From creates a new Uint16 that will be null if zero.
func Uint16FromPtr ¶
Uint16FromPtr creates a new Uint16 that be null if i is nil.
func (Uint16) IsZero ¶
IsZero returns true for null or zero Uint16s, for future omitempty support (Go 1.4?)
func (Uint16) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Uint16 is null.
func (Uint16) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Uint16 is null.
func (Uint16) Ptr ¶
Ptr returns a pointer to this Uint16's value, or a nil pointer if this Uint16 is null.
func (*Uint16) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Uint16. It also supports unmarshalling a sql.NullUint16.
func (*Uint16) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Uint16 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".
type Uint32 ¶
type Uint32 struct {
NullUint32
}
Uint32 is a nullable uint32. JSON marshals to zero if null. Considered null to SQL if zero.
func Uint32From ¶
Uint32From creates a new Uint32 that will be null if zero.
func Uint32FromPtr ¶
Uint32FromPtr creates a new Uint32 that be null if i is nil.
func (Uint32) IsZero ¶
IsZero returns true for null or zero Uint32s, for future omitempty support (Go 1.4?)
func (Uint32) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Uint32 is null.
func (Uint32) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Uint32 is null.
func (Uint32) Ptr ¶
Ptr returns a pointer to this Uint32's value, or a nil pointer if this Uint32 is null.
func (*Uint32) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Uint32. It also supports unmarshalling a sql.NullUint32.
func (*Uint32) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Uint32 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".
type Uint64 ¶
type Uint64 struct {
NullUint64
}
Uint64 is an nullable uint64. It does not consider zero values to be null. It will decode to null, not zero, if null.
func Uint64From ¶
Uint64From creates a new Uint64 that will be null if zero.
func Uint64FromPtr ¶
Uint64FromPtr creates a new Uint64 that be null if i is nil.
func (Uint64) IsZero ¶
IsZero returns true for null or zero Uint64s, for future omitempty support (Go 1.4?)
func (Uint64) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Uint64 is null.
func (Uint64) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Uint64 is null.
func (Uint64) Ptr ¶
Ptr returns a pointer to this Uint64's value, or a nil pointer if this Uint64 is null.
func (*Uint64) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Uint64. It also supports unmarshalling a sql.NullUint64.
func (*Uint64) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Uint64 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".
type Uint8 ¶
type Uint8 struct {
NullUint8
}
Uint8 is a nullable uint8. JSON marshals to zero if null. Considered null to SQL if zero.
func Uint8FromPtr ¶
Uint8FromPtr creates a new Uint8 that be null if i is nil.
func (Uint8) IsZero ¶
IsZero returns true for null or zero Uint8s, for future omitempty support (Go 1.4?)
func (Uint8) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Uint8 is null.
func (Uint8) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Uint8 is null.
func (Uint8) Ptr ¶
Ptr returns a pointer to this Uint8's value, or a nil pointer if this Uint8 is null.
func (*Uint8) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Uint8. It also supports unmarshalling a sql.NullUint8.
func (*Uint8) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Uint8 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".