From 7cee47263a12d86d35cd2be7953c60cb15d80744 Mon Sep 17 00:00:00 2001 From: rahul yadav Date: Mon, 30 Oct 2023 19:46:03 +0530 Subject: [PATCH 1/2] feat(spanner): add support of uint type for gorm.Model implementation --- spanner/key.go | 2 ++ spanner/key_test.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/spanner/key.go b/spanner/key.go index 1e689d49dc05..87a3694e42e6 100644 --- a/spanner/key.go +++ b/spanner/key.go @@ -77,6 +77,8 @@ func keyPartValue(part interface{}) (pb *proto3.Value, err error) { pb, _, err = encodeValue(int64(v)) case int32: pb, _, err = encodeValue(int64(v)) + case uint: + pb, _, err = encodeValue(int64(v)) case uint8: pb, _, err = encodeValue(int64(v)) case uint16: diff --git a/spanner/key_test.go b/spanner/key_test.go index bac0fc13f5d7..534cdb362813 100644 --- a/spanner/key_test.go +++ b/spanner/key_test.go @@ -54,6 +54,11 @@ func TestKey(t *testing.T) { wantProto *proto3.ListValue wantStr string }{ + { + k: Key{uint(4611686018427387904)}, + wantProto: listValueProto(stringProto("4611686018427387904")), + wantStr: "(4611686018427387904)", + }, { k: Key{int(1)}, wantProto: listValueProto(stringProto("1")), From 7abc3595e9cc93153a1383d60eb44a81a2bbabef Mon Sep 17 00:00:00 2001 From: rahul yadav Date: Mon, 30 Oct 2023 19:57:34 +0530 Subject: [PATCH 2/2] allow uint encoding --- spanner/value.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spanner/value.go b/spanner/value.go index 7d68739ea08c..23e6b1317001 100644 --- a/spanner/value.go +++ b/spanner/value.go @@ -3471,6 +3471,30 @@ func encodeValue(v interface{}) (*proto3.Value, *sppb.Type, error) { } } pt = listType(intType()) + case uint: + pb.Kind = stringKind(strconv.FormatInt(int64(v), 10)) + pt = intType() + case []uint: + if v != nil { + pb, err = encodeArray(len(v), func(i int) interface{} { return v[i] }) + if err != nil { + return nil, nil, err + } + } + pt = listType(intType()) + case *uint: + if v != nil { + return encodeValue(*v) + } + pt = intType() + case []*uint: + if v != nil { + pb, err = encodeArray(len(v), func(i int) interface{} { return v[i] }) + if err != nil { + return nil, nil, err + } + } + pt = listType(intType()) case bool: pb.Kind = &proto3.Value_BoolValue{BoolValue: v} pt = boolType()