nullable

package module
v0.0.0-...-92f0e35 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2016 License: MIT Imports: 8 Imported by: 0

README

Nullable Types

GoDoc Build Status (Linux) Build status (Windows) license Coverage Status GoReportCard

The nullable package provides a number of types that represent values that may be null. The standard Go library already includes types in the database/sql package for this purpose including NullBool, NullFloat64, NullInt64 and NullString.

The types in this package add to this list for convenience. The other significant difference is that the types in this package all implement the json.Marshaler and json.Unmarshaler interfaces, which are used for serializing to and from JSON.

Documentation

Overview

Package nullable contains types that represent values that may be null. The Go standard library already has NullBool, NullFloat64, NullInt64 and NullString in the database/sql package. The types in this package add additional data types.

The types in this package also all implement the json.Marshaler and json.Unmarshaler interfaces, so they can be serialized to and from JSON. These types also have convience methods for converting to and from pointers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Bool  bool
	Valid bool
}

Bool represents a bool value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func BoolFromPtr

func BoolFromPtr(ptr *bool) Bool

BoolFromPtr returns a Bool whose value matches ptr.

func (*Bool) Assign

func (b *Bool) Assign(ptr *bool) Bool

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Bool) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Bool) Normalized

func (b Bool) Normalized() Bool

Normalized returns a Bool that can be compared with another Bool for equality.

func (Bool) Ptr

func (b Bool) Ptr() *bool

Ptr returns a pointer to bool. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Bool) Scan

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

Scan implements the sql.Scanner interface.

func (*Bool) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (Bool) Value

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

Value implements the driver.Valuer interface.

type Byte

type Byte struct {
	Byte  byte
	Valid bool
}

Byte represents a byte value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func ByteFromPtr

func ByteFromPtr(ptr *byte) Byte

ByteFromPtr returns a Byte whose value matches ptr.

func (*Byte) Assign

func (n *Byte) Assign(ptr *byte) Byte

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Byte) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Byte) Normalized

func (n Byte) Normalized() Byte

Normalized returns a Byte that can be compared with another Byte for equality.

func (Byte) Ptr

func (n Byte) Ptr() *byte

Ptr returns a pointer to byte. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Byte) Scan

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

Scan implements the sql.Scanner interface.

func (*Byte) UnmarshalJSON

func (n *Byte) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Byte) Value

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

Value implements the driver.Valuer interface.

type Float32

type Float32 struct {
	Float32 float32
	Valid   bool
}

Float32 represents a float32 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Float32FromPtr

func Float32FromPtr(ptr *float32) Float32

Float32FromPtr returns a Float32 whose value matches ptr.

func (*Float32) Assign

func (n *Float32) Assign(ptr *float32) Float32

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Float32) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Float32) Normalized

func (n Float32) Normalized() Float32

Normalized returns a Float32 that can be compared with another Float32 for equality.

func (Float32) Ptr

func (n Float32) Ptr() *float32

Ptr returns a pointer to float32. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Float32) Scan

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

Scan implements the sql.Scanner interface.

func (*Float32) UnmarshalJSON

func (n *Float32) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Float32) Value

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

Value implements the driver.Valuer interface.

type Float64

type Float64 struct {
	Float64 float64
	Valid   bool
}

Float64 represents a float64 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Float64FromPtr

func Float64FromPtr(ptr *float64) Float64

Float64FromPtr returns a Float64 whose value matches ptr.

func (*Float64) Assign

func (n *Float64) Assign(ptr *float64) Float64

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Float64) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Float64) Normalized

func (n Float64) Normalized() Float64

Normalized returns a Float64 that can be compared with another Float64 for equality.

func (Float64) Ptr

func (n Float64) Ptr() *float64

Ptr returns a pointer to float64. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Float64) Scan

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

Scan implements the sql.Scanner interface.

func (*Float64) UnmarshalJSON

func (n *Float64) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Float64) Value

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

Value implements the driver.Valuer interface.

type Int

type Int struct {
	Int   int
	Valid bool
}

Int represents an int value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func IntFromPtr

func IntFromPtr(ptr *int) Int

IntFromPtr returns a Int whose value matches ptr.

func (*Int) Assign

func (n *Int) Assign(ptr *int) Int

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Int) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Int) Normalized

func (n Int) Normalized() Int

Normalized returns an Int that can be compared with another Int for equality.

func (Int) Ptr

func (n Int) Ptr() *int

Ptr returns a pointer to int. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Int) Scan

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

Scan implements the sql.Scanner interface.

func (*Int) UnmarshalJSON

func (n *Int) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Int) Value

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

Value implements the driver.Valuer interface.

type Int16

type Int16 struct {
	Int16 int16
	Valid bool
}

Int16 represents an int16 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Int16FromPtr

func Int16FromPtr(ptr *int16) Int16

Int16FromPtr returns a Int16 whose value matches ptr.

func (*Int16) Assign

func (n *Int16) Assign(ptr *int16) Int16

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Int16) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Int16) Normalized

func (n Int16) Normalized() Int16

Normalized returns an Int16 that can be compared with another Int16 for equality.

func (Int16) Ptr

func (n Int16) Ptr() *int16

Ptr returns a pointer to int16. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Int16) Scan

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

Scan implements the sql.Scanner interface.

func (*Int16) UnmarshalJSON

func (n *Int16) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Int16) Value

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

Value implements the driver.Valuer interface.

type Int32

type Int32 struct {
	Int32 int32
	Valid bool
}

Int32 represents an int32 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Int32FromPtr

func Int32FromPtr(ptr *int32) Int32

Int32FromPtr returns a Int32 whose value matches ptr.

func (*Int32) Assign

func (n *Int32) Assign(ptr *int32) Int32

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Int32) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Int32) Normalized

func (n Int32) Normalized() Int32

Normalized returns an Int32 that can be compared with another Int32 for equality.

func (Int32) Ptr

func (n Int32) Ptr() *int32

Ptr returns a pointer to int32. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Int32) Scan

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

Scan implements the sql.Scanner interface.

func (*Int32) UnmarshalJSON

func (n *Int32) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Int32) Value

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

Value implements the driver.Valuer interface.

type Int64

type Int64 struct {
	Int64 int64
	Valid bool
}

Int64 represents an int64 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Int64FromPtr

func Int64FromPtr(ptr *int64) Int64

Int64FromPtr returns a Int64 whose value matches ptr.

func (*Int64) Assign

func (n *Int64) Assign(ptr *int64) Int64

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Int64) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Int64) Normalized

func (n Int64) Normalized() Int64

Normalized returns an Int64 that can be compared with another Int64 for equality.

func (Int64) Ptr

func (n Int64) Ptr() *int64

Ptr returns a pointer to int64. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Int64) Scan

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

Scan implements the sql.Scanner interface.

func (*Int64) UnmarshalJSON

func (n *Int64) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Int64) Value

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

Value implements the driver.Valuer interface.

type Int8

type Int8 struct {
	Int8  int8
	Valid bool
}

Int8 represents an int8 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Int8FromPtr

func Int8FromPtr(ptr *int8) Int8

Int8FromPtr returns a Int8 whose value matches ptr.

func (*Int8) Assign

func (n *Int8) Assign(ptr *int8) Int8

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Int8) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Int8) Normalized

func (n Int8) Normalized() Int8

Normalized returns an Int8 that can be compared with another Int8 for equality.

func (Int8) Ptr

func (n Int8) Ptr() *int8

Ptr returns a pointer to int8. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Int8) Scan

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

Scan implements the sql.Scanner interface.

func (*Int8) UnmarshalJSON

func (n *Int8) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Int8) Value

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

Value implements the driver.Valuer interface.

type String

type String struct {
	String string
	Valid  bool
}

String represents a string value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func StringFromPtr

func StringFromPtr(ptr *string) String

StringFromPtr returns a String whose value matches ptr.

func (*String) Assign

func (s *String) Assign(ptr *string) String

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (String) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (String) Normalized

func (s String) Normalized() String

Normalized returns a String that can be compared with another String for equality.

func (String) Ptr

func (s String) Ptr() *string

Ptr returns a pointer to string. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*String) Scan

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

Scan implements the sql.Scanner interface.

func (*String) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (String) Value

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

Value implements the driver.Valuer interface.

type Time

type Time struct {
	Time  time.Time
	Valid bool
}

Time represents a time.Time value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func TimeFromPtr

func TimeFromPtr(ptr *time.Time) Time

TimeFromPtr returns a Time whose value matches ptr.

func (*Time) Assign

func (tm *Time) Assign(ptr *time.Time) Time

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Time) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Time) Normalized

func (tm Time) Normalized() Time

Normalized returns a Time that can be compared with another Time for equality.

func (Time) Ptr

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

Ptr returns a pointer to time.Time. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Time) Scan

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

Scan implements the sql.Scanner interface.

func (*Time) UnmarshalJSON

func (tm *Time) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Time) Value

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

Value implements the driver.Valuer interface.

type Uint

type Uint struct {
	Uint  uint
	Valid bool
}

Uint represents a uint value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func UintFromPtr

func UintFromPtr(ptr *uint) Uint

UintFromPtr returns a Uint whose value matches ptr.

func (*Uint) Assign

func (n *Uint) Assign(ptr *uint) Uint

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Uint) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Uint) Normalized

func (n Uint) Normalized() Uint

Normalized returns a Uint that can be compared with another Uint for equality.

func (Uint) Ptr

func (n Uint) Ptr() *uint

Ptr returns a pointer to uint. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Uint) Scan

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

Scan implements the sql.Scanner interface.

func (*Uint) UnmarshalJSON

func (n *Uint) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Uint) Value

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

Value implements the driver.Valuer interface.

type Uint16

type Uint16 struct {
	Uint16 uint16
	Valid  bool
}

Uint16 represents a uint16 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Uint16FromPtr

func Uint16FromPtr(ptr *uint16) Uint16

Uint16FromPtr returns a Uint16 whose value matches ptr.

func (*Uint16) Assign

func (n *Uint16) Assign(ptr *uint16) Uint16

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Uint16) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Uint16) Normalized

func (n Uint16) Normalized() Uint16

Normalized returns a Uint16 that can be compared with another Uint16 for equality.

func (Uint16) Ptr

func (n Uint16) Ptr() *uint16

Ptr returns a pointer to uint16. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Uint16) Scan

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

Scan implements the sql.Scanner interface.

func (*Uint16) UnmarshalJSON

func (n *Uint16) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Uint16) Value

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

Value implements the driver.Valuer interface.

type Uint32

type Uint32 struct {
	Uint32 uint32
	Valid  bool
}

Uint32 represents a uint32 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Uint32FromPtr

func Uint32FromPtr(ptr *uint32) Uint32

Uint32FromPtr returns a Uint32 whose value matches ptr.

func (*Uint32) Assign

func (n *Uint32) Assign(ptr *uint32) Uint32

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Uint32) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Uint32) Normalized

func (n Uint32) Normalized() Uint32

Normalized returns a Uint32 that can be compared with another Uint32 for equality.

func (Uint32) Ptr

func (n Uint32) Ptr() *uint32

Ptr returns a pointer to uint32. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Uint32) Scan

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

Scan implements the sql.Scanner interface.

func (*Uint32) UnmarshalJSON

func (n *Uint32) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Uint32) Value

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

Value implements the driver.Valuer interface.

type Uint64

type Uint64 struct {
	Uint64 uint64
	Valid  bool
}

Uint64 represents a uint64 value that may be null. This type implements the Scanner interface so it can be used as a scan destination, similar to NullString. It also implements the necessary interfaces to serialize to and from JSON.

func Uint64FromPtr

func Uint64FromPtr(ptr *uint64) Uint64

Uint64FromPtr returns a Uint64 whose value matches ptr.

func (*Uint64) Assign

func (n *Uint64) Assign(ptr *uint64) Uint64

Assign the value of the pointer. If the pointer is nil, then then Valid is false, otherwise Valid is true.

func (Uint64) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (Uint64) Normalized

func (n Uint64) Normalized() Uint64

Normalized returns a Uint64 that can be compared with another Uint64 for equality.

func (Uint64) Ptr

func (n Uint64) Ptr() *uint64

Ptr returns a pointer to uint64. If Valid is false then the pointer is nil, otherwise it is non-nil.

func (*Uint64) Scan

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

Scan implements the sql.Scanner interface.

func (*Uint64) UnmarshalJSON

func (n *Uint64) UnmarshalJSON(p []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Uint64) Value

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

Value implements the driver.Valuer interface.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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