types

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 13 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CantDecodeHex

func CantDecodeHex(err error, s string) error

CantDecodeHex wraps the given error with the given string that cannot be hex-decoded.

func CantParseFloat64

func CantParseFloat64(err error, s string) error

CantParseFloat64 wraps the given error with the specified string that cannot be parsed into float64.

func CantParseInt64

func CantParseInt64(err error, s string) error

CantParseInt64 wraps the given error with the specified string that cannot be parsed into int64.

func CantParseUint64

func CantParseUint64(err error, s string) error

CantParseUint64 wraps the given error with the specified string that cannot be parsed into uint64.

func CantUnmarshalYAML

func CantUnmarshalYAML(err error, v any) error

CantUnmarshalYAML wraps the given error with the designated value, which cannot be unmarshalled into.

func MarshalJSON

func MarshalJSON(v any) ([]byte, error)

MarshalJSON calls json.Marshal and wraps any resulting errors.

func Name

func Name(t any) string

Name returns the declared name of type t.

func TransformEmptyStringListToNull added in v0.10.0

func TransformEmptyStringListToNull(n *StringList)

TransformEmptyStringListToNull transforms a valid StringList carrying an empty slice to a SQL NULL.

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 TransformNilUUIDToNull added in v0.10.0

func TransformNilUUIDToNull(u *UUID)

TransformNilUUIDToNull transforms a valid UUID carrying a nil value 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

func UnmarshalJSON(data []byte, v any) error

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

func (binary Binary) MarshalJSON() ([]byte, error)

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

func (binary Binary) MarshalText() ([]byte, error)

MarshalText implements a custom marhsal function to encode the Binary as hex. MarshalText implements the encoding.TextMarshaler interface.

func (*Binary) Scan

func (binary *Binary) Scan(src any) error

Scan implements the sql.Scanner interface. Supports SQL NULL.

func (Binary) String

func (binary Binary) String() string

String returns the hex string representation form of the Binary.

func (*Binary) UnmarshalJSON

func (binary *Binary) UnmarshalJSON(data []byte) error

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

func (binary *Binary) UnmarshalText(text []byte) error

UnmarshalText implements a custom unmarshal function to decode hex into a Binary. UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Binary) Valid

func (binary Binary) Valid() bool

Valid returns whether the Binary is valid.

func (Binary) Value

func (binary Binary) Value() (driver.Value, error)

Value implements the driver.Valuer interface. Supports SQL NULL.

type Bool

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

Bool represents a bool for ENUM ('y', 'n'), which can be NULL.

func MakeBool added in v0.8.0

func MakeBool(bi bool, transformers ...func(*Bool)) Bool

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

func (b Bool) IsZero() bool

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

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

MarshalJSON implements the json.Marshaler interface.

func (*Bool) Scan

func (b *Bool) Scan(src any) error

Scan implements the sql.Scanner interface. Supports SQL NULL.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Bool) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Bool) Value

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

Value implements the driver.Valuer interface. Supports SQL NULL.

type Float

type Float struct {
	sql.NullFloat64
}

Float adds JSON support to sql.NullFloat64.

func (Float) MarshalJSON

func (f Float) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. Supports JSON null.

func (*Float) UnmarshalJSON

func (f *Float) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. Supports JSON null.

func (*Float) UnmarshalText

func (f *Float) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Int

type Int struct {
	sql.NullInt64
}

Int adds JSON support to sql.NullInt64.

func MakeInt added in v0.7.0

func MakeInt(in int64, transformers ...func(*Int)) Int

MakeInt constructs a new Int.

Multiple transformer functions can be given, each transforming the generated Int, e.g., TransformZeroIntToNull.

func (*Int) IsZero added in v0.10.0

func (i *Int) IsZero() bool

IsZero implements the json.isZeroer interface.

An Integer is considered zero if it is not valid regardless of the actual int64 value.

func (Int) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface. Supports JSON null.

func (*Int) UnmarshalJSON

func (i *Int) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. Supports JSON null.

func (*Int) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

type String

type String struct {
	sql.NullString
}

String adds JSON support to sql.NullString.

func MakeString

func MakeString(in string, transformers ...func(*String)) String

MakeString constructs a new String.

Multiple transformer functions can be given, each transforming the generated String, e.g., TransformEmptyStringToNull.

func (String) IsZero added in v0.10.0

func (s String) IsZero() bool

IsZero implements the json.isZeroer interface.

A String is considered zero if it is not valid regardless of the actual string value.

func (String) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface. Supports JSON null.

func (*String) UnmarshalJSON

func (s *String) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. Supports JSON null.

func (*String) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (String) Value

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

Value implements the driver.Valuer interface. Supports SQL NULL.

type StringList added in v0.10.0

type StringList struct {
	List  []string
	Valid bool
}

StringList is a nullable slice of strings that can be used with SQL databases and JSON serialization.

Its driver.Valuer implementation returns a JSON array of strings or NULL if the StringList is not valid.

func MakeStringList added in v0.10.0

func MakeStringList(in []string, transformers ...func(*StringList)) StringList

MakeStringList constructs a new StringList.

Multiple transformer functions can be given, each transforming the generated StringList, e.g., TransformEmptyStringListToNull.

func (StringList) IsZero added in v0.10.0

func (n StringList) IsZero() bool

IsZero implements the json.isZeroer interface.

A StringList is considered zero if it is not valid regardless of the actual List value.

func (StringList) MarshalJSON added in v0.10.0

func (n StringList) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*StringList) Scan added in v0.10.0

func (n *StringList) Scan(src any) error

Scan implements the SQL driver.Scanner interface.

func (*StringList) UnmarshalJSON added in v0.10.0

func (n *StringList) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (StringList) Value added in v0.10.0

func (n StringList) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type UUID

type UUID struct {
	uuid.NullUUID
}

UUID is like uuid.NullUUID, but marshals itself binarily (not like xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) in SQL.

func MakeUUID added in v0.10.0

func MakeUUID(in uuid.UUID, opts ...func(*UUID)) UUID

MakeUUID constructs a new UUID.

Multiple transformer functions can be given, each transforming the generated UUID, e.g., TransformNilUUIDToNull.

func (*UUID) IsZero added in v0.10.0

func (u *UUID) IsZero() bool

IsZero implements the json.isZeroer interface.

A NullUUID is considered zero if it is not valid regardless of the actual UUID value.

func (UUID) String added in v0.10.0

func (u UUID) String() string

String implements fmt.Stringer.

It is necessary to implement this method because the embedded NullUUID's doesn't embed the uuid.UUID type, but has it as a field, so the String() method of the UUID field of NullUUID is not promoted.

func (UUID) Value

func (u UUID) Value() (driver.Value, error)

Value implements driver.Valuer. Supports SQL NULL.

type UnixMilli

type UnixMilli time.Time

UnixMilli is a nullable millisecond UNIX timestamp in databases and JSON.

func (UnixMilli) MarshalJSON

func (t UnixMilli) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. Marshals to milliseconds. Supports JSON null.

func (UnixMilli) MarshalText

func (t UnixMilli) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*UnixMilli) Scan

func (t *UnixMilli) Scan(src any) error

Scan implements the sql.Scanner interface. Scans from milliseconds. Supports SQL NULL.

func (UnixMilli) Time

func (t UnixMilli) Time() time.Time

Time returns the time.Time conversion of UnixMilli.

func (*UnixMilli) UnmarshalJSON

func (t *UnixMilli) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. Unmarshals from milliseconds. Supports JSON null.

func (*UnixMilli) UnmarshalText

func (t *UnixMilli) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (UnixMilli) Value

func (t UnixMilli) Value() (driver.Value, error)

Value implements the driver.Valuer interface. Returns milliseconds. Supports SQL NULL.

Jump to

Keyboard shortcuts

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