null.v3: gopkg.in/guregu/null.v3 Index | Files | Directories

package null

import "gopkg.in/guregu/null.v3"

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

Package Files

bool.go float.go int.go string.go time.go

type Bool Uses

type Bool struct {
    sql.NullBool
}

Bool is a nullable bool. It does not consider false values to be null. It will decode to null, not false, if null.

func BoolFrom Uses

func BoolFrom(b bool) Bool

BoolFrom creates a new Bool that will always be valid.

func BoolFromPtr Uses

func BoolFromPtr(b *bool) Bool

BoolFromPtr creates a new Bool that will be null if f is nil.

func NewBool Uses

func NewBool(b bool, valid bool) Bool

NewBool creates a new Bool

func (Bool) IsZero Uses

func (b Bool) IsZero() bool

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 Uses

func (b Bool) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this Bool is null.

func (Bool) MarshalText Uses

func (b Bool) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Bool is null.

func (Bool) Ptr Uses

func (b Bool) Ptr() *bool

Ptr returns a pointer to this Bool's value, or a nil pointer if this Bool is null.

func (*Bool) SetValid Uses

func (b *Bool) SetValid(v bool)

SetValid changes this Bool's value and also sets it to be non-null.

func (*Bool) UnmarshalJSON Uses

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Bool. It also supports unmarshalling a sql.NullBool.

func (*Bool) UnmarshalText Uses

func (b *Bool) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Bool if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or "null".

func (Bool) ValueOrZero Uses

func (b Bool) ValueOrZero() bool

ValueOrZero returns the inner value if valid, otherwise false.

type Float Uses

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 FloatFrom Uses

func FloatFrom(f float64) Float

FloatFrom creates a new Float that will always be valid.

func FloatFromPtr Uses

func FloatFromPtr(f *float64) Float

FloatFromPtr creates a new Float that be null if f is nil.

func NewFloat Uses

func NewFloat(f float64, valid bool) Float

NewFloat creates a new Float

func (Float) IsZero Uses

func (f Float) IsZero() bool

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 Uses

func (f Float) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this Float is null.

func (Float) MarshalText Uses

func (f Float) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Float is null.

func (Float) Ptr Uses

func (f Float) Ptr() *float64

Ptr returns a pointer to this Float's value, or a nil pointer if this Float is null.

func (*Float) SetValid Uses

func (f *Float) SetValid(n float64)

SetValid changes this Float's value and also sets it to be non-null.

func (*Float) UnmarshalJSON Uses

func (f *Float) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Float. It also supports unmarshalling a sql.NullFloat64.

func (*Float) UnmarshalText Uses

func (f *Float) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Float if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or "null".

func (Float) ValueOrZero Uses

func (f Float) ValueOrZero() float64

ValueOrZero returns the inner value if valid, otherwise zero.

type Int Uses

type Int struct {
    sql.NullInt64
}

Int is an nullable int64. It does not consider zero values to be null. It will decode to null, not zero, if null.

func IntFrom Uses

func IntFrom(i int64) Int

IntFrom creates a new Int that will always be valid.

func IntFromPtr Uses

func IntFromPtr(i *int64) Int

IntFromPtr creates a new Int that be null if i is nil.

func NewInt Uses

func NewInt(i int64, valid bool) Int

NewInt creates a new Int

func (Int) IsZero Uses

func (i Int) IsZero() bool

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 Uses

func (i Int) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this Int is null.

func (Int) MarshalText Uses

func (i Int) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Int is null.

func (Int) Ptr Uses

func (i Int) Ptr() *int64

Ptr returns a pointer to this Int's value, or a nil pointer if this Int is null.

func (*Int) SetValid Uses

func (i *Int) SetValid(n int64)

SetValid changes this Int's value and also sets it to be non-null.

func (*Int) UnmarshalJSON Uses

func (i *Int) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Int. It also supports unmarshalling a sql.NullInt64.

func (*Int) UnmarshalText Uses

func (i *Int) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or "null".

func (Int) ValueOrZero Uses

func (i Int) ValueOrZero() int64

ValueOrZero returns the inner value if valid, otherwise zero.

type String Uses

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 NewString Uses

func NewString(s string, valid bool) String

NewString creates a new String

func StringFrom Uses

func StringFrom(s string) String

StringFrom creates a new String that will never be blank.

func StringFromPtr Uses

func StringFromPtr(s *string) String

StringFromPtr creates a new String that be null if s is nil.

func (String) IsZero Uses

func (s String) IsZero() bool

IsZero returns true for null strings, for potential future omitempty support.

func (String) MarshalJSON Uses

func (s String) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this String is null.

func (String) MarshalText Uses

func (s String) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string when this String is null.

func (String) Ptr Uses

func (s String) Ptr() *string

Ptr returns a pointer to this String's value, or a nil pointer if this String is null.

func (*String) SetValid Uses

func (s *String) SetValid(v string)

SetValid changes this String's value and also sets it to be non-null.

func (*String) UnmarshalJSON Uses

func (s *String) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports string and null input. Blank string input does not produce a null String. It also supports unmarshalling a sql.NullString.

func (*String) UnmarshalText Uses

func (s *String) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null String if the input is a blank string.

func (String) ValueOrZero Uses

func (s String) ValueOrZero() string

ValueOrZero returns the inner value if valid, otherwise zero.

type Time Uses

type Time struct {
    Time  time.Time
    Valid bool
}

Time is a nullable time.Time. It supports SQL and JSON serialization. It will marshal to null if null.

func NewTime Uses

func NewTime(t time.Time, valid bool) Time

NewTime creates a new Time.

func TimeFrom Uses

func TimeFrom(t time.Time) Time

TimeFrom creates a new Time that will always be valid.

func TimeFromPtr Uses

func TimeFromPtr(t *time.Time) Time

TimeFromPtr creates a new Time that will be null if t is nil.

func (Time) MarshalJSON Uses

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this time is null.

func (Time) MarshalText Uses

func (t Time) MarshalText() ([]byte, error)

func (Time) Ptr Uses

func (t Time) Ptr() *time.Time

Ptr returns a pointer to this Time's value, or a nil pointer if this Time is null.

func (*Time) Scan Uses

func (t *Time) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Time) SetValid Uses

func (t *Time) SetValid(v time.Time)

SetValid changes this Time's value and sets it to be non-null.

func (*Time) UnmarshalJSON Uses

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports string, object (e.g. pq.NullTime and friends) and null input.

func (*Time) UnmarshalText Uses

func (t *Time) UnmarshalText(text []byte) error

func (Time) Value Uses

func (t Time) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Time) ValueOrZero Uses

func (t Time) ValueOrZero() time.Time

ValueOrZero returns the inner value if valid, otherwise zero.

Directories

PathSynopsis
zeroPackage zero contains SQL types that consider zero input and null input to be equivalent with convenient support for JSON and text marshaling.

Package null imports 9 packages (graph) and is imported by 69 packages. Updated 2018-03-03. Refresh now. Tools for package owners.