From a7809284a60057dce0e2e5f27c3163eac37a490d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 12 Nov 2022 08:56:26 +0800 Subject: [PATCH 1/3] Add test for get customized types --- integrations/session_get_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/integrations/session_get_test.go b/integrations/session_get_test.go index 841ec709..b3cc95b8 100644 --- a/integrations/session_get_test.go +++ b/integrations/session_get_test.go @@ -1012,4 +1012,12 @@ func TestGetBytesVars(t *testing.T) { assert.True(t, has) assert.EqualValues(t, []byte("bytes1-1"), gbv.Bytes1) assert.EqualValues(t, []byte("bytes2-2"), gbv.Bytes2) + + type MyID int64 + var myID MyID + + has, err = testEngine.Table("get_bytes_vars").Get(&myID) + assert.NoError(t, err) + assert.True(t, has) + assert.EqualValues(t, gbv.Id, myID) } -- 2.40.1 From 82751e797f6a749bb96f491a18a7601b5a66c126 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 12 Nov 2022 10:29:07 +0800 Subject: [PATCH 2/3] Fix test --- integrations/session_get_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/session_get_test.go b/integrations/session_get_test.go index b3cc95b8..d3403814 100644 --- a/integrations/session_get_test.go +++ b/integrations/session_get_test.go @@ -1016,7 +1016,7 @@ func TestGetBytesVars(t *testing.T) { type MyID int64 var myID MyID - has, err = testEngine.Table("get_bytes_vars").Get(&myID) + has, err = testEngine.Table("get_bytes_vars").Select("id").Desc("id").Get(&myID) assert.NoError(t, err) assert.True(t, has) assert.EqualValues(t, gbv.Id, myID) -- 2.40.1 From 299bb56b1670c43fa994c7f4c420b5bb3d626440 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 26 Jul 2023 09:15:08 +0800 Subject: [PATCH 3/3] Fix convert --- convert/int.go | 58 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/convert/int.go b/convert/int.go index af8d4f75..03994773 100644 --- a/convert/int.go +++ b/convert/int.go @@ -35,6 +35,56 @@ func AsInt64(src interface{}) (int64, error) { return int64(v), nil case uint64: return int64(v), nil + case *int: + if v == nil { + return 0, nil + } + return int64(*v), nil + case *int16: + if v == nil { + return 0, nil + } + return int64(*v), nil + case *int32: + if v == nil { + return 0, nil + } + return int64(*v), nil + case *int8: + if v == nil { + return 0, nil + } + return int64(*v), nil + case *int64: + if v == nil { + return 0, nil + } + return *v, nil + case *uint: + if v == nil { + return 0, nil + } + return int64(*v), nil + case *uint8: + if v == nil { + return 0, nil + } + return int64(*v), nil + case *uint16: + if v == nil { + return 0, nil + } + return int64(*v), nil + case *uint32: + if v == nil { + return 0, nil + } + return int64(*v), nil + case *uint64: + if v == nil { + return 0, nil + } + return int64(*v), nil case []byte: return strconv.ParseInt(string(v), 10, 64) case string: @@ -110,9 +160,7 @@ func AsUint64(src interface{}) (uint64, error) { return 0, fmt.Errorf("unsupported value %T as uint64", src) } -var ( - _ sql.Scanner = &NullUint64{} -) +var _ sql.Scanner = &NullUint64{} // NullUint64 represents an uint64 that may be null. // NullUint64 implements the Scanner interface so @@ -142,9 +190,7 @@ func (n NullUint64) Value() (driver.Value, error) { return n.Uint64, nil } -var ( - _ sql.Scanner = &NullUint32{} -) +var _ sql.Scanner = &NullUint32{} // NullUint32 represents an uint32 that may be null. // NullUint32 implements the Scanner interface so -- 2.40.1