Documentation ¶
Overview ¶
Package null implements nullable sql fields that are safely marshalable from/to json and text.
Each of the types defined within implement the `Stringer`, `sql.Scanner`, `json.Marshaller`, `json.Unmarshaller`, `encoding.TextMarshaller`, and `encoding.TextUnmarshaller“ interfaces. This makes them safe to use struct fields that can be saved and read from a database as well as from http json requests and parsed from string values. They can also be safely printed in a `fmt.Printf“
Where possible we try to alias and delegate known and well tested types, such as pd.NullTime and uuid.NullUUID. These types are provide more complete interfaces for our expected normal usage in Labs.
Index ¶
- type Time
- func (nt Time) Format(layout string) string
- func (nt Time) MarshalJSON() ([]byte, error)
- func (nt Time) MarshalText() ([]byte, error)
- func (nt *Time) Scan(value interface{}) error
- func (nt Time) String() string
- func (nt *Time) UnmarshalJSON(data []byte) error
- func (nt *Time) UnmarshalText(text []byte) error
- func (nt Time) Value() (driver.Value, error)
- type UUID
- func (nu UUID) MarshalBinary() ([]byte, error)
- func (nu UUID) MarshalJSON() ([]byte, error)
- func (nu UUID) MarshalText() ([]byte, error)
- func (nu *UUID) Scan(src interface{}) error
- func (nu UUID) String() string
- func (nu *UUID) UnmarshalBinary(data []byte) (err error)
- func (nu *UUID) UnmarshalJSON(data []byte) error
- func (nu *UUID) UnmarshalText(text []byte) error
- func (nu UUID) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Time ¶
Time represents a time.Time that may be null. Time implements the sql.Scanner interface so it can be used as a scan destination, similar to sql.NullString.
func (Time) Format ¶
Format returns a textual representation of the time value formatted according to layout. This is delegated to the time.Time object, see time.Time.Format for more details
func (Time) MarshalJSON ¶
MarshalJSON marshalls Time to the primitive value `null` or the RFC3339 string representation of the time value
func (Time) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports string and null input.
func (*Time) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type UUID ¶
type UUID uuid.NullUUID
UUID represents a uuid.UUID that may be null. UUID implements the sql.Scanner interface so it can be used as a scan destination, similar to sql.NullString. Addtionally, it implements the json.Marshaller, json.Unmarshaller, encoding.TextMarshaller, and encoding.TextUnmarshaller
func UUIDFromBytes ¶
UUIDFromBytes returns UUID converted from raw byte slice input. It will return error if the slice isn't 16 bytes long.
func UUIDFromString ¶
UUIDFromString returns UUID parsed from string input. Input is expected in a form accepted by UnmarshalText.
func (UUID) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (UUID) MarshalJSON ¶
MarshalJSON marshalls UUID to the primitive value `null` or the RFC3339 string representation of the time value
func (UUID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*UUID) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. It will return error if the slice isn't 16 bytes long.
func (*UUID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports string and null input.
func (*UUID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.