null

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 9 Imported by: 0

README

null

Go Report Card GoDoc

Package null is a simple package for dealing with nullable SQL and JSON values.

type User struct {
	ID          int64        `json:"id"`
	CountryID   null.Int64   `json:"country_id"`
	LocaleID    int64        `json:"locale_id"`
	Email       string       `json:"email"`
	Phone       null.String  `json:"phone"`
	Rating      null.Float64 `json:"rating"`
	IsTrial     bool         `json:"is_trial"`
	IsActivated null.Bool    `json:"is_activated"`
	Timezone    string       `json:"timezone"`
	CreatedAt   time.Time    `json:"created_at"`
	DeletedAt   null.Time    `json:"deleted_at"`
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NullBytes = []byte("null")

NullBytes is a byte slice of JSON null

Functions

This section is empty.

Types

type Bool

type Bool struct {
	sql.NullBool
}

Bool is a nullable bool. Bool provides SQL and JSON serialization.

func BoolFrom

func BoolFrom(b bool) Bool

BoolFrom creates a new valid Bool from raw bool.

func NewBool

func NewBool(b bool, v bool) Bool

NewBool creates a new Bool

func (Bool) IsSet

func (e Bool) IsSet() bool

IsSet returns true for valid value.

func (Bool) IsSetZero added in v0.2.0

func (e Bool) IsSetZero() bool

IsSetZero returns true if value is set to zero.

func (Bool) IsZero

func (e Bool) IsZero() bool

IsZero returns true for zero value.

func (Bool) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Bool) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (*Bool) UnmarshalJSON

func (e *Bool) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

func (*Bool) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

type Bytes added in v0.3.0

type Bytes struct {
	Bytes []byte
	Valid bool
}

Bytes is a nullable string. Bytes provides SQL and JSON serialization.

func BytesFrom added in v0.3.0

func BytesFrom(b []byte) Bytes

BytesFrom creates a new valid Bytes from []byte.

func NewBytes added in v0.3.0

func NewBytes(b []byte, v bool) Bytes

NewBytes creates a new Bytes

func (Bytes) IsSet added in v0.3.0

func (e Bytes) IsSet() bool

IsSet returns true for valid value.

func (Bytes) IsSetZero added in v0.3.0

func (e Bytes) IsSetZero() bool

IsSetZero returns true if value is set to zero.

func (Bytes) IsZero added in v0.3.0

func (e Bytes) IsZero() bool

IsZero returns true for zero value.

func (Bytes) MarshalJSON added in v0.3.0

func (e Bytes) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Bytes) MarshalText added in v0.3.0

func (e Bytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Bytes) Scan added in v0.3.0

func (e *Bytes) Scan(value interface{}) error

Scan implements sql.Scanner interface.

func (*Bytes) UnmarshalJSON added in v0.3.0

func (e *Bytes) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

func (*Bytes) UnmarshalText added in v0.3.0

func (e *Bytes) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Bytes) Value added in v0.3.0

func (e Bytes) Value() (driver.Value, error)

Value implements driver.Valuer interface.

type Float64

type Float64 struct {
	sql.NullFloat64
}

Float64 is a nullable float64. Float64 provides SQL and JSON serialization.

func Float64From

func Float64From(f float64) Float64

Float64From creates a new valid Float64 from raw float64.

func NewFloat64

func NewFloat64(f float64, v bool) Float64

NewFloat64 creates a new Float64

func (Float64) IsSet

func (e Float64) IsSet() bool

IsSet returns true for valid value.

func (Float64) IsSetZero added in v0.2.0

func (e Float64) IsSetZero() bool

IsSetZero returns true if value is set to zero.

func (Float64) IsZero

func (e Float64) IsZero() bool

IsZero returns true for zero value.

func (Float64) MarshalJSON

func (e Float64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Float64) MarshalText

func (e Float64) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Float64) UnmarshalJSON

func (e *Float64) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

func (*Float64) UnmarshalText

func (e *Float64) UnmarshalText(text []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler.

type Int64

type Int64 struct {
	sql.NullInt64
}

Int64 is a nullable int64. Int64 provides SQL and JSON serialization.

func Int64From

func Int64From(i int64) Int64

Int64From creates a new valid Int64 from raw int64.

func NewInt64

func NewInt64(i int64, v bool) Int64

NewInt64 creates a new Int64

func (Int64) IsSet

func (e Int64) IsSet() bool

IsSet returns true for valid value.

func (Int64) IsSetZero added in v0.2.0

func (e Int64) IsSetZero() bool

IsSetZero returns true if value is set to zero.

func (Int64) IsZero

func (e Int64) IsZero() bool

IsZero returns true for zero value.

func (Int64) MarshalJSON

func (e Int64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Int64) MarshalText

func (e Int64) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Int64) UnmarshalJSON

func (e *Int64) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

func (*Int64) UnmarshalText

func (e *Int64) UnmarshalText(text []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler.

type String

type String struct {
	sql.NullString
}

String is a nullable string. String provides SQL and JSON serialization.

func NewString

func NewString(s string, v bool) String

NewString creates a new String

func StringFrom

func StringFrom(s string) String

StringFrom creates a new valid String from raw string.

func (String) IsSet

func (e String) IsSet() bool

IsSet returns true for valid value.

func (String) IsSetZero added in v0.2.0

func (e String) IsSetZero() bool

IsSetZero returns true if value is set to zero.

func (String) IsZero

func (e String) IsZero() bool

IsZero returns true for zero value.

func (String) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (String) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (*String) UnmarshalJSON

func (e *String) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

func (*String) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

type Time

type Time struct {
	sql.NullTime
}

Time is a nullable string. Time provides SQL and JSON serialization.

func NewTime

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

NewTime creates a new Time

func TimeFrom

func TimeFrom(t time.Time) Time

TimeFrom creates a new valid Time from raw time.Time.

func (Time) IsSet

func (e Time) IsSet() bool

IsSet returns true for valid value.

func (Time) IsSetZero added in v0.2.0

func (e Time) IsSetZero() bool

IsSetZero returns true if value is set to zero.

func (Time) IsZero

func (e Time) IsZero() bool

IsZero returns true for zero value.

func (Time) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Time) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (*Time) UnmarshalJSON

func (e *Time) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Unmarshaler.

func (*Time) UnmarshalText

func (e *Time) UnmarshalText(text []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler.

Jump to

Keyboard shortcuts

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