Skip to content

Commit ce7aa8a

Browse files
author
Dean Karn
authored
fix Option sql.Valuer (#49)
1 parent 348e7d6 commit ce7aa8a

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [5.28.1] - 2024-02-14
10+
### Fixed
11+
- Additional supported types, cast to `sql.Valuer` supported types, they need to be returned to the driver for evaluation.
12+
913
## [5.28.0] - 2024-02-13
1014
### Added
1115
- Additionally supported types, cast to `sql.Valuer` supported types.
@@ -116,7 +120,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
116120
### Added
117121
- Added `timext.NanoTime` for fast low level monotonic time with nanosecond precision.
118122

119-
[Unreleased]: https://github.com/go-playground/pkg/compare/v5.28.0...HEAD
123+
[Unreleased]: https://github.com/go-playground/pkg/compare/v5.28.1...HEAD
124+
[5.28.1]: https://github.com/go-playground/pkg/compare/v5.28.0..v5.28.1
120125
[5.28.0]: https://github.com/go-playground/pkg/compare/v5.27.0..v5.28.0
121126
[5.27.0]: https://github.com/go-playground/pkg/compare/v5.26.0..v5.27.0
122127
[5.26.0]: https://github.com/go-playground/pkg/compare/v5.25.0..v5.26.0

values/option/option_sql.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var (
2020
timeType = reflect.TypeOf((*time.Time)(nil)).Elem()
2121
stringType = reflect.TypeOf((*string)(nil)).Elem()
2222
int64Type = reflect.TypeOf((*int64)(nil)).Elem()
23-
uInt64Type = reflect.TypeOf((*uint64)(nil)).Elem()
2423
float64Type = reflect.TypeOf((*float64)(nil)).Elem()
2524
boolType = reflect.TypeOf((*bool)(nil)).Elem()
2625
)
@@ -43,15 +42,9 @@ func (o Option[T]) Value() (driver.Value, error) {
4342
return val.Convert(stringType).Interface(), nil
4443
case reflect.Bool:
4544
return val.Convert(boolType).Interface(), nil
46-
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
47-
n := val.Convert(uInt64Type).Interface().(uint64)
48-
if n > math.MaxInt64 {
49-
return math.MaxInt64, nil
50-
}
51-
return int64(n), nil
5245
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
5346
return val.Convert(int64Type).Interface(), nil
54-
case reflect.Float32, reflect.Float64:
47+
case reflect.Float64:
5548
return val.Convert(float64Type).Interface(), nil
5649
case reflect.Slice, reflect.Array:
5750
if val.Type().ConvertibleTo(byteSliceType) {

values/option/option_sql_go1.22.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ var (
1919
timeType = reflect.TypeFor[time.Time]()
2020
stringType = reflect.TypeFor[string]()
2121
int64Type = reflect.TypeFor[int64]()
22-
uInt64Type = reflect.TypeFor[uint64]()
2322
float64Type = reflect.TypeFor[float64]()
2423
boolType = reflect.TypeFor[bool]()
2524
)
@@ -42,15 +41,9 @@ func (o Option[T]) Value() (driver.Value, error) {
4241
return val.Convert(stringType).Interface(), nil
4342
case reflect.Bool:
4443
return val.Convert(boolType).Interface(), nil
45-
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
46-
n := val.Convert(uInt64Type).Interface().(uint64)
47-
if n > math.MaxInt64 {
48-
return math.MaxInt64, nil
49-
}
50-
return int64(n), nil
5144
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
5245
return val.Convert(int64Type).Interface(), nil
53-
case reflect.Float32, reflect.Float64:
46+
case reflect.Float64:
5447
return val.Convert(float64Type).Interface(), nil
5548
case reflect.Slice, reflect.Array:
5649
if val.Type().ConvertibleTo(byteSliceType) {

0 commit comments

Comments
 (0)