Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Option sql.Valuer #49

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [5.28.1] - 2024-02-14
### Fixed
- Additional supported types, cast to `sql.Valuer` supported types, they need to be returned to the driver for evaluation.

## [5.28.0] - 2024-02-13
### Added
- Additionally supported types, cast to `sql.Valuer` supported types.
Expand Down Expand Up @@ -116,7 +120,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added `timext.NanoTime` for fast low level monotonic time with nanosecond precision.

[Unreleased]: https://github.com/go-playground/pkg/compare/v5.28.0...HEAD
[Unreleased]: https://github.com/go-playground/pkg/compare/v5.28.1...HEAD
[5.28.1]: https://github.com/go-playground/pkg/compare/v5.28.0..v5.28.1
[5.28.0]: https://github.com/go-playground/pkg/compare/v5.27.0..v5.28.0
[5.27.0]: https://github.com/go-playground/pkg/compare/v5.26.0..v5.27.0
[5.26.0]: https://github.com/go-playground/pkg/compare/v5.25.0..v5.26.0
Expand Down
9 changes: 1 addition & 8 deletions values/option/option_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var (
timeType = reflect.TypeOf((*time.Time)(nil)).Elem()
stringType = reflect.TypeOf((*string)(nil)).Elem()
int64Type = reflect.TypeOf((*int64)(nil)).Elem()
uInt64Type = reflect.TypeOf((*uint64)(nil)).Elem()
float64Type = reflect.TypeOf((*float64)(nil)).Elem()
boolType = reflect.TypeOf((*bool)(nil)).Elem()
)
Expand All @@ -43,15 +42,9 @@ func (o Option[T]) Value() (driver.Value, error) {
return val.Convert(stringType).Interface(), nil
case reflect.Bool:
return val.Convert(boolType).Interface(), nil
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
n := val.Convert(uInt64Type).Interface().(uint64)
if n > math.MaxInt64 {
return math.MaxInt64, nil
}
return int64(n), nil
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return val.Convert(int64Type).Interface(), nil
case reflect.Float32, reflect.Float64:
case reflect.Float64:
return val.Convert(float64Type).Interface(), nil
case reflect.Slice, reflect.Array:
if val.Type().ConvertibleTo(byteSliceType) {
Expand Down
9 changes: 1 addition & 8 deletions values/option/option_sql_go1.22.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var (
timeType = reflect.TypeFor[time.Time]()
stringType = reflect.TypeFor[string]()
int64Type = reflect.TypeFor[int64]()
uInt64Type = reflect.TypeFor[uint64]()
float64Type = reflect.TypeFor[float64]()
boolType = reflect.TypeFor[bool]()
)
Expand All @@ -42,15 +41,9 @@ func (o Option[T]) Value() (driver.Value, error) {
return val.Convert(stringType).Interface(), nil
case reflect.Bool:
return val.Convert(boolType).Interface(), nil
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
n := val.Convert(uInt64Type).Interface().(uint64)
if n > math.MaxInt64 {
return math.MaxInt64, nil
}
return int64(n), nil
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return val.Convert(int64Type).Interface(), nil
case reflect.Float32, reflect.Float64:
case reflect.Float64:
return val.Convert(float64Type).Interface(), nil
case reflect.Slice, reflect.Array:
if val.Type().ConvertibleTo(byteSliceType) {
Expand Down
Loading