Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Feb 28, 2025
1 parent e83d378 commit e311630
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 197 deletions.
169 changes: 0 additions & 169 deletions contrib/drivers/mysql/db_utils_test.go

This file was deleted.

37 changes: 31 additions & 6 deletions contrib/drivers/mysql/mysql_z_unit_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1719,9 +1719,9 @@ func Test_Issue4086(t *testing.T) {

gtest.C(t, func(t *gtest.T) {
type ProxyParam struct {
ProxyId int64 `json:"proxyId" orm:"proxy_id"`
RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids"`
Photos []string `json:"photos" orm:"photos"`
ProxyId int64 `json:"proxyId" orm:"proxy_id"`
RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids"`
Photos []int64 `json:"photos" orm:"photos"`
}

var proxyParamList []*ProxyParam
Expand All @@ -1744,9 +1744,34 @@ func Test_Issue4086(t *testing.T) {

gtest.C(t, func(t *gtest.T) {
type ProxyParam struct {
ProxyId int64 `json:"proxyId" orm:"proxy_id"`
RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids"`
Photos []int64 `json:"photos" orm:"photos"`
ProxyId int64 `json:"proxyId" orm:"proxy_id"`
RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids"`
Photos []float32 `json:"photos" orm:"photos"`
}

var proxyParamList []*ProxyParam
err := db.Model(table).Ctx(ctx).Scan(&proxyParamList)
t.AssertNil(err)
t.Assert(len(proxyParamList), 2)
t.Assert(proxyParamList, []*ProxyParam{
{
ProxyId: 1,
RecommendIds: []int64{584, 585},
Photos: nil,
},
{
ProxyId: 2,
RecommendIds: []int64{},
Photos: nil,
},
})
})

gtest.C(t, func(t *gtest.T) {
type ProxyParam struct {
ProxyId int64 `json:"proxyId" orm:"proxy_id"`
RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids"`
Photos []string `json:"photos" orm:"photos"`
}

var proxyParamList []*ProxyParam
Expand Down
7 changes: 4 additions & 3 deletions util/gconv/gconv_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/gogf/gf/v2/encoding/gbinary"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/internal/empty"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/internal/reflection"
"github.com/gogf/gf/v2/os/gtime"
Expand All @@ -43,7 +44,7 @@ func Bytes(any any) []byte {
}

func doBytes(any any) ([]byte, error) {
if any == nil {
if empty.IsNil(any) {
return nil, nil
}
switch value := any.(type) {
Expand Down Expand Up @@ -133,7 +134,7 @@ func String(any any) string {
}

func doString(any any) (string, error) {
if any == nil {
if empty.IsNil(any) {
return "", nil
}
switch value := any.(type) {
Expand Down Expand Up @@ -254,7 +255,7 @@ func Bool(any any) bool {
}

func doBool(any any) (bool, error) {
if any == nil {
if empty.IsNil(any) {
return false, nil
}
switch value := any.(type) {
Expand Down
5 changes: 3 additions & 2 deletions util/gconv/gconv_float.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/gogf/gf/v2/encoding/gbinary"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/internal/empty"
"github.com/gogf/gf/v2/util/gconv/internal/localinterface"
)

Expand All @@ -23,7 +24,7 @@ func Float32(any any) float32 {
}

func doFloat32(any any) (float32, error) {
if any == nil {
if empty.IsNil(any) {
return 0, nil
}
switch value := any.(type) {
Expand Down Expand Up @@ -86,7 +87,7 @@ func Float64(any any) float64 {
}

func doFloat64(any any) (float64, error) {
if any == nil {
if empty.IsNil(any) {
return 0, nil
}
switch value := any.(type) {
Expand Down
3 changes: 2 additions & 1 deletion util/gconv/gconv_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gogf/gf/v2/encoding/gbinary"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/internal/empty"
"github.com/gogf/gf/v2/util/gconv/internal/localinterface"
)

Expand Down Expand Up @@ -92,7 +93,7 @@ func Int64(any any) int64 {
}

func doInt64(any any) (int64, error) {
if any == nil {
if empty.IsNil(any) {
return 0, nil
}
if v, ok := any.(int64); ok {
Expand Down
11 changes: 10 additions & 1 deletion util/gconv/gconv_slice_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
package gconv

import (
"bytes"
"reflect"
"strings"

"github.com/gogf/gf/v2/internal/empty"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/internal/reflection"
"github.com/gogf/gf/v2/util/gconv/internal/localinterface"
Expand All @@ -21,7 +24,7 @@ func SliceAny(any interface{}) []interface{} {

// Interfaces converts `any` to []interface{}.
func Interfaces(any interface{}) []interface{} {
if any == nil {
if empty.IsNil(any) {
return nil
}
var array []interface{}
Expand Down Expand Up @@ -68,6 +71,9 @@ func Interfaces(any interface{}) []interface{} {
if _ = json.UnmarshalUseNumber(value, &array); array != nil {
return array
}
if bytes.EqualFold([]byte("null"), value) {
return nil
}
}
array = make([]interface{}, len(value))
for k, v := range value {
Expand All @@ -79,6 +85,9 @@ func Interfaces(any interface{}) []interface{} {
if _ = json.UnmarshalUseNumber(byteValue, &array); array != nil {
return array
}
if strings.EqualFold(value, "null") {
return nil
}
}

case []uint16:
Expand Down
Loading

0 comments on commit e311630

Please sign in to comment.