null

package
v3.2.22 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

README

null GoDoc Coverage

null is a library with reasonable options for dealing with nullable SQL and JSON values.

Types in null will only be considered null on null input, and will JSON encode to null.

All types implement sql.Scanner and driver.Valuer, so you can use this library in place of sql.NullXXX. All types also implement: encoding.TextMarshaler, encoding.TextUnmarshaler, json.Marshaler, json.Unmarshaler and sql.Scanner.


Installation

Null installation, ensure you're using go modules.

go get github.com/mbahjadol/null

Usage

The following are all types supported in this package. All types will marshal to JSON null if Invalid or SQL source data is null.

Type Description Notes
null.Date Nullable time.Time That accept only full-year, month, date and ignore elses. Marshals to JSON null if SQL source data is null. Uses customize time.Time's json & text marshaler that support format with YYYY-MM-DD.
null.CTime Nullable time.Time That accept only hour, minute, second and ignore elses. Marshals to JSON null if SQL source data is null. Uses customize time.Time's json & text marshaler that support format with hh:mm:ss . It is use name CTime (Customize Time) to differentiate null.Time and partially support for RFC3339 only time
null.DateTime Nullable time.Time That accept full-year,month,date,hour,minute,second and ignore elses. Marshals to JSON null if SQL source data is null. Uses customize time.Time's json & text marshaler that support format with YYYY-MM-DD hh:mm:ss
null.TimeStamp Nullable time.Time That accept full-year,month,date,hour,minute,second and microsecond. Marshals to JSON null if SQL source data is null. Uses customize time.Time's json & text marshaler that support format with YYYY-MM-DD hh:mm:ss.zzzzzz
null.Time Nullable time.Time Marshals to JSON null if SQL source data is null. Uses time.Time's marshaler. It marshall json with RFC3339.
null.JSON Nullable []byte Will marshal to JSON null if Invalid. []byte{} input will not produce an Invalid JSON, but []byte(nil) will. This should be used for storing raw JSON in the database. Also has null.JSON.Marshal and null.JSON.Unmarshal helpers to marshal and unmarshal foreign objects.
null.Bytes Nullable []byte []byte{} input will not produce an Invalid Bytes, but []byte(nil) will. This should be used for storing binary data (bytes in PSQL for example) in the database.
null.String Nullable string
null.Byte Nullable byte
null.Bool Nullable bool
null.Float32 Nullable float32
null.Float64 Nullable float64
null.Int Nullable int
null.Int8 Nullable int8
null.Int16 Nullable int16
null.Int32 Nullable int32
null.Int64 Nullable int64
null.Uint Nullable uint
null.Uint8 Nullable uint8
null.Uint16 Nullable uint16
null.Uint32 Nullable uint32
null.Uint64 Nullable uint64

Bugs

json's ",omitempty" struct tag does not work correctly right now. It will never omit a null or empty String. This might be fixed eventually.

License

BSD-3 (See License file)

Documentation

Index

Constants

View Source
const (
	RFC3339DateOnly = "2006-01-02"
	RFC3339TimeOnly = "15:04:05"
	DateTimeSQL     = "2006-01-02 15:04:05"
	TimeStampSQL    = "2006-01-02 15:04:05.000000"
)

Variables

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

NullBytes is a global byte slice of JSON null

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Bool  bool
	Valid bool
	Set   bool
}

Bool is a nullable bool.

func BoolFrom

func BoolFrom(b bool) Bool

BoolFrom creates a new Bool that will always be valid.

func BoolFromPtr

func BoolFromPtr(b *bool) Bool

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

func NewBool

func NewBool(b, valid bool) Bool

NewBool creates a new Bool

func (Bool) IsSet

func (b Bool) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Bool) IsValid

func (b Bool) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Bool) IsZero

func (b Bool) IsZero() bool

IsZero returns true for invalid Bools, for future omitempty support (Go 1.4?)

func (Bool) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Bool) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Bool) Ptr

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

func (t Bool) Result() string

Result returns the string representation of the float or null.

func (*Bool) Scan

func (b *Bool) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Bool) SetValid

func (b *Bool) SetValid(v bool)

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

func (*Bool) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Bool) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Bool) Value

func (b Bool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Bool) ValueOrDefault

func (t Bool) ValueOrDefault() bool

ValueOrDefault returns the inner value if valid, otherwise default.

type Byte

type Byte struct {
	Byte  byte
	Valid bool
	Set   bool
}

Byte is an nullable int.

func ByteFrom

func ByteFrom(b byte) Byte

ByteFrom creates a new Byte that will always be valid.

func ByteFromPtr

func ByteFromPtr(b *byte) Byte

ByteFromPtr creates a new Byte that be null if i is nil.

func NewByte

func NewByte(b byte, valid bool) Byte

NewByte creates a new Byte

func (Byte) IsSet

func (b Byte) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Byte) IsValid

func (b Byte) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Byte) IsZero

func (b Byte) IsZero() bool

IsZero returns true for invalid Bytes, for future omitempty support (Go 1.4?)

func (Byte) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Byte) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Byte) Ptr

func (b Byte) Ptr() *byte

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

func (Byte) Result

func (t Byte) Result() string

String returns the string representation of the float or null.

func (*Byte) Scan

func (b *Byte) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Byte) SetValid

func (b *Byte) SetValid(n byte)

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

func (*Byte) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Byte) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Byte) Value

func (b Byte) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Byte) ValueOrDefault

func (t Byte) ValueOrDefault() byte

ValueOrDefault returns the inner value if valid, otherwise default.

type Bytes

type Bytes struct {
	Bytes []byte
	Valid bool
	Set   bool
}

Bytes is a nullable []byte.

func BytesFrom

func BytesFrom(b []byte) Bytes

BytesFrom creates a new Bytes that will be invalid if nil.

func BytesFromPtr

func BytesFromPtr(b *[]byte) Bytes

BytesFromPtr creates a new Bytes that will be invalid if nil.

func NewBytes

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

NewBytes creates a new Bytes

func (Bytes) IsSet

func (b Bytes) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Bytes) IsValid

func (b Bytes) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Bytes) IsZero

func (b Bytes) IsZero() bool

IsZero returns true for null or zero Bytes's, for future omitempty support (Go 1.4?)

func (Bytes) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Bytes) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Bytes) Ptr

func (b Bytes) Ptr() *[]byte

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

func (Bytes) Result

func (t Bytes) Result() string

String returns the string representation of the float or null.

func (*Bytes) Scan

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

Scan implements the Scanner interface.

func (*Bytes) SetValid

func (b *Bytes) SetValid(n []byte)

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

func (*Bytes) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Bytes) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Bytes) Value

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

Value implements the driver Valuer interface.

func (Bytes) ValueOrDefault

func (t Bytes) ValueOrDefault() []byte

ValueOrDefault returns the inner value if valid, otherwise default.

type CTime

type CTime struct {
	CTime time.Time
	Valid bool
	Set   bool
}

CTime (Customize Time) is a nullable time.Time that accept only hour,minutes,seconds and ignore elses. When it is serialize to JSON and vice versa only accept of front half RFC 3339 ([2 digit hour]:[2 digit minutes]:[2 digit seconds]). It supports SQL and JSON serialization.

func CTimeFrom

func CTimeFrom(t time.Time) CTime

CTimeFrom creates a new CTime that will always be valid.

func CTimeFromPtr

func CTimeFromPtr(t *time.Time) CTime

CTimeFromPtr creates a new CTime that will be null if t is nil.

func NewCTime

func NewCTime(t time.Time, valid bool) CTime

NewCTime creates a new Time. that accept only hour,minutes,seconds and ignore elses.

func (CTime) IsSet

func (t CTime) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (CTime) IsValid

func (t CTime) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (CTime) IsZero

func (t CTime) IsZero() bool

IsZero returns true for an invalid Time's value, for potential future omitempty support.

func (CTime) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (CTime) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (CTime) Ptr

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

Ptr returns a pointer to this Time's value that accept only hour,minutes,seconds and ignore elses. , or a nil pointer if this Time is null.

func (CTime) Result

func (t CTime) Result() string

String returns the string representation of the float or null.

func (*CTime) Scan

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

Scan implements the Scanner interface. that accept only hour,minutes,seconds and ignore elses.

func (*CTime) SetValid

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

SetValid changes this Time's value that accept only hour,minutes,seconds and ignore elses. and sets it to be non-null.

func (*CTime) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*CTime) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (CTime) Value

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

Value implements the driver Valuer interface.

func (CTime) ValueOrDefault

func (t CTime) ValueOrDefault() time.Time

ValueOrDefault returns the inner value if valid, otherwise default.

type Date

type Date struct {
	Date  time.Time
	Valid bool
	Set   bool
}

Date is a nullable time.Time that accept only fullyear,month,date and ignore elses. When it is serialize to JSON and vice versa only accept of front half RFC 3339 ([4 digit year]-[2 digit month]-[2 digit year]). It supports SQL and JSON serialization.

func DateFrom

func DateFrom(t time.Time) Date

DateFrom creates a new Date that will always be valid.

func DateFromPtr

func DateFromPtr(t *time.Time) Date

DateFromPtr creates a new Date that will be null if t is nil.

func NewDate

func NewDate(t time.Time, valid bool) Date

NewDate creates a new Time. that accept only fullyear,month,date and ignore elses.

func (Date) IsSet

func (t Date) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Date) IsValid

func (t Date) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Date) IsZero

func (t Date) IsZero() bool

IsZero returns true for an invalid Time's value, for potential future omitempty support.

func (Date) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Date) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Date) Ptr

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

Ptr returns a pointer to this Time's value that accept only fullyear,month,date and ignore elses. , or a nil pointer if this Time is null.

func (Date) Result

func (t Date) Result() string

String returns the string representation of the float or null.

func (*Date) Scan

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

Scan implements the Scanner interface. that accept only fullyear,month,date and ignore elses.

func (*Date) SetValid

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

SetValid changes this Time's value that accept only fullyear,month,date and ignore elses. and sets it to be non-null.

func (*Date) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Date) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Date) Value

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

Value implements the driver Valuer interface.

func (Date) ValueOrDefault

func (t Date) ValueOrDefault() time.Time

ValueOrDefault returns the inner value if valid, otherwise default.

type DateTime

type DateTime struct {
	DateTime time.Time
	Valid    bool
	Set      bool
}

DateTime is a nullable time.Time that accept only fullyear,month,date,hour,minute,second and ignore elses. When it is serialize to JSON and vice versa only accept of SQL DateTime Format YYYY-MM-DD hh:mm:ss ([4 digit year]-[2 digit month]-[2 digit year] [2 digit hour]:[2 digit minute][2 digit second]). It supports SQL and JSON serialization.

func DateTimeFrom

func DateTimeFrom(t time.Time) DateTime

DateTimeFrom creates a new DateTime that will always be valid.

func DateTimeFromPtr

func DateTimeFromPtr(t *time.Time) DateTime

DateTimeFromPtr creates a new DateTime that will be null if t is nil.

func NewDateTime

func NewDateTime(t time.Time, valid bool) DateTime

NewDateTime creates a new Time. that accept only fullyear,month,date,hour,minute,second and ignore elses.

func (DateTime) IsSet

func (t DateTime) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (DateTime) IsValid

func (t DateTime) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (DateTime) IsZero

func (t DateTime) IsZero() bool

IsZero returns true for an invalid Time's value, for potential future omitempty support.

func (DateTime) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (DateTime) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (DateTime) Ptr

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

Ptr returns a pointer to this Time's value that accept only fullyear,month,date and ignore elses. , or a nil pointer if this Time is null.

func (DateTime) Result

func (t DateTime) Result() string

String returns the string representation of the float or null.

func (*DateTime) Scan

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

Scan implements the Scanner interface. that accept only fullyear,month,date and ignore elses.

func (*DateTime) SetValid

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

SetValid changes this Time's value that accept only fullyear,month,date and ignore elses. and sets it to be non-null.

func (*DateTime) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*DateTime) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (DateTime) Value

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

Value implements the driver Valuer interface.

func (DateTime) ValueOrDefault

func (t DateTime) ValueOrDefault() time.Time

ValueOrDefault returns the inner value if valid, otherwise default.

type Float32

type Float32 struct {
	Float32 float32
	Valid   bool
	Set     bool
}

Float32 is a nullable float32.

func Float32From

func Float32From(f float32) Float32

Float32From creates a new Float32 that will always be valid.

func Float32FromPtr

func Float32FromPtr(f *float32) Float32

Float32FromPtr creates a new Float32 that be null if f is nil.

func NewFloat32

func NewFloat32(f float32, valid bool) Float32

NewFloat32 creates a new Float32

func (Float32) IsSet

func (f Float32) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Float32) IsValid

func (f Float32) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Float32) IsZero

func (f Float32) IsZero() bool

IsZero returns true for invalid Float32s, for future omitempty support (Go 1.4?)

func (Float32) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Float32) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Float32) Ptr

func (f Float32) Ptr() *float32

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

func (Float32) Result

func (a Float32) Result() string

String returns the string representation of the float or null.

func (*Float32) Scan

func (f *Float32) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Float32) SetValid

func (f *Float32) SetValid(n float32)

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

func (*Float32) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Float32) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Float32) Value

func (f Float32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Float32) ValueOrDefault

func (t Float32) ValueOrDefault() float32

ValueOrDefault returns the inner value if valid, otherwise zero.

type Float64

type Float64 struct {
	Float64 float64
	Valid   bool
	Set     bool
}

Float64 is a nullable float64.

func Float64From

func Float64From(f float64) Float64

Float64From creates a new Float64 that will always be valid.

func Float64FromPtr

func Float64FromPtr(f *float64) Float64

Float64FromPtr creates a new Float64 that be null if f is nil.

func NewFloat64

func NewFloat64(f float64, valid bool) Float64

NewFloat64 creates a new Float64

func (Float64) IsSet

func (f Float64) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Float64) IsValid

func (f Float64) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Float64) IsZero

func (f Float64) IsZero() bool

IsZero returns true for invalid Float64s, for future omitempty support (Go 1.4?)

func (Float64) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Float64) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Float64) Ptr

func (f Float64) Ptr() *float64

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

func (Float64) Result

func (a Float64) Result() string

String returns the string representation of the float or null.

func (*Float64) Scan

func (f *Float64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Float64) SetValid

func (f *Float64) SetValid(n float64)

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

func (*Float64) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Float64) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Float64) Value

func (f Float64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Float64) ValueOrDefault

func (t Float64) ValueOrDefault() float64

ValueOrDefault returns the inner value if valid, otherwise zero.

type Int

type Int struct {
	Int   int
	Valid bool
	Set   bool
}

Int is an nullable int.

func IntFrom

func IntFrom(i int) Int

IntFrom creates a new Int that will always be valid.

func IntFromPtr

func IntFromPtr(i *int) Int

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

func NewInt

func NewInt(i int, valid bool) Int

NewInt creates a new Int

func (Int) IsSet

func (i Int) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Int) IsValid

func (i Int) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Int) IsZero

func (i Int) IsZero() bool

IsZero returns true for invalid Ints, for future omitempty support (Go 1.4?)

func (Int) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Int) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Int) Ptr

func (i Int) Ptr() *int

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

func (Int) Result

func (a Int) Result() string

String returns the string representation of the float or null.

func (*Int) Scan

func (i *Int) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Int) SetValid

func (i *Int) SetValid(n int)

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

func (*Int) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Int) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Int) Value

func (i Int) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Int) ValueOrDefault

func (i Int) ValueOrDefault() int

ValueOrDefault returns the inner value if valid, otherwise default.

type Int16

type Int16 struct {
	Int16 int16
	Valid bool
	Set   bool
}

Int16 is an nullable int16.

func Int16From

func Int16From(i int16) Int16

Int16From creates a new Int16 that will always be valid.

func Int16FromPtr

func Int16FromPtr(i *int16) Int16

Int16FromPtr creates a new Int16 that be null if i is nil.

func NewInt16

func NewInt16(i int16, valid bool) Int16

NewInt16 creates a new Int16

func (Int16) IsSet

func (i Int16) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Int16) IsValid

func (i Int16) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Int16) IsZero

func (i Int16) IsZero() bool

IsZero returns true for invalid Int16's, for future omitempty support (Go 1.4?)

func (Int16) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Int16) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Int16) Ptr

func (i Int16) Ptr() *int16

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

func (Int16) Result

func (a Int16) Result() string

String returns the string representation of the int or null.

func (*Int16) Scan

func (i *Int16) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Int16) SetValid

func (i *Int16) SetValid(n int16)

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

func (*Int16) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Int16) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Int16) Value

func (i Int16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Int16) ValueOrDefault

func (i Int16) ValueOrDefault() int16

ValueOrDefault returns the inner value if valid, otherwise default.

type Int32

type Int32 struct {
	Int32 int32
	Valid bool
	Set   bool
}

Int32 is an nullable int32.

func Int32From

func Int32From(i int32) Int32

Int32From creates a new Int32 that will always be valid.

func Int32FromPtr

func Int32FromPtr(i *int32) Int32

Int32FromPtr creates a new Int32 that be null if i is nil.

func NewInt32

func NewInt32(i int32, valid bool) Int32

NewInt32 creates a new Int32

func (Int32) IsSet

func (i Int32) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Int32) IsValid

func (i Int32) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Int32) IsZero

func (i Int32) IsZero() bool

IsZero returns true for invalid Int32's, for future omitempty support (Go 1.4?)

func (Int32) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Int32) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Int32) Ptr

func (i Int32) Ptr() *int32

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

func (Int32) Result

func (a Int32) Result() string

String returns the string representation of the int or null.

func (*Int32) Scan

func (i *Int32) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Int32) SetValid

func (i *Int32) SetValid(n int32)

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

func (*Int32) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Int32) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Int32) Value

func (i Int32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Int32) ValueOrDefault

func (i Int32) ValueOrDefault() int32

ValueOrDefault returns the inner value if valid, otherwise default.

type Int64

type Int64 struct {
	Int64 int64
	Valid bool
	Set   bool
}

Int64 is an nullable int64.

func Int64From

func Int64From(i int64) Int64

Int64From creates a new Int64 that will always be valid.

func Int64FromPtr

func Int64FromPtr(i *int64) Int64

Int64FromPtr creates a new Int64 that be null if i is nil.

func NewInt64

func NewInt64(i int64, valid bool) Int64

NewInt64 creates a new Int64

func (Int64) IsSet

func (i Int64) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Int64) IsValid

func (i Int64) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Int64) IsZero

func (i Int64) IsZero() bool

IsZero returns true for invalid Int64's, for future omitempty support (Go 1.4?)

func (Int64) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Int64) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Int64) Ptr

func (i Int64) Ptr() *int64

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

func (Int64) Result

func (a Int64) Result() string

String returns the string representation of the int or null.

func (*Int64) Scan

func (i *Int64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Int64) SetValid

func (i *Int64) SetValid(n int64)

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

func (*Int64) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Int64) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Int64) Value

func (i Int64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Int64) ValueOrDefault

func (i Int64) ValueOrDefault() int64

ValueOrDefault returns the inner value if valid, otherwise default.

type Int8

type Int8 struct {
	Int8  int8
	Valid bool
	Set   bool
}

Int8 is an nullable int8.

func Int8From

func Int8From(i int8) Int8

Int8From creates a new Int8 that will always be valid.

func Int8FromPtr

func Int8FromPtr(i *int8) Int8

Int8FromPtr creates a new Int8 that be null if i is nil.

func NewInt8

func NewInt8(i int8, valid bool) Int8

NewInt8 creates a new Int8

func (Int8) IsSet

func (i Int8) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Int8) IsValid

func (i Int8) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Int8) IsZero

func (i Int8) IsZero() bool

IsZero returns true for invalid Int8's, for future omitempty support (Go 1.4?)

func (Int8) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Int8) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Int8) Ptr

func (i Int8) Ptr() *int8

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

func (Int8) Result

func (a Int8) Result() string

String returns the string representation of the int or null.

func (*Int8) Scan

func (i *Int8) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Int8) SetValid

func (i *Int8) SetValid(n int8)

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

func (*Int8) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Int8) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Int8) Value

func (i Int8) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Int8) ValueOrDefault

func (i Int8) ValueOrDefault() int8

ValueOrDefault returns the inner value if valid, otherwise default.

type JSON

type JSON struct {
	JSON  []byte
	Valid bool
	Set   bool
}

JSON is a nullable []byte that contains JSON.

You might want to use this in the case where you have say a nullable JSON column in postgres for instance, where there is one layer of null for the postgres column, and then you also have the opportunity to have null as a value contained in the json. When unmarshalling json however you cannot set 'null' as a value.

func JSONFrom

func JSONFrom(b []byte) JSON

JSONFrom creates a new JSON that will be invalid if nil.

func JSONFromPtr

func JSONFromPtr(b *[]byte) JSON

JSONFromPtr creates a new JSON that will be invalid if nil.

func NewJSON

func NewJSON(b []byte, valid bool) JSON

NewJSON creates a new JSON

func (JSON) IsSet

func (j JSON) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (JSON) IsValid

func (j JSON) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (JSON) IsZero

func (j JSON) IsZero() bool

IsZero returns true for null or zero JSON's, for future omitempty support (Go 1.4?)

func (*JSON) Marshal

func (j *JSON) Marshal(obj interface{}) error

Marshal will marshal the passed in object, and store it in the JSON member on the JSON object.

func (JSON) MarshalJSON

func (j JSON) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (JSON) MarshalText

func (j JSON) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (JSON) Ptr

func (j JSON) Ptr() *[]byte

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

func (JSON) Result

func (t JSON) Result() string

String returns the string representation of the float or null.

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*JSON) SetValid

func (j *JSON) SetValid(n []byte)

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

func (JSON) Unmarshal

func (j JSON) Unmarshal(dest interface{}) error

Unmarshal will unmarshal your JSON stored in your JSON object and store the result in the value pointed to by dest.

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

Example if you have a struct with a null.JSON called v:

		{}          -> does not call unmarshaljson: !set & !valid
		{"v": null} -> calls unmarshaljson, set & !valid
     {"v": {}}   -> calls unmarshaljson, set & valid (json value is '{}')

That's to say if 'null' is passed in at the json level we do not capture that value - instead we set the value-level null flag so that an sql value will turn out null.

func (*JSON) UnmarshalText

func (j *JSON) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (JSON) ValueOrDefault

func (t JSON) ValueOrDefault() []byte

ValueOrDefault returns the inner value if valid, otherwise default.

type String

type String struct {
	String string
	Valid  bool
	Set    bool
}

String is a nullable string. It supports SQL and JSON serialization.

func NewString

func NewString(s string, valid bool) String

NewString creates a new String

func StringFrom

func StringFrom(s string) String

StringFrom creates a new String that will never be blank.

func StringFromPtr

func StringFromPtr(s *string) String

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

func (String) IsSet

func (s String) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (String) IsValid

func (s String) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (String) IsZero

func (s String) IsZero() bool

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

func (String) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (String) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (String) Ptr

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

func (t String) Result() string

Result returns the string representation of the float or null.

func (*String) Scan

func (s *String) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*String) SetValid

func (s *String) SetValid(v string)

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

func (*String) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*String) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (String) Value

func (s String) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (String) ValueOrDefault

func (t String) ValueOrDefault() string

ValueOrDefault returns the inner value if valid, otherwise default.

type Time

type Time struct {
	Time  time.Time
	Valid bool
	Set   bool
}

Time is a nullable time.Time. It supports SQL and JSON serialization.

func NewTime

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

NewTime creates a new Time.

func TimeFrom

func TimeFrom(t time.Time) Time

TimeFrom creates a new Time that will always be valid.

func TimeFromPtr

func TimeFromPtr(t *time.Time) Time

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

func (Time) IsSet

func (t Time) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Time) IsValid

func (t Time) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero returns true for an invalid Time's value, for potential future omitempty support.

func (Time) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (Time) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Time) Ptr

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

func (t Time) Result() string

Result returns the string representation of the float or null.

func (*Time) Scan

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

Scan implements the Scanner interface.

func (*Time) SetValid

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

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

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Time) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Time) Value

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

Value implements the driver Valuer interface.

func (Time) ValueOrDefault

func (t Time) ValueOrDefault() time.Time

ValueOrDefault returns the inner value if valid, otherwise default.

type TimeStamp

type TimeStamp struct {
	TimeStamp time.Time
	Valid     bool
	Set       bool
}

TimeStamp is a nullable time.Time that accept only fullyear,month,date,hour,minute,second, and microsecond . When it is serialize to JSON and vice versa only accept of SQL DateTime Format YYYY-MM-DD hh:mm:ss ([4 digit year]-[2 digit month]-[2 digit year] [2 digit hour]:[2 digit minute][2 digit second].[6 digit microsecond]). It supports SQL and JSON serialization.

func NewTimeStamp

func NewTimeStamp(t time.Time, valid bool) TimeStamp

NewTimeStamp creates a new Time. that accept only fullyear,month,date,hour,minute,second and microsecond.

func TimeStampFrom

func TimeStampFrom(t time.Time) TimeStamp

TimeStampFrom creates a new TimeStamp that will always be valid.

func TimeStampFromPtr

func TimeStampFromPtr(t *time.Time) TimeStamp

TimeStampFromPtr creates a new TimeStamp that will be null if t is nil.

func (TimeStamp) IsSet

func (t TimeStamp) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (TimeStamp) IsValid

func (t TimeStamp) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (TimeStamp) IsZero

func (t TimeStamp) IsZero() bool

IsZero returns true for an invalid Time's value, for potential future omitempty support.

func (TimeStamp) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (TimeStamp) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (TimeStamp) Ptr

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

Ptr returns a pointer to this Time's value that accept only fullyear,month,date,hour,minute,second and microsecond. , or a nil pointer if this Time is null.

func (TimeStamp) Result

func (t TimeStamp) Result() string

Result returns the string representation of the float or null.

func (*TimeStamp) Scan

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

Scan implements the Scanner interface. that accept only fullyear,month,date,hour,minute,second and microsecond.

func (*TimeStamp) SetValid

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

SetValid changes this Time's value that accept only fullyear,month,date,hour,minute,second and microsecond. and sets it to be non-null.

func (*TimeStamp) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*TimeStamp) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (TimeStamp) Value

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

Value implements the driver Valuer interface.

func (TimeStamp) ValueOrDefault

func (t TimeStamp) ValueOrDefault() time.Time

ValueOrDefault returns the inner value if valid, otherwise default.

type Uint

type Uint struct {
	Uint  uint
	Valid bool
	Set   bool
}

Uint is an nullable uint.

func NewUint

func NewUint(i uint, valid bool) Uint

NewUint creates a new Uint

func UintFrom

func UintFrom(i uint) Uint

UintFrom creates a new Uint that will always be valid.

func UintFromPtr

func UintFromPtr(i *uint) Uint

UintFromPtr creates a new Uint that be null if i is nil.

func (Uint) IsSet

func (u Uint) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Uint) IsValid

func (u Uint) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Uint) IsZero

func (u Uint) IsZero() bool

IsZero returns true for invalid Uints, for future omitempty support (Go 1.4?)

func (Uint) MarshalJSON

func (u Uint) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Uint) MarshalText

func (u Uint) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint) Ptr

func (u Uint) Ptr() *uint

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

func (Uint) Result

func (t Uint) Result() string

String returns the string representation of the float or null.

func (*Uint) Scan

func (u *Uint) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Uint) SetValid

func (u *Uint) SetValid(n uint)

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

func (*Uint) UnmarshalJSON

func (u *Uint) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint) UnmarshalText

func (u *Uint) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Uint) Value

func (u Uint) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Uint) ValueOrDefault

func (u Uint) ValueOrDefault() uint

ValueOrDefault returns the inner value if valid, otherwise default.

type Uint16

type Uint16 struct {
	Uint16 uint16
	Valid  bool
	Set    bool
}

Uint16 is an nullable uint16.

func NewUint16

func NewUint16(i uint16, valid bool) Uint16

NewUint16 creates a new Uint16

func Uint16From

func Uint16From(i uint16) Uint16

Uint16From creates a new Uint16 that will always be valid.

func Uint16FromPtr

func Uint16FromPtr(i *uint16) Uint16

Uint16FromPtr creates a new Uint16 that be null if i is nil.

func (Uint16) IsSet

func (u Uint16) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Uint16) IsValid

func (u Uint16) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Uint16) IsZero

func (u Uint16) IsZero() bool

IsZero returns true for invalid Uint16's, for future omitempty support (Go 1.4?)

func (Uint16) MarshalJSON

func (u Uint16) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Uint16) MarshalText

func (u Uint16) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint16) Ptr

func (u Uint16) Ptr() *uint16

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

func (Uint16) Result

func (t Uint16) Result() string

String returns the string representation of the float or null.

func (*Uint16) Scan

func (u *Uint16) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Uint16) SetValid

func (u *Uint16) SetValid(n uint16)

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

func (*Uint16) UnmarshalJSON

func (u *Uint16) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint16) UnmarshalText

func (u *Uint16) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Uint16) Value

func (u Uint16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Uint16) ValueOrDefault

func (u Uint16) ValueOrDefault() uint16

ValueOrDefault returns the inner value if valid, otherwise default.

type Uint32

type Uint32 struct {
	Uint32 uint32
	Valid  bool
	Set    bool
}

Uint32 is an nullable uint32.

func NewUint32

func NewUint32(i uint32, valid bool) Uint32

NewUint32 creates a new Uint32

func Uint32From

func Uint32From(i uint32) Uint32

Uint32From creates a new Uint32 that will always be valid.

func Uint32FromPtr

func Uint32FromPtr(i *uint32) Uint32

Uint32FromPtr creates a new Uint32 that be null if i is nil.

func (Uint32) IsSet

func (u Uint32) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Uint32) IsValid

func (u Uint32) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Uint32) IsZero

func (u Uint32) IsZero() bool

IsZero returns true for invalid Uint32's, for future omitempty support (Go 1.4?)

func (Uint32) MarshalJSON

func (u Uint32) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Uint32) MarshalText

func (u Uint32) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint32) Ptr

func (u Uint32) Ptr() *uint32

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

func (Uint32) Result

func (t Uint32) Result() string

String returns the string representation of the float or null.

func (*Uint32) Scan

func (u *Uint32) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Uint32) SetValid

func (u *Uint32) SetValid(n uint32)

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

func (*Uint32) UnmarshalJSON

func (u *Uint32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint32) UnmarshalText

func (u *Uint32) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Uint32) Value

func (u Uint32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Uint32) ValueOrDefault

func (u Uint32) ValueOrDefault() uint32

ValueOrDefault returns the inner value if valid, otherwise default.

type Uint64

type Uint64 struct {
	Uint64 uint64
	Valid  bool
	Set    bool
}

Uint64 is an nullable uint64.

func NewUint64

func NewUint64(i uint64, valid bool) Uint64

NewUint64 creates a new Uint64

func Uint64From

func Uint64From(i uint64) Uint64

Uint64From creates a new Uint64 that will always be valid.

func Uint64FromPtr

func Uint64FromPtr(i *uint64) Uint64

Uint64FromPtr creates a new Uint64 that be null if i is nil.

func (Uint64) IsSet

func (u Uint64) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Uint64) IsValid

func (u Uint64) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Uint64) IsZero

func (u Uint64) IsZero() bool

IsZero returns true for invalid Uint64's, for future omitempty support (Go 1.4?)

func (Uint64) MarshalJSON

func (u Uint64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Uint64) MarshalText

func (u Uint64) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint64) Ptr

func (u Uint64) Ptr() *uint64

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

func (Uint64) Result

func (t Uint64) Result() string

String returns the string representation of the float or null.

func (*Uint64) Scan

func (u *Uint64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Uint64) SetValid

func (u *Uint64) SetValid(n uint64)

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

func (*Uint64) UnmarshalJSON

func (u *Uint64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint64) UnmarshalText

func (u *Uint64) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Uint64) Value

func (u Uint64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Uint64) ValueOrDefault

func (u Uint64) ValueOrDefault() uint64

ValueOrDefault returns the inner value if valid, otherwise default.

type Uint8

type Uint8 struct {
	Uint8 uint8
	Valid bool
	Set   bool
}

Uint8 is an nullable uint8.

func NewUint8

func NewUint8(i uint8, valid bool) Uint8

NewUint8 creates a new Uint8

func Uint8From

func Uint8From(i uint8) Uint8

Uint8From creates a new Uint8 that will always be valid.

func Uint8FromPtr

func Uint8FromPtr(i *uint8) Uint8

Uint8FromPtr creates a new Uint8 that be null if i is nil.

func (Uint8) IsSet

func (u Uint8) IsSet() bool

IsSet returns true if this carries an explicit value (null inclusive)

func (Uint8) IsValid

func (u Uint8) IsValid() bool

IsValid returns true if this carries and explicit value and is not null.

func (Uint8) IsZero

func (u Uint8) IsZero() bool

IsZero returns true for invalid Uint8's, for future omitempty support (Go 1.4?)

func (Uint8) MarshalJSON

func (u Uint8) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Uint8) MarshalText

func (u Uint8) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Uint8) Ptr

func (u Uint8) Ptr() *uint8

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

func (Uint8) Result

func (t Uint8) Result() string

String returns the string representation of the float or null.

func (*Uint8) Scan

func (u *Uint8) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Uint8) SetValid

func (u *Uint8) SetValid(n uint8)

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

func (*Uint8) UnmarshalJSON

func (u *Uint8) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Uint8) UnmarshalText

func (u *Uint8) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Uint8) Value

func (u Uint8) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Uint8) ValueOrDefault

func (u Uint8) ValueOrDefault() uint8

ValueOrDefault returns the inner value if valid, otherwise default.

type Value

type Value interface {
	// IsValid returns true iff the value is set and non-null
	IsValid() bool
	// IsSet returns true iff the value is set (null inclusive)
	IsSet() bool
}

Value specifies methods that allow introspection into the state of a value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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