nullish

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 8 Imported by: 0

README

Nullish

Go Reference

MIT License

Nullish is type helper fo handle null in golang. its support null for primitive data types and also another data type.

Warning ⚠️

This project is used by my companies on production and there is not enough time to make unit testing so maybe something not work for you. use at your own risk.

Installation

  go get -u github.com/sutantodadang/nullish

Features

  • NullString
  • NullJsonb / Json
  • NullInt
  • NullFloat
  • NullBool
  • NullUUID
  • NullTime
  • NullULID

Usage/Examples

  • nullstring
import "github.com/sutantodadang/nullish"

type foo struct {
    bar nullish.NullString

}

// you can also defined default value
foo.bar = nullish.NewNullString("hello", true)

Authors

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type NullArr

type NullArr struct {
	Arr   []interface{}
	Valid bool
}

func NewNullArr

func NewNullArr(array []interface{}, valid bool) NullArr

func (NullArr) MarshalJSON

func (na NullArr) MarshalJSON() ([]byte, error)

MarshalJSON method

func (*NullArr) Scan

func (na *NullArr) Scan(value interface{}) error

Scan method

func (*NullArr) UnmarshalJSON

func (na *NullArr) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullArr) Value

func (na NullArr) Value() (driver.Value, error)

Value method

type NullArrObj

type NullArrObj struct {
	ArrObj []map[string]interface{}
	Valid  bool
}

func NewNullArrObj

func NewNullArrObj(arrayObject []map[string]interface{}, valid bool) NullArrObj

func (NullArrObj) MarshalJSON

func (na NullArrObj) MarshalJSON() ([]byte, error)

MarshalJSON method

func (*NullArrObj) Scan

func (na *NullArrObj) Scan(value interface{}) error

Scan method

func (*NullArrObj) UnmarshalJSON

func (na *NullArrObj) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullArrObj) Value

func (na NullArrObj) Value() (driver.Value, error)

Value method

type NullBool

type NullBool struct {
	Bool  bool
	Valid bool
}

func NewNullBool

func NewNullBool(boolean bool, valid bool) NullBool

func (NullBool) MarshalJSON

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

MarshalJSON method

func (*NullBool) Scan

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

Scan method

func (*NullBool) UnmarshalJSON

func (nb *NullBool) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullBool) Value

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

Value method

type NullFloat

type NullFloat struct {
	Float float64
	Valid bool
}

func NewNullFloat

func NewNullFloat(float float64, valid bool) NullFloat

func (NullFloat) MarshalJSON

func (nf NullFloat) MarshalJSON() ([]byte, error)

MarshalJSON method

func (*NullFloat) Scan

func (nf *NullFloat) Scan(value interface{}) error

Scan method

func (*NullFloat) UnmarshalJSON

func (nf *NullFloat) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullFloat) Value

func (nf NullFloat) Value() (driver.Value, error)

Value method

type NullInt

type NullInt struct {
	Int   int
	Valid bool
}

func NewNullInt

func NewNullInt(integer int, valid bool) NullInt

func (NullInt) MarshalJSON

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

MarshalJSON method

func (*NullInt) Scan

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

Scan method

func (*NullInt) UnmarshalJSON

func (ni *NullInt) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullInt) Value

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

Value method

type NullJSON

type NullJSON struct {
	Json  json.RawMessage
	Valid bool
}

func NewNullJSON

func NewNullJSON(json json.RawMessage, valid bool) NullJSON

func (NullJSON) MarshalJSON

func (nj NullJSON) MarshalJSON() ([]byte, error)

MarshalJSON method

func (*NullJSON) Scan

func (nj *NullJSON) Scan(value interface{}) error

Scan method

func (*NullJSON) UnmarshalJSON

func (nj *NullJSON) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullJSON) Value

func (nj NullJSON) Value() (driver.Value, error)

Value method

type NullObj

type NullObj struct {
	Obj   map[string]interface{}
	Valid bool
}

func NewNullObj

func NewNullObj(object map[string]interface{}, valid bool) NullObj

func (NullObj) MarshalJSON

func (no NullObj) MarshalJSON() ([]byte, error)

MarshalJSON method

func (*NullObj) Scan

func (no *NullObj) Scan(value interface{}) error

Scan method

func (*NullObj) UnmarshalJSON

func (no *NullObj) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullObj) Value

func (no NullObj) Value() (driver.Value, error)

Value method

type NullString

type NullString struct {
	String string
	Valid  bool
}

func NewNullString

func NewNullString(str string, valid bool) NullString

func (NullString) MarshalJSON

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

MarshalJSON method

func (*NullString) Scan

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

Scan method

func (*NullString) UnmarshalJSON

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

UnmarshalJSON method

func (NullString) Value

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

Value method

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool
}

func NewNullTime

func NewNullTime(time time.Time, valid bool) NullTime

func (NullTime) MarshalJSON

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

MarshalJSON method

func (*NullTime) Scan

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

Scan method

func (*NullTime) UnmarshalJSON

func (nt *NullTime) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullTime) Value

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

Value method

type NullULID

type NullULID struct {
	ULID  ulid.ULID
	Valid bool
}

func NewNullULID

func NewNullULID(ulid ulid.ULID, valid bool) NullULID

func (NullULID) MarshalJSON

func (nl NullULID) MarshalJSON() ([]byte, error)

MarshalJSON method

func (*NullULID) Scan

func (nl *NullULID) Scan(value interface{}) error

Scan method

func (*NullULID) UnmarshalJSON

func (nl *NullULID) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullULID) Value

func (nl NullULID) Value() (driver.Value, error)

Value method

type NullUUID

type NullUUID struct {
	UUID  uuid.UUID
	Valid bool
}

func NewNullUUID

func NewNullUUID(uuid uuid.UUID, valid bool) NullUUID

func (NullUUID) MarshalJSON

func (nu NullUUID) MarshalJSON() ([]byte, error)

MarshalJSON method

func (*NullUUID) Scan

func (nu *NullUUID) Scan(value interface{}) error

Scan method

func (*NullUUID) UnmarshalJSON

func (nu *NullUUID) UnmarshalJSON(data []byte) error

UnmarshalJSON method

func (NullUUID) Value

func (nu NullUUID) Value() (driver.Value, error)

Value method

Jump to

Keyboard shortcuts

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