null

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package null provides utilities for converting sql.Null* types to pointers. These functions help bridge the gap between database NULL values and Go's pointer types, making it easier to work with optional fields in structs and JSON serialization.

Example usage:

var ns sql.NullString
// ... populate ns from database query

// Convert to *string, nil if NULL
ptr := null.StringToPtr(ns)
if ptr != nil {
	fmt.Println("Value:", *ptr)
} else {
	fmt.Println("Value is NULL")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToPtr

func BoolToPtr(nb sql.NullBool) *bool

BoolToPtr converts a sql.NullBool to a *bool. Returns a pointer to the bool value if Valid is true, nil otherwise.

func Float32ToPtr

func Float32ToPtr(nf sql.NullFloat64) *float32

Float32ToPtr converts a sql.NullFloat64 to a *float32 with type conversion. Returns a pointer to the float32 value if Valid is true, nil otherwise. Note: This performs a float64 to float32 conversion which may lose precision.

func Float64ToPtr

func Float64ToPtr(nf sql.NullFloat64) *float64

Float64ToPtr converts a sql.NullFloat64 to a *float64. Returns a pointer to the float64 value if Valid is true, nil otherwise.

func Int16ToPtr

func Int16ToPtr(ni sql.NullInt16) *int16

Int16ToPtr converts a sql.NullInt16 to a *int16. Returns a pointer to the int16 value if Valid is true, nil otherwise.

func Int32ToPtr

func Int32ToPtr(ni sql.NullInt32) *int32

Int32ToPtr converts a sql.NullInt32 to a *int32. Returns a pointer to the int32 value if Valid is true, nil otherwise.

func Int64ToPtr

func Int64ToPtr(ni sql.NullInt64) *int64

Int64ToPtr converts a sql.NullInt64 to a *int64. Returns a pointer to the int64 value if Valid is true, nil otherwise.

func StringToPtr

func StringToPtr(ns sql.NullString) *string

StringToPtr converts a sql.NullString to a *string. Returns a pointer to the string value if Valid is true, nil otherwise.

func TimeToPtr

func TimeToPtr(nt sql.NullTime) *time.Time

TimeToPtr converts a sql.NullTime to a *time.Time. Returns a pointer to the time.Time value if Valid is true, nil otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

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