Describe the feature

It's very common to use automatically generated structs from proto, and further, directly use those structs as models for gorm. For MySQL/Postgres timestamps, protobuf generates struct google.protobuf.Timestamp.

Problem

gorm doesn't have an inbuilt serializer for google.protobuf.Timestamp. If a struct containing this type is used as a model for gorm, scanning returns error invalid field found for struct <struct> field <fieldName>: define a valid foreign key for relations or implement the Valuer/Scanner interface.

Implementing the Valuer/Scanner interface isn't possible for this type, as you cannot define new methods on non-local types (the generated go code from the proto will live in a different package). Additionally, using gorm serializers is not straightforward, since it requires generating protobuf implementations with gorm tags. This requires changing the way you build protobuf: by installing a new dependency (protoc-gen-gorm) and using it to create gorm tags. This isn't possible in our case as I'm hesitant on asking everyone in my company to install this dependency when they build protobuf.

Motivation

As pb.timestamp is a very common type, gorm should support serializing and deserializing to it out of the box.

Related Issues

4604

Comment From: github-actions[bot]

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days