Documentation
¶
Index ¶
- func CantDecodeHex(err error, s string) error
- func CantParseFloat64(err error, s string) error
- func CantParseInt64(err error, s string) error
- func CantParseUint64(err error, s string) error
- func CantUnmarshalYAML(err error, v interface{}) error
- func MarshalJSON(v interface{}) ([]byte, error)
- func Name(t any) string
- func TransformEmptyStringToNull(s *String)
- func TransformZeroBoolToNull(b *Bool)
- func TransformZeroIntToNull(i *Int)
- func UnmarshalJSON(data []byte, v interface{}) error
- type Binary
- func (binary Binary) MarshalJSON() ([]byte, error)
- func (binary Binary) MarshalText() ([]byte, error)
- func (binary *Binary) Scan(src interface{}) error
- func (binary Binary) String() string
- func (binary *Binary) UnmarshalJSON(data []byte) error
- func (binary *Binary) UnmarshalText(text []byte) error
- func (binary Binary) Valid() bool
- func (binary Binary) Value() (driver.Value, error)
- type Bool
- type Float
- type Int
- type String
- type UUID
- type UnixMilli
- func (t UnixMilli) MarshalJSON() ([]byte, error)
- func (t UnixMilli) MarshalText() ([]byte, error)
- func (t *UnixMilli) Scan(src interface{}) error
- func (t UnixMilli) Time() time.Time
- func (t *UnixMilli) UnmarshalJSON(data []byte) error
- func (t *UnixMilli) UnmarshalText(text []byte) error
- func (t UnixMilli) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CantDecodeHex ¶
CantDecodeHex wraps the given error with the given string that cannot be hex-decoded.
func CantParseFloat64 ¶
CantParseFloat64 wraps the given error with the specified string that cannot be parsed into float64.
func CantParseInt64 ¶
CantParseInt64 wraps the given error with the specified string that cannot be parsed into int64.
func CantParseUint64 ¶
CantParseUint64 wraps the given error with the specified string that cannot be parsed into uint64.
func CantUnmarshalYAML ¶
CantUnmarshalYAML wraps the given error with the designated value, which cannot be unmarshalled into.
func MarshalJSON ¶
MarshalJSON calls json.Marshal and wraps any resulting errors.
func TransformEmptyStringToNull ¶ added in v0.7.0
func TransformEmptyStringToNull(s *String)
TransformEmptyStringToNull transforms a valid String carrying an empty text to a SQL NULL.
func TransformZeroBoolToNull ¶ added in v0.8.0
func TransformZeroBoolToNull(b *Bool)
TransformZeroBoolToNull is a transformer function that sets the Valid field to false if the Bool is zero. This is useful when you want to convert a zero value to a NULL value in a database context.
func TransformZeroIntToNull ¶ added in v0.7.0
func TransformZeroIntToNull(i *Int)
TransformZeroIntToNull transforms a valid Int carrying a zero value to a SQL NULL.
func UnmarshalJSON ¶
UnmarshalJSON calls json.Unmarshal and wraps any resulting errors.
Types ¶
type Binary ¶
type Binary []byte
Binary nullable byte string. Hex as JSON.
func (Binary) MarshalJSON ¶
MarshalJSON implements a custom marshal function to encode the Binary as a hex string. MarshalJSON implements the json.Marshaler interface. Supports JSON null.
func (Binary) MarshalText ¶
MarshalText implements a custom marhsal function to encode the Binary as hex. MarshalText implements the encoding.TextMarshaler interface.
func (*Binary) UnmarshalJSON ¶
UnmarshalJSON implements a custom unmarshal function to decode a JSON hex string into a Binary. UnmarshalJSON implements the json.Unmarshaler interface. Supports JSON null.
func (*Binary) UnmarshalText ¶
UnmarshalText implements a custom unmarshal function to decode hex into a Binary. UnmarshalText implements the encoding.TextUnmarshaler interface.
type Bool ¶
Bool represents a bool for ENUM ('y', 'n'), which can be NULL.
func MakeBool ¶ added in v0.8.0
MakeBool constructs a new Bool.
Multiple transformer functions can be given, each transforming the generated Bool to whatever is needed. If no transformers are given, the Bool will be valid and set to the given value.
func (Bool) IsZero ¶ added in v0.8.0
IsZero implements the json.isZeroer interface. A Bool is considered zero if its Valid field is false regardless of its actual Bool value.
func (Bool) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Bool) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Float ¶
type Float struct {
sql.NullFloat64
}
Float adds JSON support to sql.NullFloat64.
func (Float) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. Supports JSON null.
func (*Float) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. Supports JSON null.
func (*Float) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Int ¶
Int adds JSON support to sql.NullInt64.
func MakeInt ¶ added in v0.7.0
MakeInt constructs a new Int.
Multiple transformer functions can be given, each transforming the generated Int, e.g., TransformZeroIntToNull.
func (Int) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. Supports JSON null.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. Supports JSON null.
func (*Int) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type String ¶
type String struct {
sql.NullString
}
String adds JSON support to sql.NullString.
func MakeString ¶
MakeString constructs a new String.
Multiple transformer functions can be given, each transforming the generated String, e.g., TransformEmptyStringToNull.
func (String) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. Supports JSON null.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. Supports JSON null.
func (*String) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type UUID ¶
UUID is like uuid.UUID, but marshals itself binarily (not like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) in SQL context.
type UnixMilli ¶
UnixMilli is a nullable millisecond UNIX timestamp in databases and JSON.
func (UnixMilli) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. Marshals to milliseconds. Supports JSON null.
func (UnixMilli) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*UnixMilli) Scan ¶
Scan implements the sql.Scanner interface. Scans from milliseconds. Supports SQL NULL.
func (*UnixMilli) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. Unmarshals from milliseconds. Supports JSON null.
func (*UnixMilli) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.