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 ¶
- func BoolToPtr(nb sql.NullBool) *bool
- func Float32ToPtr(nf sql.NullFloat64) *float32
- func Float64ToPtr(nf sql.NullFloat64) *float64
- func Int16ToPtr(ni sql.NullInt16) *int16
- func Int32ToPtr(ni sql.NullInt32) *int32
- func Int64ToPtr(ni sql.NullInt64) *int64
- func StringToPtr(ns sql.NullString) *string
- func TimeToPtr(nt sql.NullTime) *time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolToPtr ¶
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 ¶
Int16ToPtr converts a sql.NullInt16 to a *int16. Returns a pointer to the int16 value if Valid is true, nil otherwise.
func Int32ToPtr ¶
Int32ToPtr converts a sql.NullInt32 to a *int32. Returns a pointer to the int32 value if Valid is true, nil otherwise.
func Int64ToPtr ¶
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.
Types ¶
This section is empty.