Documentation
¶
Index ¶
- func Bool(val any) sql.NullBool
- func BoolAny(nullBool sql.NullBool) driver.Value
- func BoolNil(nullBool sql.NullBool) *bool
- func Byte(val any) sql.NullByte
- func ByteAny(nullBool sql.NullByte) driver.Value
- func ByteNil(nullByte sql.NullByte) *byte
- func Float64(val any) sql.NullFloat64
- func Float64Any(nullInt sql.NullFloat64) driver.Value
- func FloatNil(nullFloat sql.NullFloat64) *float64
- func Int16(val any) sql.NullInt16
- func Int16Any(nullInt sql.NullInt16) driver.Value
- func Int16Nil(nullInt sql.NullInt16) *int16
- func Int32(val any) sql.NullInt32
- func Int32Any(nullInt sql.NullInt32) driver.Value
- func Int32Nil(nullInt sql.NullInt32) *int32
- func Int64(val any) sql.NullInt64
- func Int64Any(nullInt sql.NullInt64) driver.Value
- func Int64Nil(nullInt sql.NullInt64) *int64
- func NowTime() sql.NullTime
- func String(val any) sql.NullString
- func StringAny(nullString sql.NullString) driver.Value
- func StringNil(nullString sql.NullString) *string
- func Time(val any) sql.NullTime
- func TimeAny(nullTime sql.NullTime) driver.Value
- func TimeNil(nullTime sql.NullTime) *time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool creates a sql.NullBool from various input types. This function provides a convenient way to create nullable boolean values for database operations, handling both direct values and pointers.
Parameters:
- val (any): The input value to convert. Supported types:
- bool: Creates a valid NullBool with the given boolean value
- *bool: Creates a valid NullBool from pointer (nil pointer creates invalid NullBool)
- any other type: Creates an invalid NullBool with false value
Returns:
- sql.NullBool: A NullBool struct with appropriate Valid flag and Bool value.
Examples:
// From bool value
nullBool := Bool(true) // Returns: {Bool: true, Valid: true}
// From bool pointer
boolPtr := &true
nullBool := Bool(boolPtr) // Returns: {Bool: true, Valid: true}
// From nil pointer
nullBool := Bool((*bool)(nil)) // Returns: {Bool: false, Valid: false}
// From unsupported type
nullBool := Bool("invalid") // Returns: {Bool: false, Valid: false}
func BoolAny ¶ added in v1.8.0
BoolAny converts a sql.NullBool to a driver.Value for database operations. This function is typically used when you need to pass a nullable boolean value to database driver operations.
Parameters:
- nullBool (sql.NullBool): The nullable boolean value to convert.
Returns:
- driver.Value: The boolean value if valid, or nil if the NullBool is invalid/null.
Example:
nullBool := sql.NullBool{Bool: true, Valid: true}
value := BoolAny(nullBool) // Returns: true
invalidBool := sql.NullBool{Bool: false, Valid: false}
value := BoolAny(invalidBool) // Returns: nil
func BoolNil ¶ added in v1.8.0
BoolNil converts a sql.NullBool to a pointer to bool (*bool). This function is useful when you need to work with nullable boolean values in your application logic, where nil represents a null database value.
Parameters:
- nullBool (sql.NullBool): The nullable boolean value to convert.
Returns:
- *bool: A pointer to the boolean value if valid, or nil if the NullBool is invalid/null.
Example:
nullBool := sql.NullBool{Bool: true, Valid: true}
ptr := BoolNil(nullBool) // Returns: &true
invalidBool := sql.NullBool{Bool: false, Valid: false}
ptr := BoolNil(invalidBool) // Returns: nil
func Byte ¶
Byte creates a sql.NullByte from various input types. This function provides a convenient way to create nullable byte values for database operations, handling both direct values and pointers.
Parameters:
- val (any): The input value to convert. Supported types:
- byte: Creates a valid NullByte with the given byte value
- *byte: Creates a valid NullByte from pointer (nil pointer creates invalid NullByte)
- any other type: Creates an invalid NullByte with zero value
Returns:
- sql.NullByte: A NullByte struct with appropriate Valid flag and Byte value.
Examples:
// From byte value
nullByte := Byte(byte(65)) // Returns: {Byte: 65, Valid: true}
// From byte pointer
bytePtr := byte(97)
nullByte := Byte(&bytePtr) // Returns: {Byte: 97, Valid: true}
// From nil pointer
nullByte := Byte((*byte)(nil)) // Returns: {Byte: 0, Valid: false}
// From unsupported type
nullByte := Byte("invalid") // Returns: {Byte: 0, Valid: false}
func ByteAny ¶ added in v1.8.0
ByteAny converts a sql.NullByte to a driver.Value for database operations. This function is typically used when you need to pass a nullable byte value to database driver operations.
Parameters:
- nullBool (sql.NullByte): The nullable byte value to convert.
Returns:
- driver.Value: The byte value if valid, or nil if the NullByte is invalid/null.
Example:
nullByte := sql.NullByte{Byte: 65, Valid: true}
value := ByteAny(nullByte) // Returns: 65
invalidByte := sql.NullByte{Byte: 0, Valid: false}
value := ByteAny(invalidByte) // Returns: nil
func ByteNil ¶ added in v1.8.0
ByteNil converts a sql.NullByte to a pointer to byte (*byte). This function is useful when you need to work with nullable byte values in your application logic, where nil represents a null database value.
Parameters:
- nullByte (sql.NullByte): The nullable byte value to convert.
Returns:
- *byte: A pointer to the byte value if valid, or nil if the NullByte is invalid/null.
Example:
nullByte := sql.NullByte{Byte: 65, Valid: true}
ptr := ByteNil(nullByte) // Returns: &65
invalidByte := sql.NullByte{Byte: 0, Valid: false}
ptr := ByteNil(invalidByte) // Returns: nil
func Float64 ¶
func Float64(val any) sql.NullFloat64
Float64 creates a sql.NullFloat64 from various input types. This function provides a convenient way to create nullable float64 values for database operations, handling both direct values and pointers.
Parameters:
- val (any): The input value to convert. Supported types:
- float64: Creates a valid NullFloat64 with the given float64 value
- *float64: Creates a valid NullFloat64 from pointer (nil pointer creates invalid NullFloat64)
- any other type: Creates an invalid NullFloat64 with zero value
Returns:
- sql.NullFloat64: A NullFloat64 struct with appropriate Valid flag and Float64 value.
Examples:
// From float64 value
nullFloat := Float64(3.14) // Returns: {Float64: 3.14, Valid: true}
// From float64 pointer
floatPtr := 2.71
nullFloat := Float64(&floatPtr) // Returns: {Float64: 2.71, Valid: true}
// From nil pointer
nullFloat := Float64((*float64)(nil)) // Returns: {Float64: 0, Valid: false}
// From unsupported type
nullFloat := Float64("invalid") // Returns: {Float64: 0, Valid: false}
func Float64Any ¶ added in v1.8.0
func Float64Any(nullInt sql.NullFloat64) driver.Value
Float64Any converts a sql.NullFloat64 to a driver.Value for database operations. This function is typically used when you need to pass a nullable float64 value to database driver operations.
Parameters:
- nullInt (sql.NullFloat64): The nullable float64 value to convert.
Returns:
- driver.Value: The float64 value if valid, or nil if the NullFloat64 is invalid/null.
Example:
nullFloat := sql.NullFloat64{Float64: 3.14, Valid: true}
value := Float64Any(nullFloat) // Returns: 3.14
invalidFloat := sql.NullFloat64{Float64: 0, Valid: false}
value := Float64Any(invalidFloat) // Returns: nil
func FloatNil ¶ added in v1.8.0
func FloatNil(nullFloat sql.NullFloat64) *float64
FloatNil converts a sql.NullFloat64 to a pointer to float64 (*float64). This function is useful when you need to work with nullable float64 values in your application logic, where nil represents a null database value.
Parameters:
- nullFloat (sql.NullFloat64): The nullable float64 value to convert.
Returns:
- *float64: A pointer to the float64 value if valid, or nil if the NullFloat64 is invalid/null.
Example:
nullFloat := sql.NullFloat64{Float64: 3.14, Valid: true}
ptr := FloatNil(nullFloat) // Returns: &3.14
invalidFloat := sql.NullFloat64{Float64: 0, Valid: false}
ptr := FloatNil(invalidFloat) // Returns: nil
func Int16 ¶
Int16 creates a sql.NullInt16 from various input types. This function provides a convenient way to create nullable int16 values for database operations, handling both direct values and pointers.
Parameters:
- val (any): The input value to convert. Supported types:
- int16: Creates a valid NullInt16 with the given int16 value
- *int16: Creates a valid NullInt16 from pointer (nil pointer creates invalid NullInt16)
- any other type: Creates an invalid NullInt16 with zero value
Returns:
- sql.NullInt16: A NullInt16 struct with appropriate Valid flag and Int16 value.
Examples:
// From int16 value
nullInt := Int16(int16(42)) // Returns: {Int16: 42, Valid: true}
// From int16 pointer
intPtr := int16(100)
nullInt := Int16(&intPtr) // Returns: {Int16: 100, Valid: true}
// From nil pointer
nullInt := Int16((*int16)(nil)) // Returns: {Int16: 0, Valid: false}
// From unsupported type
nullInt := Int16("invalid") // Returns: {Int16: 0, Valid: false}
func Int16Any ¶ added in v1.8.0
Int16Any converts a sql.NullInt16 to a driver.Value for database operations. This function is typically used when you need to pass a nullable int16 value to database driver operations.
Parameters:
- nullInt (sql.NullInt16): The nullable int16 value to convert.
Returns:
- driver.Value: The int16 value if valid, or nil if the NullInt16 is invalid/null.
Example:
nullInt := sql.NullInt16{Int16: 42, Valid: true}
value := Int16Any(nullInt) // Returns: 42
invalidInt := sql.NullInt16{Int16: 0, Valid: false}
value := Int16Any(invalidInt) // Returns: nil
func Int16Nil ¶ added in v1.8.0
Int16Nil converts a sql.NullInt16 to a pointer to int16 (*int16). This function is useful when you need to work with nullable int16 values in your application logic, where nil represents a null database value.
Parameters:
- nullInt (sql.NullInt16): The nullable int16 value to convert.
Returns:
- *int16: A pointer to the int16 value if valid, or nil if the NullInt16 is invalid/null.
Example:
nullInt := sql.NullInt16{Int16: 42, Valid: true}
ptr := Int16Nil(nullInt) // Returns: &42
invalidInt := sql.NullInt16{Int16: 0, Valid: false}
ptr := Int16Nil(invalidInt) // Returns: nil
func Int32 ¶
Int32 creates a sql.NullInt32 from various input types. This function provides a convenient way to create nullable int32 values for database operations, handling both direct values and pointers.
Parameters:
- val (any): The input value to convert. Supported types:
- int32: Creates a valid NullInt32 with the given int32 value
- *int32: Creates a valid NullInt32 from pointer (nil pointer creates invalid NullInt32)
- any other type: Creates an invalid NullInt32 with zero value
Returns:
- sql.NullInt32: A NullInt32 struct with appropriate Valid flag and Int32 value.
Examples:
// From int32 value
nullInt := Int32(int32(42)) // Returns: {Int32: 42, Valid: true}
// From int32 pointer
intPtr := int32(100)
nullInt := Int32(&intPtr) // Returns: {Int32: 100, Valid: true}
// From nil pointer
nullInt := Int32((*int32)(nil)) // Returns: {Int32: 0, Valid: false}
// From unsupported type
nullInt := Int32("invalid") // Returns: {Int32: 0, Valid: false}
func Int32Any ¶ added in v1.8.0
Int32Any converts a sql.NullInt32 to a driver.Value for database operations. This function is typically used when you need to pass a nullable int32 value to database driver operations.
Parameters:
- nullInt (sql.NullInt32): The nullable int32 value to convert.
Returns:
- driver.Value: The int32 value if valid, or nil if the NullInt32 is invalid/null.
Example:
nullInt := sql.NullInt32{Int32: 42, Valid: true}
value := Int32Any(nullInt) // Returns: 42
invalidInt := sql.NullInt32{Int32: 0, Valid: false}
value := Int32Any(invalidInt) // Returns: nil
func Int32Nil ¶ added in v1.8.0
Int32Nil converts a sql.NullInt32 to a pointer to int32 (*int32). This function is useful when you need to work with nullable int32 values in your application logic, where nil represents a null database value.
Parameters:
- nullInt (sql.NullInt32): The nullable int32 value to convert.
Returns:
- *int32: A pointer to the int32 value if valid, or nil if the NullInt32 is invalid/null.
Example:
nullInt := sql.NullInt32{Int32: 42, Valid: true}
ptr := Int32Nil(nullInt) // Returns: &42
invalidInt := sql.NullInt32{Int32: 0, Valid: false}
ptr := Int32Nil(invalidInt) // Returns: nil
func Int64 ¶
Int64 creates a sql.NullInt64 from various input types. This function provides a convenient way to create nullable int64 values for database operations, handling both direct values and pointers.
Parameters:
- val (any): The input value to convert. Supported types:
- int64: Creates a valid NullInt64 with the given int64 value
- *int64: Creates a valid NullInt64 from pointer (nil pointer creates invalid NullInt64)
- any other type: Creates an invalid NullInt64 with zero value
Returns:
- sql.NullInt64: A NullInt64 struct with appropriate Valid flag and Int64 value.
Examples:
// From int64 value
nullInt := Int64(int64(42)) // Returns: {Int64: 42, Valid: true}
// From int64 pointer
intPtr := int64(100)
nullInt := Int64(&intPtr) // Returns: {Int64: 100, Valid: true}
// From nil pointer
nullInt := Int64((*int64)(nil)) // Returns: {Int64: 0, Valid: false}
// From unsupported type
nullInt := Int64("invalid") // Returns: {Int64: 0, Valid: false}
func Int64Any ¶ added in v1.8.0
Int64Any converts a sql.NullInt64 to a driver.Value for database operations. This function is typically used when you need to pass a nullable int64 value to database driver operations.
Parameters:
- nullInt (sql.NullInt64): The nullable int64 value to convert.
Returns:
- driver.Value: The int64 value if valid, or nil if the NullInt64 is invalid/null.
Example:
nullInt := sql.NullInt64{Int64: 42, Valid: true}
value := Int64Any(nullInt) // Returns: 42
invalidInt := sql.NullInt64{Int64: 0, Valid: false}
value := Int64Any(invalidInt) // Returns: nil
func Int64Nil ¶ added in v1.8.0
Int64Nil converts a sql.NullInt64 to a pointer to int64 (*int64). This function is useful when you need to work with nullable int64 values in your application logic, where nil represents a null database value.
Parameters:
- nullInt (sql.NullInt64): The nullable int64 value to convert.
Returns:
- *int64: A pointer to the int64 value if valid, or nil if the NullInt64 is invalid/null.
Example:
nullInt := sql.NullInt64{Int64: 42, Valid: true}
ptr := Int64Nil(nullInt) // Returns: &42
invalidInt := sql.NullInt64{Int64: 0, Valid: false}
ptr := Int64Nil(invalidInt) // Returns: nil
func NowTime ¶
NowTime creates a sql.NullTime with the current time. This is a convenience function that creates a valid NullTime using the current system time, equivalent to calling Time(time.Now()).
Returns:
- sql.NullTime: A valid NullTime struct with the current time and Valid set to true.
Example:
nullTime := NowTime() // Returns: {Time: <current time>, Valid: true}
// Equivalent to:
nullTime := Time(time.Now())
func String ¶
func String(val any) sql.NullString
String creates a sql.NullString from various input types. This function provides a convenient way to create nullable string values for database operations, handling both direct values and pointers.
Parameters:
- val (any): The input value to convert. Supported types:
- string: Creates a valid NullString with the given string value
- *string: Creates a valid NullString from pointer (nil pointer creates invalid NullString)
- any other type: Creates an invalid NullString with empty string value
Returns:
- sql.NullString: A NullString struct with appropriate Valid flag and String value.
Examples:
// From string value
nullString := String("hello") // Returns: {String: "hello", Valid: true}
// From string pointer
strPtr := &"world"
nullString := String(strPtr) // Returns: {String: "world", Valid: true}
// From nil pointer
nullString := String((*string)(nil)) // Returns: {String: "", Valid: false}
// From unsupported type
nullString := String(123) // Returns: {String: "", Valid: false}
func StringAny ¶ added in v1.8.0
func StringAny(nullString sql.NullString) driver.Value
StringAny converts a sql.NullString to a driver.Value for database operations. This function is typically used when you need to pass a nullable string value to database driver operations.
Parameters:
- nullString (sql.NullString): The nullable string value to convert.
Returns:
- driver.Value: The string value if valid, or nil if the NullString is invalid/null.
Example:
nullString := sql.NullString{String: "hello", Valid: true}
value := StringAny(nullString) // Returns: "hello"
invalidString := sql.NullString{String: "", Valid: false}
value := StringAny(invalidString) // Returns: nil
func StringNil ¶ added in v1.8.0
func StringNil(nullString sql.NullString) *string
StringNil converts a sql.NullString to a pointer to string (*string). This function is useful when you need to work with nullable string values in your application logic, where nil represents a null database value.
Parameters:
- nullString (sql.NullString): The nullable string value to convert.
Returns:
- *string: A pointer to the string value if valid, or nil if the NullString is invalid/null.
Example:
nullString := sql.NullString{String: "hello", Valid: true}
ptr := StringNil(nullString) // Returns: &"hello"
invalidString := sql.NullString{String: "", Valid: false}
ptr := StringNil(invalidString) // Returns: nil
func Time ¶
Time creates a sql.NullTime from various input types. This function provides a convenient way to create nullable time.Time values for database operations, handling both direct values and pointers.
Parameters:
- val (any): The input value to convert. Supported types:
- time.Time: Creates a valid NullTime with the given time.Time value
- *time.Time: Creates a valid NullTime from pointer (nil pointer creates invalid NullTime)
- any other type: Creates an invalid NullTime with zero time value
Returns:
- sql.NullTime: A NullTime struct with appropriate Valid flag and Time value.
Examples:
// From time.Time value
now := time.Now()
nullTime := Time(now) // Returns: {Time: now, Valid: true}
// From time.Time pointer
timePtr := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
nullTime := Time(&timePtr) // Returns: {Time: timePtr, Valid: true}
// From nil pointer
nullTime := Time((*time.Time)(nil)) // Returns: {Time: time.Time{}, Valid: false}
// From unsupported type
nullTime := Time("invalid") // Returns: {Time: time.Time{}, Valid: false}
func TimeAny ¶ added in v1.8.0
TimeAny converts a sql.NullTime to a driver.Value for database operations. This function is typically used when you need to pass a nullable time.Time value to database driver operations.
Parameters:
- nullTime (sql.NullTime): The nullable time.Time value to convert.
Returns:
- driver.Value: The time.Time value if valid, or nil if the NullTime is invalid/null.
Example:
now := time.Now()
nullTime := sql.NullTime{Time: now, Valid: true}
value := TimeAny(nullTime) // Returns: now
invalidTime := sql.NullTime{Time: time.Time{}, Valid: false}
value := TimeAny(invalidTime) // Returns: nil
func TimeNil ¶ added in v1.8.0
TimeNil converts a sql.NullTime to a pointer to time.Time (*time.Time). This function is useful when you need to work with nullable time.Time values in your application logic, where nil represents a null database value.
Parameters:
- nullTime (sql.NullTime): The nullable time.Time value to convert.
Returns:
- *time.Time: A pointer to the time.Time value if valid, or nil if the NullTime is invalid/null.
Example:
now := time.Now()
nullTime := sql.NullTime{Time: now, Valid: true}
ptr := TimeNil(nullTime) // Returns: &now
invalidTime := sql.NullTime{Time: time.Time{}, Valid: false}
ptr := TimeNil(invalidTime) // Returns: nil
Types ¶
This section is empty.