nulls

package
v4.0.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2018 License: MIT Imports: 10 Imported by: 0

README

github.com/gobuffalo/pop/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/gobuffalo/pop/nulls

Supported Datatypes

  • string (nulls.String) - Replaces sql.NullString
  • int64 (nulls.Int64) - Replaces sql.NullInt64
  • float64 (nulls.Float64) - Replaces sql.NullFloat64
  • bool (nulls.Bool) - Replaces sql.NullBool
  • []byte (nulls.ByteSlice)
  • float32 (nulls.Float32)
  • int (nulls.Int)
  • int32 (nulls.Int32)
  • uint32 (nulls.UInt32)
  • time.Time (nulls.Time)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterWithSchema

func RegisterWithSchema(reg register)

RegisterWithSchema allows for the nulls package to be used with http://www.gorillatoolkit.org/pkg/schema#Converter

Types

type Bool

type Bool struct {
	Bool  bool
	Valid bool
}

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

func NewBool

func NewBool(b bool) Bool

NewBool returns a new, properly instantiated Boll object.

func (Bool) Interface

func (ns Bool) Interface() interface{}

func (Bool) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*Bool) Scan

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

Scan implements the Scanner interface.

func (*Bool) UnmarshalJSON

func (ns *Bool) 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 (*Bool) UnmarshalText

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

func (Bool) Value

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

Value implements the driver Valuer interface.

type ByteSlice

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

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

func NewByteSlice

func NewByteSlice(b []byte) ByteSlice

NewByteSlice returns a new, properly instantiated ByteSlice object.

func (ByteSlice) Interface

func (ns ByteSlice) Interface() interface{}

func (ByteSlice) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*ByteSlice) Scan

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

Scan implements the Scanner interface.

func (*ByteSlice) UnmarshalJSON

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

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

func (*ByteSlice) UnmarshalText

func (ns *ByteSlice) UnmarshalText(text []byte) error

func (ByteSlice) Value

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

Value implements the driver Valuer interface.

type Float32

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

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

func NewFloat32

func NewFloat32(i float32) Float32

NewFloat32 returns a new, properly instantiated Float32 object.

func (Float32) Interface

func (ns Float32) Interface() interface{}

func (Float32) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*Float32) Scan

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

Scan implements the Scanner interface.

func (*Float32) UnmarshalJSON

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

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

func (*Float32) UnmarshalText

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

func (Float32) Value

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

Value implements the driver Valuer interface.

type Float64

type Float64 sql.NullFloat64

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

func NewFloat64

func NewFloat64(i float64) Float64

NewFloat64 returns a new, properly instantiated Float64 object.

func (Float64) Interface

func (ns Float64) Interface() interface{}

func (Float64) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*Float64) Scan

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

Scan implements the Scanner interface.

func (*Float64) UnmarshalJSON

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

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

func (*Float64) UnmarshalText

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

func (Float64) Value

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

Value implements the driver Valuer interface.

type Int

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

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

func NewInt

func NewInt(i int) Int

NewInt returns a new, properly instantiated Int object.

func (Int) Interface

func (ns Int) Interface() interface{}

func (Int) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*Int) Scan

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

Scan implements the Scanner interface.

func (*Int) UnmarshalJSON

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

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

func (*Int) UnmarshalText

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

func (Int) Value

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

Value implements the driver Valuer interface.

type Int32

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

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

func NewInt32

func NewInt32(i int32) Int32

NewInt32 returns a new, properly instantiated Int object.

func (Int32) Interface

func (ns Int32) Interface() interface{}

func (Int32) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*Int32) Scan

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

Scan implements the Scanner interface.

func (*Int32) UnmarshalJSON

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

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

func (*Int32) UnmarshalText

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

func (Int32) Value

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

Value implements the driver Valuer interface.

type Int64

type Int64 sql.NullInt64

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

func NewInt64

func NewInt64(i int64) Int64

NewInt64 returns a new, properly instantiated Int64 object.

func (Int64) Interface

func (ns Int64) Interface() interface{}

func (Int64) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*Int64) Scan

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

Scan implements the Scanner interface.

func (*Int64) UnmarshalJSON

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

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

func (*Int64) UnmarshalText

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

func (Int64) Value

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

Value implements the driver Valuer interface.

type String

type String sql.NullString

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

func NewString

func NewString(s string) String

NewString returns a new, properly instantiated String object.

func (String) Interface

func (ns String) Interface() interface{}

func (String) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*String) Scan

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

Scan implements the Scanner interface.

func (*String) UnmarshalJSON

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

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

func (*String) UnmarshalText

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

func (String) Value

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

Value implements the driver Valuer interface.

type Time

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

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

func NewTime

func NewTime(t time.Time) Time

NewTime returns a new, properly instantiated Time object.

func (Time) Interface

func (ns Time) Interface() interface{}

func (Time) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*Time) Scan

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

Scan implements the Scanner interface.

func (*Time) UnmarshalJSON

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

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

func (*Time) UnmarshalText

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

func (Time) Value

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

Value implements the driver Valuer interface.

type UInt32

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

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

func NewUInt32

func NewUInt32(i uint32) UInt32

NewUInt32 returns a new, properly instantiated Int object.

func (UInt32) Interface

func (ns UInt32) Interface() interface{}

func (UInt32) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*UInt32) Scan

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

Scan implements the Scanner interface.

func (*UInt32) UnmarshalJSON

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

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

func (*UInt32) UnmarshalText

func (ns *UInt32) UnmarshalText(text []byte) error

func (UInt32) Value

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

Value implements the driver Valuer interface.

type UUID

type UUID struct {
	UUID  uuid.UUID
	Valid bool
}

UUID can be used with the standard sql package to represent a UUID value that can be NULL in the database

func NewUUID

func NewUUID(u uuid.UUID) UUID

NewUUID returns a new, properly instantiated UUID object.

func (UUID) Interface

func (ns UUID) Interface() interface{}

func (UUID) MarshalJSON

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

MarshalJSON marshals the underlying value to a proper JSON representation.

func (*UUID) Scan

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

Scan implements the sql.Scanner interface.

func (*UUID) UnmarshalJSON

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

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

func (*UUID) UnmarshalText

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

func (UUID) Value

func (u 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