null

package
v1.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2022 License: BSD-2-Clause-Patent Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

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 (Bool) IsZero

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) UnmarshalJSON

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.

type Int

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 (Int) IsZero

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) UnmarshalJSON

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.

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 (String) IsZero

func (s String) IsZero() bool

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

func (*String) UnmarshalJSON

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.

type Time added in v1.14.1

type Time struct {
	Time  time.Time
	Valid bool
}

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 NewTime added in v1.16.0

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

NewTime creates a new Time.

func TimeFrom added in v1.16.0

func TimeFrom(t time.Time) Time

TimeFrom creates a new Time that will always be valid.

func (Time) IsZero added in v1.14.1

func (t Time) IsZero() bool

IsZero returns true for null or zero Times, for potential future omitempty support.

func (Time) MarshalJSON added in v1.14.1

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

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

func (Time) Ptr added in v1.16.0

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

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

func (*Time) UnmarshalJSON added in v1.14.1

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) ValueOrZero added in v1.14.1

func (t Time) ValueOrZero() time.Time

ValueOrZero returns the inner value if valid, otherwise zero.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL