nullable

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Unlicense Imports: 5 Imported by: 0

Documentation

Overview

Package nullable provides nullable value types with SQL and JSON support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	NullableBase[bool]
}

Bool represents a nullable bool.

func NewBool

func NewBool(value bool) Bool

NewBool returns a non-null Bool containing value.

func NewNullBool

func NewNullBool() Bool

NewNullBool returns a null Bool.

func (Bool) Equal

func (nv Bool) Equal(value Bool) bool

Equal reports whether nv and value are both null or contain the same bool.

type Byte

type Byte = UInt8

Byte is an alias for UInt8.

type Float32

type Float32 struct {
	NullableBase[float32]
}

Float32 represents a nullable float32.

func NewFloat32

func NewFloat32(value float32) Float32

NewFloat32 returns a non-null Float32 containing value.

func NewNullFloat32

func NewNullFloat32() Float32

NewNullFloat32 returns a null Float32.

func (Float32) Equal

func (nv Float32) Equal(value Float32) bool

Equal reports whether nv and value are both null or contain equal float32 values.

func (Float32) EqualBits

func (nv Float32) EqualBits(value Float32) bool

EqualBits reports whether nv and value are both null or have the same float32 bit pattern.

func (Float32) EqualEpsilon

func (nv Float32) EqualEpsilon(value Float32, epsilon float32) bool

EqualEpsilon reports whether nv and value are both null or differ by at most epsilon. It panics if epsilon is negative or NaN.

type Float64

type Float64 struct {
	NullableBase[float64]
}

Float64 represents a nullable float64.

func NewFloat64

func NewFloat64(value float64) Float64

NewFloat64 returns a non-null Float64 containing value.

func NewNullFloat64

func NewNullFloat64() Float64

NewNullFloat64 returns a null Float64.

func (Float64) Equal

func (nv Float64) Equal(value Float64) bool

Equal reports whether nv and value are both null or contain equal float64 values.

func (Float64) EqualBits

func (nv Float64) EqualBits(value Float64) bool

EqualBits reports whether nv and value are both null or have the same float64 bit pattern.

func (Float64) EqualEpsilon

func (nv Float64) EqualEpsilon(value Float64, epsilon float64) bool

EqualEpsilon reports whether nv and value are both null or differ by at most epsilon. It panics if epsilon is negative or NaN.

type Int

type Int struct {
	NullableBase[int]
}

Int represents a nullable int.

func NewInt

func NewInt(value int) Int

NewInt returns a non-null Int containing value.

func NewNullInt

func NewNullInt() Int

NewNullInt returns a null Int.

func (Int) Equal

func (nv Int) Equal(value Int) bool

Equal reports whether nv and value are both null or contain the same int.

type Int8

type Int8 struct {
	NullableBase[int8]
}

Int8 represents a nullable int8.

func NewInt8

func NewInt8(value int8) Int8

NewInt8 returns a non-null Int8 containing value.

func NewNullInt8

func NewNullInt8() Int8

NewNullInt8 returns a null Int8.

func (Int8) Equal

func (nv Int8) Equal(value Int8) bool

Equal reports whether nv and value are both null or contain the same int8.

type Int16

type Int16 struct {
	NullableBase[int16]
}

Int16 represents a nullable int16.

func NewInt16

func NewInt16(value int16) Int16

NewInt16 returns a non-null Int16 containing value.

func NewNullInt16

func NewNullInt16() Int16

NewNullInt16 returns a null Int16.

func (Int16) Equal

func (nv Int16) Equal(value Int16) bool

Equal reports whether nv and value are both null or contain the same int16.

type Int32

type Int32 struct {
	NullableBase[int32]
}

Int32 represents a nullable int32.

func NewInt32

func NewInt32(value int32) Int32

NewInt32 returns a non-null Int32 containing value.

func NewNullInt32

func NewNullInt32() Int32

NewNullInt32 returns a null Int32.

func (Int32) Equal

func (nv Int32) Equal(value Int32) bool

Equal reports whether nv and value are both null or contain the same int32.

type Int64

type Int64 struct {
	NullableBase[int64]
}

Int64 represents a nullable int64.

func NewInt64

func NewInt64(value int64) Int64

NewInt64 returns a non-null Int64 containing value.

func NewNullInt64

func NewNullInt64() Int64

NewNullInt64 returns a null Int64.

func (Int64) Equal

func (nv Int64) Equal(value Int64) bool

Equal reports whether nv and value are both null or contain the same int64.

type NullableBase

type NullableBase[T any] struct {
	// contains filtered or unexported fields
}

NullableBase stores a nullable value and implements SQL and JSON interfaces.

func NewNullableBase

func NewNullableBase[T any](value T) NullableBase[T]

NewNullableBase returns a non-null NullableBase containing value.

func (NullableBase[T]) IsNull

func (nv NullableBase[T]) IsNull() bool

IsNull reports whether the receiver is null.

func (NullableBase[T]) MarshalJSON

func (nv NullableBase[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes null when the receiver is null.

func (NullableBase[T]) RawValue

func (nv NullableBase[T]) RawValue() T

RawValue returns the stored value without checking whether it is null.

func (*NullableBase[T]) Scan

func (nv *NullableBase[T]) Scan(src any) error

Scan stores a database value using sql.Null scanning rules.

func (*NullableBase[T]) SetNull

func (nv *NullableBase[T]) SetNull()

SetNull marks the receiver as null and clears the stored value.

func (*NullableBase[T]) SetSqlNull

func (nv *NullableBase[T]) SetSqlNull(value sql.Null[T])

SetSqlNull stores the value and null state from sql.Null.

func (*NullableBase[T]) SetValue

func (nv *NullableBase[T]) SetValue(value T)

SetValue stores value and marks the receiver as non-null.

func (NullableBase[T]) SqlNull

func (nv NullableBase[T]) SqlNull() sql.Null[T]

SqlNull returns a sql.Null with the same value and null state.

func (*NullableBase[T]) UnmarshalJSON

func (nv *NullableBase[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON stores null for JSON null, otherwise stores the decoded value.

func (NullableBase[T]) Value

func (nv NullableBase[T]) Value() (driver.Value, error)

Value returns nil for null values, otherwise the converted driver value.

func (NullableBase[T]) ValueOrZero

func (nv NullableBase[T]) ValueOrZero() T

ValueOrZero returns the stored value, or the zero value when it is null.

type Rune

type Rune = Int32

Rune is an alias for Int32.

type String

type String struct {
	NullableBase[string]
}

String represents a nullable string.

func NewNullString

func NewNullString() String

NewNullString returns a null String.

func NewString

func NewString(value string) String

NewString returns a non-null String containing value.

func (String) Equal

func (nv String) Equal(value String) bool

Equal reports whether nv and value are both null or contain the same string.

type Time

type Time struct {
	NullableBase[time.Time]
}

Time represents a nullable time.Time.

func NewNullTime

func NewNullTime() Time

NewNullTime returns a null Time.

func NewTime

func NewTime(value time.Time) Time

NewTime returns a non-null Time containing value.

func (Time) Equal

func (nv Time) Equal(value Time) bool

Equal reports whether nv and value are both null or contain equal time values.

type UInt

type UInt struct {
	NullableBase[uint]
}

UInt represents a nullable uint.

func NewNullUInt

func NewNullUInt() UInt

NewNullUInt returns a null UInt.

func NewUInt

func NewUInt(value uint) UInt

NewUInt returns a non-null UInt containing value.

func (UInt) Equal

func (nv UInt) Equal(value UInt) bool

Equal reports whether nv and value are both null or contain the same uint.

type UInt8

type UInt8 struct {
	NullableBase[uint8]
}

UInt8 represents a nullable uint8.

func NewNullUInt8

func NewNullUInt8() UInt8

NewNullUInt8 returns a null UInt8.

func NewUInt8

func NewUInt8(value uint8) UInt8

NewUInt8 returns a non-null UInt8 containing value.

func (UInt8) Equal

func (nv UInt8) Equal(value UInt8) bool

Equal reports whether nv and value are both null or contain the same uint8.

type UInt16

type UInt16 struct {
	NullableBase[uint16]
}

UInt16 represents a nullable uint16.

func NewNullUInt16

func NewNullUInt16() UInt16

NewNullUInt16 returns a null UInt16.

func NewUInt16

func NewUInt16(value uint16) UInt16

NewUInt16 returns a non-null UInt16 containing value.

func (UInt16) Equal

func (nv UInt16) Equal(value UInt16) bool

Equal reports whether nv and value are both null or contain the same uint16.

type UInt32

type UInt32 struct {
	NullableBase[uint32]
}

UInt32 represents a nullable uint32.

func NewNullUInt32

func NewNullUInt32() UInt32

NewNullUInt32 returns a null UInt32.

func NewUInt32

func NewUInt32(value uint32) UInt32

NewUInt32 returns a non-null UInt32 containing value.

func (UInt32) Equal

func (nv UInt32) Equal(value UInt32) bool

Equal reports whether nv and value are both null or contain the same uint32.

type UInt64

type UInt64 struct {
	NullableBase[uint64]
}

UInt64 represents a nullable uint64.

func NewNullUInt64

func NewNullUInt64() UInt64

NewNullUInt64 returns a null UInt64.

func NewUInt64

func NewUInt64(value uint64) UInt64

NewUInt64 returns a non-null UInt64 containing value.

func (UInt64) Equal

func (nv UInt64) Equal(value UInt64) bool

Equal reports whether nv and value are both null or contain the same uint64.

Jump to

Keyboard shortcuts

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