go get -u github.com/cihangir/nisql
Package nisql provides nullable types for database operations with proper json marshalling and unmarshalling
type NullBool struct {
sql.NullBool
}
NullBool is a type that can be null or a bool
func Bool(b bool) NullBool
Bool creates a valid NullBool
func (n *NullBool) Get() *bool
Get returns nil or underlying bool value
func (n *NullBool) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (n *NullBool) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type NullFloat64 struct {
sql.NullFloat64
}
NullFloat64 is a type that can be null or a float64
func Float64(f float64) NullFloat64
Float64 creates a valid NullFloat64
func (n *NullFloat64) Get() *float64
Get returns nil or underlying float64 value
func (n *NullFloat64) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (n *NullFloat64) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type NullInt64 struct {
sql.NullInt64
}
NullInt64 is a type that can be null or an int
func Int64(i int64) NullInt64
Int64 creates a valid NullInt64
func (n *NullInt64) Get() *int64
Get returns nil or underlying int64 value
func (n *NullInt64) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (n *NullInt64) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type NullString struct {
sql.NullString
}
NullString is a type that can be null or a string
func String(s string) NullString
String creates a valid NullString
func (n *NullString) Get() *string
Get returns nil or underlying string value
func (n *NullString) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (n *NullString) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type NullTime struct {
pq.NullTime
}
NullTime is a type that can be null or a time.Time
func Time(t time.Time) NullTime
Time creates a valid NullTime
func (n *NullTime) Get() *time.Time
Get returns nil or underlying time.Time value
func (n *NullTime) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (n *NullTime) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.