null

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

null makes it easier to deal with values that could be null or undefined. Armaria deals with databases and JSON a fair bit. Both of these things make use of NULL. The abstractions in this file allow us to support NULL robustly for both of them. The abstractions also keep track of whether a field was set at all which is useful for optional params. This is largely based on the excellent ideas in this package: https://github.com/guregu/null

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PtrFromNullInt64

func PtrFromNullInt64(num NullInt64) *int64

PtrFromNullInt64 converts a NullInt64 to a *int64. If the NullInt64 is not Valid nil is returned.

func PtrFromNullString

func PtrFromNullString(str NullString) *string

PtrFromNullString converts a NullString to a *string. If the NullString is not Valid nil is returned.

Types

type NullInt64

type NullInt64 struct {
	sql.NullInt64      // allows use with sql/database and grants null support (null if Valid = false)
	Dirty         bool // tracks if the argument has been provided at all (provided if Dirty = true)
}

NullInt64 is an int64 that can be NULL.

func NullInt64From

func NullInt64From(num int64) NullInt64

NullInt64From converts an int to a NullInt. If the int is zero it will be treated as null. The returned NullInt64 will have Dirty set to true.

func NullInt64FromPtr

func NullInt64FromPtr(num *int64) NullInt64

NullInt64FromPtr converts a *int64 to a NullInt64. If the int64 is nil it will be treated as null. The returned NullInt64 will have Dirty set to true.

func (NullInt64) MarshalJSON

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

MarshalJSON marshalls a NullInt64 to JSON.

func (*NullInt64) UnmarshalJSON

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

UnmarshalJSON unmarshalls a NullInt64 from JSON.

type NullString

type NullString struct {
	sql.NullString      // allows use with sql/database and grants null support (null if Valid = false)
	Dirty          bool // tracks if the argument has been provided at all (provided if Dirty = true)
}

NullString is a string that can be NULL.

func NullStringFrom

func NullStringFrom(str string) NullString

NullStringFrom converts a string to a NullString. The returned NullString will have Dirty set to true.

func NullStringFromPtr

func NullStringFromPtr(str *string) NullString

NullStringFromPtr converts a *string to a NullString. If the string is nil it will be treated as null. The returned NullString will have Dirty set to true.

func (NullString) MarshalJSON

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

MarshalJSON marshalls a NullString to JSON.

func (*NullString) UnmarshalJSON

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

UnmarshalJSON unmarshalls a NullString from JSON.

Jump to

Keyboard shortcuts

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