nulls

package
v0.0.0-...-dc4534b Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2015 License: MIT Imports: 7 Imported by: 0

README

github.com/markbates/going/nulls

This package should be used in place of the built-in null types in the sql package.

The real benefit of this packages comes in its implementation of MarshalJSON and UnmarshalJSON to properly encode/decode null values.

Installation

$ go get github.com/markbates/going/nulls

Supported Datatypes

  • string (nulls.NullString) - Replaces sql.NullString
  • int64 (nulls.NullInt64) - Replaces sql.NullInt64
  • float64 (nulls.NullFloat64) - Replaces sql.NullFloat64
  • bool (nulls.NullBool) - Replaces sql.NullBool
  • []byte (nulls.NullByteSlice)
  • float32 (nulls.NullFloat32)
  • int (nulls.NullInt)
  • int32 (nulls.NullInt32)
  • uint32 (nulls.NullUInt32)

Additionally this package provides the following extra data types:

  • time.Time (nulls.NullTime)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NullBool

type NullBool struct {
	Bool  bool
	Valid bool
}

NullBool replaces sql.NullBool with an implementation that supports proper JSON encoding/decoding.

func NewNullBool

func NewNullBool(b bool) NullBool

NewNullBool returns a new, properly instantiated NullBoll object.

func (NullBool) MarshalJSON

func (ns NullBool) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullBool) Scan

func (ns *NullBool) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullBool) UnmarshalJSON

func (ns *NullBool) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the proper representation of that value. The strings "true" and "t" will be considered "true", "false" and "f" will be treated as "false". All other values will be set to null by Valid = false

func (NullBool) Value

func (ns NullBool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullByteSlice

type NullByteSlice struct {
	ByteSlice []byte
	Valid     bool // Valid is true if NullByteSlice is not NULL
}

NullByteSlice adds an implementation for []byte that supports proper JSON encoding/decoding.

func NewNullByteSlice

func NewNullByteSlice(b []byte) NullByteSlice

NewNullByteSlice returns a new, properly instantiated NullByteSlice object.

func (NullByteSlice) MarshalJSON

func (ns NullByteSlice) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullByteSlice) Scan

func (ns *NullByteSlice) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullByteSlice) UnmarshalJSON

func (ns *NullByteSlice) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullByteSlice) Value

func (ns NullByteSlice) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullFloat32

type NullFloat32 struct {
	Float32 float32
	Valid   bool // Valid is true if Float32 is not NULL
}

NullFloat32 adds an implementation for float32 that supports proper JSON encoding/decoding.

func NewNullFloat32

func NewNullFloat32(i float32) NullFloat32

NewNullFloat32 returns a new, properly instantiated NullFloat32 object.

func (NullFloat32) MarshalJSON

func (ns NullFloat32) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullFloat32) Scan

func (ns *NullFloat32) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullFloat32) UnmarshalJSON

func (ns *NullFloat32) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullFloat32) Value

func (ns NullFloat32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullFloat64

type NullFloat64 sql.NullFloat64

NullFloat64 replaces sql.NullFloat64 with an implementation that supports proper JSON encoding/decoding.

func NewNullFloat64

func NewNullFloat64(i float64) NullFloat64

NewNullFloat64 returns a new, properly instantiated NullFloat64 object.

func (NullFloat64) MarshalJSON

func (ns NullFloat64) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullFloat64) Scan

func (ns *NullFloat64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullFloat64) UnmarshalJSON

func (ns *NullFloat64) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullFloat64) Value

func (ns NullFloat64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt

type NullInt struct {
	Int   int
	Valid bool // Valid is true if Int is not NULL
}

NullInt adds an implementation for int that supports proper JSON encoding/decoding.

func NewNullInt

func NewNullInt(i int) NullInt

NewNullInt returns a new, properly instantiated NullInt object.

func (NullInt) MarshalJSON

func (ns NullInt) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullInt) Scan

func (ns *NullInt) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullInt) UnmarshalJSON

func (ns *NullInt) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullInt) Value

func (ns NullInt) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt32

type NullInt32 struct {
	Int32 int32
	Valid bool // Valid is true if Int32 is not NULL
}

NullInt32 adds an implementation for int32 that supports proper JSON encoding/decoding.

func NewNullInt32

func NewNullInt32(i int32) NullInt32

NewNullInt32 returns a new, properly instantiated NullInt object.

func (NullInt32) MarshalJSON

func (ns NullInt32) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullInt32) Scan

func (ns *NullInt32) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullInt32) UnmarshalJSON

func (ns *NullInt32) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullInt32) Value

func (ns NullInt32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt64

type NullInt64 sql.NullInt64

NullInt64 replaces sql.NullInt64 with an implementation that supports proper JSON encoding/decoding.

func NewNullInt64

func NewNullInt64(i int64) NullInt64

NewNullInt64 returns a new, properly instantiated NullInt64 object.

func (NullInt64) MarshalJSON

func (ns NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullInt64) Scan

func (ns *NullInt64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullInt64) UnmarshalJSON

func (ns *NullInt64) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullInt64) Value

func (ns NullInt64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullString

type NullString sql.NullString

NullString replaces sql.NullString with an implementation that supports proper JSON encoding/decoding.

func NewNullString

func NewNullString(s string) NullString

NewNullString returns a new, properly instantiated NullString object.

func (NullString) MarshalJSON

func (ns NullString) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullString) Scan

func (ns *NullString) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullString) UnmarshalJSON

func (ns *NullString) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullString) Value

func (ns NullString) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

NullTime replaces sql.NullTime with an implementation that supports proper JSON encoding/decoding.

func NewNullTime

func NewNullTime(t time.Time) NullTime

NewNullTime returns a new, properly instantiated NullTime object.

func (NullTime) MarshalJSON

func (ns NullTime) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullTime) Scan

func (ns *NullTime) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullTime) UnmarshalJSON

func (ns *NullTime) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullTime) Value

func (ns NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullUInt32

type NullUInt32 struct {
	UInt32 uint32
	Valid  bool // Valid is true if Int is not NULL
}

NullUInt32 adds an implementation for int that supports proper JSON encoding/decoding.

func NewNullUInt32

func NewNullUInt32(i uint32) NullUInt32

NewNullUInt32 returns a new, properly instantiated NullInt object.

func (NullUInt32) MarshalJSON

func (ns NullUInt32) MarshalJSON() ([]byte, error)

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*NullUInt32) Scan

func (ns *NullUInt32) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullUInt32) UnmarshalJSON

func (ns *NullUInt32) UnmarshalJSON(text []byte) error

UnmarshalJSON will unmarshal a JSON value into the propert representation of that value.

func (NullUInt32) Value

func (ns NullUInt32) 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