googleapis / go-gorm-spanner

Google Cloud Spanner implementation for Go's GORM library.
Apache License 2.0
29 stars 4 forks source link

Feature Request: Add the automatic type mapping for uint8/16/32/64 and int8/16/32 #122

Open gsbingo17 opened 3 weeks ago

gsbingo17 commented 3 weeks ago

Developers make code changes to Spanner from MySQL using go-gorm-spanner; Because Spanner does not use unsigned integer type, it causes developers to introduce explicit conversions, creating overhead for application refactoring.

For example:


    testObject := &TestObject{
        Id:                  int64(in.Id),
        TestId:            int64(in.TestId),
        TestType: int64(in.TestType),
        ...
    }

Could you please consider the support for automatic type mapping to INT64 from unit/unit8/16/32/64.
olavloite commented 1 week ago

@gsbingo17 uint should automatically be mapped to INT64. The uint8/16/32/64 types are currently not mapped. Is that the issue? Would you otherwise mind elaborating a bit more on exactly what is not working as expected?

Many of the tests in this repository use gorm.Model, which uses uint as the primary key. I've also added this pull request to verify that it is possible to write and read uint values without any conversion: https://github.com/googleapis/go-gorm-spanner/pull/125

gsbingo17 commented 1 week ago

@olavloite Thank you! This feature request addresses a common use case where developers are refactoring applications to migrate from MySQL to Spanner.

olavloite commented 1 week ago

@gsbingo17 Could you supply a code sample for something that you have at the moment that does not work with Spanner? That makes it easier to understand where it goes wrong.

I understand that the desire is to minimize code changes, but it's not entirely clear to me how your structure is at the moment, and where that then causes an issue.

Put another way, based on your original example:

    testObject := &TestObject{
        Id:                  int64(in.Id),
        TestId:            int64(in.TestId),
        TestType: int64(in.TestType),
        ...
    }

The above conversions should all not be necessary if in.Id, in.TestId, and in.TestType are of type uint, and you also define the fields of TestObject of type uint. Is the problem specifically that the other types uint8 etc. are not mapped? Or something else?

gsbingo17 commented 1 week ago

@olavloite Thank you! I just created a doc and shared it with you.