null

package
v2.8.3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Time

type Time pq.NullTime

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 Now

func Now() Time

Now returns the current local time as a null.Time

func TimeFrom

func TimeFrom(input time.Time) Time

TimeFrom returns a Time instance from a time.Time instance

func (Time) Format

func (nt Time) Format(layout string) string

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

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

MarshalJSON marshalls Time to the primitive value `null` or the RFC3339 string representation of the time value

func (Time) MarshalText

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

MarshalText implements the encoding.TextMarshaler interface.

func (*Time) Scan

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

Scan implements the sql.Scanner interface.

func (Time) String

func (nt Time) String() string

String implements the Stringer interface

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler. It supports string and null input.

func (*Time) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Time) Value

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

Value implements the driver Valuer 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 UUIDFrom

func UUIDFrom(input uuid.UUID) UUID

UUIDFrom returns UUID from a uuid.UUID

func UUIDFromBytes

func UUIDFromBytes(input []byte) (u UUID, err error)

UUIDFromBytes returns UUID converted from raw byte slice input. It will return error if the slice isn't 16 bytes long.

func UUIDFromString

func UUIDFromString(input string) (u UUID, err error)

UUIDFromString returns UUID parsed from string input. Input is expected in a form accepted by UnmarshalText.

func (UUID) MarshalBinary

func (nu UUID) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (UUID) MarshalJSON

func (nu UUID) MarshalJSON() ([]byte, error)

MarshalJSON marshalls UUID to the primitive value `null` or the RFC3339 string representation of the time value

func (UUID) MarshalText

func (nu UUID) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*UUID) Scan

func (nu *UUID) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (UUID) String

func (nu UUID) String() string

String implements the Stringer interface

func (*UUID) UnmarshalBinary

func (nu *UUID) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. It will return error if the slice isn't 16 bytes long.

func (*UUID) UnmarshalJSON

func (nu *UUID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports string and null input.

func (*UUID) UnmarshalText

func (nu *UUID) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (UUID) Value

func (nu UUID) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

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