Skip to content

cihangir/nisql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status GoDoc

nisql

go get -u github.com/cihangir/nisql

Package nisql provides nullable types for database operations with proper json marshalling and unmarshalling

Usage

type NullBool

type NullBool struct {
    sql.NullBool
}

NullBool is a type that can be null or a bool

func Bool

func Bool(b bool) NullBool

Bool creates a valid NullBool

func (*NullBool) Get

func (n *NullBool) Get() *bool

Get returns nil or underlying bool value

func (*NullBool) MarshalJSON

func (n *NullBool) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*NullBool) UnmarshalJSON

func (n *NullBool) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type NullFloat64

type NullFloat64 struct {
    sql.NullFloat64
}

NullFloat64 is a type that can be null or a float64

func Float64

func Float64(f float64) NullFloat64

Float64 creates a valid NullFloat64

func (*NullFloat64) Get

func (n *NullFloat64) Get() *float64

Get returns nil or underlying float64 value

func (*NullFloat64) MarshalJSON

func (n *NullFloat64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*NullFloat64) UnmarshalJSON

func (n *NullFloat64) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type NullInt64

type NullInt64 struct {
    sql.NullInt64
}

NullInt64 is a type that can be null or an int

func Int64

func Int64(i int64) NullInt64

Int64 creates a valid NullInt64

func (*NullInt64) Get

func (n *NullInt64) Get() *int64

Get returns nil or underlying int64 value

func (*NullInt64) MarshalJSON

func (n *NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*NullInt64) UnmarshalJSON

func (n *NullInt64) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type NullString

type NullString struct {
    sql.NullString
}

NullString is a type that can be null or a string

func String

func String(s string) NullString

String creates a valid NullString

func (*NullString) Get

func (n *NullString) Get() *string

Get returns nil or underlying string value

func (*NullString) MarshalJSON

func (n *NullString) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*NullString) UnmarshalJSON

func (n *NullString) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type NullTime

type NullTime struct {
    pq.NullTime
}

NullTime is a type that can be null or a time.Time

func Time

func Time(t time.Time) NullTime

Time creates a valid NullTime

func (*NullTime) Get

func (n *NullTime) Get() *time.Time

Get returns nil or underlying time.Time value

func (*NullTime) MarshalJSON

func (n *NullTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*NullTime) UnmarshalJSON

func (n *NullTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

About

Nullable SQL Types with proper marshalers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published