mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-13 14:34:25 +00:00
feat(spectypes): ✨ enhance SqlNull to support float and int types
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in -27m18s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in -26m43s
Build , Vet Test, and Lint / Lint Code (push) Successful in -26m48s
Build , Vet Test, and Lint / Build (push) Successful in -27m4s
Tests / Unit Tests (push) Successful in -27m26s
Tests / Integration Tests (push) Failing after -27m41s
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in -27m18s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in -26m43s
Build , Vet Test, and Lint / Lint Code (push) Successful in -26m48s
Build , Vet Test, and Lint / Build (push) Successful in -27m4s
Tests / Unit Tests (push) Successful in -27m26s
Tests / Integration Tests (push) Failing after -27m41s
* Add handling for float32 and float64 in Scan method. * Implement parsing for integer types in Scan and FromString methods. * Improve flexibility of SqlNull for various numeric inputs.
This commit is contained in:
@@ -74,6 +74,10 @@ func (n *SqlNull[T]) Scan(value any) error {
|
||||
return n.FromString(v)
|
||||
case []byte:
|
||||
return n.FromString(string(v))
|
||||
case float32, float64:
|
||||
return n.FromString(fmt.Sprintf("%f", value))
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
return n.FromString(fmt.Sprintf("%d", value))
|
||||
default:
|
||||
return n.FromString(fmt.Sprintf("%v", value))
|
||||
}
|
||||
@@ -94,6 +98,10 @@ func (n *SqlNull[T]) FromString(s string) error {
|
||||
reflect.ValueOf(&n.Val).Elem().SetInt(i)
|
||||
n.Valid = true
|
||||
}
|
||||
if f, err := strconv.ParseFloat(s, 64); err == nil {
|
||||
reflect.ValueOf(&n.Val).Elem().SetInt(int64(f))
|
||||
n.Valid = true
|
||||
}
|
||||
case float32, float64:
|
||||
if f, err := strconv.ParseFloat(s, 64); err == nil {
|
||||
reflect.ValueOf(&n.Val).Elem().SetFloat(f)
|
||||
|
||||
Reference in New Issue
Block a user