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

feat(spanner): support of uint datatype for gorm.Model #8935

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions spanner/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions spanner/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
24 changes: 24 additions & 0 deletions spanner/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -3471,6 +3471,30 @@ func encodeValue(v interface{}) (*proto3.Value, *sppb.Type, error) {
}
}
pt = listType(intType())
case uint:
Copy link
Contributor

@harshachinta harshachinta Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shouldn't we add support for uint type in decodeValue method also?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

@rahul2393 rahul2393 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gorm.Model tests were able decode to uint without making any changes in decodeValue function, seems like default case is sufficient, let me add tests validating it

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()
Expand Down
Loading