From 834d5202eea8e783fb987ff82c7873a702f70a44 Mon Sep 17 00:00:00 2001 From: Zack Stevens Date: Mon, 3 Jul 2023 12:42:14 -0600 Subject: [PATCH] fix: Support google timestamp type --- example/cockroachdb/example.pb.go | 184 +++++++++++++------------ example/cockroachdb/example.pb.gorm.go | 11 ++ example/cockroachdb/example.proto | 2 + go.mod | 2 +- plugin/plugin.go | 3 + 5 files changed, 116 insertions(+), 86 deletions(-) diff --git a/example/cockroachdb/example.pb.go b/example/cockroachdb/example.pb.go index 2079139..919ce32 100644 --- a/example/cockroachdb/example.pb.go +++ b/example/cockroachdb/example.pb.go @@ -164,6 +164,8 @@ type User struct { Date string `protobuf:"bytes,48,opt,name=date,proto3" json:"date,omitempty" fake:"{date:2006-01-02}"` // @gotags: fake:"{date:2006-01-02}" OptionalDate *string `protobuf:"bytes,49,opt,name=optional_date,json=optionalDate,proto3,oneof" json:"optional_date,omitempty" fake:"{date:2006-01-02}"` + // @gotags: fake:"skip" + SomeTimestamp *timestamppb.Timestamp `protobuf:"bytes,50,opt,name=some_timestamp,json=someTimestamp,proto3" json:"some_timestamp,omitempty" fake:"skip"` } func (x *User) Reset() { @@ -429,6 +431,13 @@ func (x *User) GetOptionalDate() string { return "" } +func (x *User) GetSomeTimestamp() *timestamppb.Timestamp { + if x != nil { + return x.SomeTimestamp + } + return nil +} + type Company struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -767,7 +776,7 @@ var file_cockroachdb_example_proto_rawDesc = []byte{ 0x6f, 0x1a, 0x12, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x67, 0x6f, 0x72, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x22, 0xa0, 0x0c, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x13, 0x0a, 0x02, + 0x6f, 0x74, 0x6f, 0x22, 0xe3, 0x0c, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, @@ -861,78 +870,82 @@ var file_cockroachdb_example_proto_rawDesc = []byte{ 0x3a, 0x0a, 0x0d, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x31, 0x20, 0x01, 0x28, 0x09, 0x42, 0x10, 0xba, 0xb9, 0x19, 0x0c, 0x5a, 0x0a, 0x32, 0x30, 0x30, 0x36, 0x2d, 0x30, 0x31, 0x2d, 0x30, 0x32, 0x48, 0x02, 0x52, 0x0c, 0x6f, 0x70, 0x74, 0x69, - 0x6f, 0x6e, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x65, 0x88, 0x01, 0x01, 0x3a, 0x06, 0xba, 0xb9, 0x19, - 0x02, 0x08, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x69, 0x64, 0x42, 0x18, 0x0a, 0x16, 0x5f, 0x6f, - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x5f, 0x73, 0x63, 0x61, 0x6c, 0x61, 0x72, 0x5f, 0x66, - 0x69, 0x65, 0x6c, 0x64, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, - 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x22, 0xb7, 0x01, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x70, 0x61, - 0x6e, 0x79, 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, - 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x12, 0x0a, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x3a, 0x06, 0xba, 0xb9, 0x19, 0x02, 0x08, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x69, 0x64, - 0x22, 0xa1, 0x02, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x13, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, - 0x01, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, - 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, - 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x75, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x07, 0x75, - 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x06, - 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x3e, 0x0a, 0x04, 0x75, 0x73, 0x65, - 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 0x2e, 0x63, 0x6f, 0x63, 0x6b, 0x72, 0x6f, 0x61, 0x63, 0x68, 0x64, 0x62, 0x2e, 0x55, 0x73, - 0x65, 0x72, 0x42, 0x0f, 0xba, 0xb9, 0x19, 0x0b, 0x52, 0x07, 0x43, 0x41, 0x53, 0x43, 0x41, 0x44, - 0x45, 0x22, 0x00, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x3a, 0x06, 0xba, 0xb9, 0x19, 0x02, 0x08, - 0x01, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x69, 0x64, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x75, 0x73, 0x65, - 0x72, 0x5f, 0x69, 0x64, 0x22, 0xe1, 0x01, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, - 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x02, - 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6f, 0x6e, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x65, 0x88, 0x01, 0x01, 0x12, 0x41, 0x0a, 0x0e, 0x73, + 0x6f, 0x6d, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x32, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x0d, 0x73, 0x6f, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x3a, 0x06, + 0xba, 0xb9, 0x19, 0x02, 0x08, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x69, 0x64, 0x42, 0x18, 0x0a, + 0x16, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x5f, 0x73, 0x63, 0x61, 0x6c, 0x61, + 0x72, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x6f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x61, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x22, 0xb7, 0x01, 0x0a, 0x07, 0x43, 0x6f, + 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x48, 0x00, 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, + 0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, - 0x12, 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x1c, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, - 0x48, 0x01, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x88, 0x01, 0x01, 0x3a, 0x06, 0xba, - 0xb9, 0x19, 0x02, 0x08, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x69, 0x64, 0x42, 0x0a, 0x0a, 0x08, - 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x22, 0xb7, 0x01, 0x0a, 0x07, 0x50, 0x72, 0x6f, - 0x66, 0x69, 0x6c, 0x65, 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x48, 0x00, 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, - 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, + 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x06, 0xba, 0xb9, 0x19, 0x02, 0x08, 0x01, 0x42, 0x05, 0x0a, 0x03, + 0x5f, 0x69, 0x64, 0x22, 0xa1, 0x02, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, + 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x02, 0x69, + 0x64, 0x88, 0x01, 0x01, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, + 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, - 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, - 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x3a, 0x06, 0xba, 0xb9, 0x19, 0x02, 0x08, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x5f, - 0x69, 0x64, 0x2a, 0x70, 0x0a, 0x07, 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x6e, 0x65, 0x12, 0x0b, 0x0a, - 0x07, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x6e, - 0x65, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x77, 0x6f, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, - 0x54, 0x68, 0x72, 0x65, 0x65, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x6f, 0x75, 0x72, 0x10, - 0x04, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x69, 0x76, 0x65, 0x10, 0x05, 0x12, 0x07, 0x0a, 0x03, 0x53, - 0x69, 0x78, 0x10, 0x06, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x65, 0x76, 0x65, 0x6e, 0x10, 0x07, 0x12, - 0x09, 0x0a, 0x05, 0x45, 0x69, 0x67, 0x68, 0x74, 0x10, 0x08, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x69, - 0x6e, 0x65, 0x10, 0x09, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x63, 0x61, 0x74, 0x61, 0x6c, 0x79, 0x73, 0x74, 0x73, 0x71, 0x75, 0x61, 0x64, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x67, 0x6f, 0x2d, 0x67, - 0x6f, 0x72, 0x6d, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3b, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, + 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1c, + 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, + 0x01, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x3e, 0x0a, 0x04, + 0x75, 0x73, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x65, 0x78, 0x61, + 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x63, 0x6b, 0x72, 0x6f, 0x61, 0x63, 0x68, 0x64, 0x62, + 0x2e, 0x55, 0x73, 0x65, 0x72, 0x42, 0x0f, 0xba, 0xb9, 0x19, 0x0b, 0x52, 0x07, 0x43, 0x41, 0x53, + 0x43, 0x41, 0x44, 0x45, 0x22, 0x00, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x3a, 0x06, 0xba, 0xb9, + 0x19, 0x02, 0x08, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x69, 0x64, 0x42, 0x0a, 0x0a, 0x08, 0x5f, + 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x22, 0xe1, 0x01, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, + 0x65, 0x6e, 0x74, 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, + 0x00, 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, + 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x12, + 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x88, 0x01, 0x01, + 0x3a, 0x06, 0xba, 0xb9, 0x19, 0x02, 0x08, 0x01, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x69, 0x64, 0x42, + 0x0a, 0x0a, 0x08, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x22, 0xb7, 0x01, 0x0a, 0x07, + 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x39, 0x0a, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, + 0x41, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x06, 0xba, 0xb9, 0x19, 0x02, 0x08, 0x01, 0x42, 0x05, + 0x0a, 0x03, 0x5f, 0x69, 0x64, 0x2a, 0x70, 0x0a, 0x07, 0x45, 0x6e, 0x75, 0x6d, 0x4f, 0x6e, 0x65, + 0x12, 0x0b, 0x0a, 0x07, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x10, 0x00, 0x12, 0x07, 0x0a, + 0x03, 0x4f, 0x6e, 0x65, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x77, 0x6f, 0x10, 0x02, 0x12, + 0x09, 0x0a, 0x05, 0x54, 0x68, 0x72, 0x65, 0x65, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x6f, + 0x75, 0x72, 0x10, 0x04, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x69, 0x76, 0x65, 0x10, 0x05, 0x12, 0x07, + 0x0a, 0x03, 0x53, 0x69, 0x78, 0x10, 0x06, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x65, 0x76, 0x65, 0x6e, + 0x10, 0x07, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x69, 0x67, 0x68, 0x74, 0x10, 0x08, 0x12, 0x08, 0x0a, + 0x04, 0x4e, 0x69, 0x6e, 0x65, 0x10, 0x09, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x61, 0x74, 0x61, 0x6c, 0x79, 0x73, 0x74, 0x73, 0x71, + 0x75, 0x61, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x67, + 0x6f, 0x2d, 0x67, 0x6f, 0x72, 0x6d, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3b, 0x65, + 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -972,20 +985,21 @@ var file_cockroachdb_example_proto_depIdxs = []int32{ 0, // 9: example.cockroachdb.User.string_enum:type_name -> example.cockroachdb.EnumOne 0, // 10: example.cockroachdb.User.int_enum_list:type_name -> example.cockroachdb.EnumOne 0, // 11: example.cockroachdb.User.string_enum_list:type_name -> example.cockroachdb.EnumOne - 6, // 12: example.cockroachdb.Company.created_at:type_name -> google.protobuf.Timestamp - 6, // 13: example.cockroachdb.Company.updated_at:type_name -> google.protobuf.Timestamp - 6, // 14: example.cockroachdb.Address.created_at:type_name -> google.protobuf.Timestamp - 6, // 15: example.cockroachdb.Address.updated_at:type_name -> google.protobuf.Timestamp - 1, // 16: example.cockroachdb.Address.user:type_name -> example.cockroachdb.User - 6, // 17: example.cockroachdb.Comment.created_at:type_name -> google.protobuf.Timestamp - 6, // 18: example.cockroachdb.Comment.updated_at:type_name -> google.protobuf.Timestamp - 6, // 19: example.cockroachdb.Profile.created_at:type_name -> google.protobuf.Timestamp - 6, // 20: example.cockroachdb.Profile.updated_at:type_name -> google.protobuf.Timestamp - 21, // [21:21] is the sub-list for method output_type - 21, // [21:21] is the sub-list for method input_type - 21, // [21:21] is the sub-list for extension type_name - 21, // [21:21] is the sub-list for extension extendee - 0, // [0:21] is the sub-list for field type_name + 6, // 12: example.cockroachdb.User.some_timestamp:type_name -> google.protobuf.Timestamp + 6, // 13: example.cockroachdb.Company.created_at:type_name -> google.protobuf.Timestamp + 6, // 14: example.cockroachdb.Company.updated_at:type_name -> google.protobuf.Timestamp + 6, // 15: example.cockroachdb.Address.created_at:type_name -> google.protobuf.Timestamp + 6, // 16: example.cockroachdb.Address.updated_at:type_name -> google.protobuf.Timestamp + 1, // 17: example.cockroachdb.Address.user:type_name -> example.cockroachdb.User + 6, // 18: example.cockroachdb.Comment.created_at:type_name -> google.protobuf.Timestamp + 6, // 19: example.cockroachdb.Comment.updated_at:type_name -> google.protobuf.Timestamp + 6, // 20: example.cockroachdb.Profile.created_at:type_name -> google.protobuf.Timestamp + 6, // 21: example.cockroachdb.Profile.updated_at:type_name -> google.protobuf.Timestamp + 22, // [22:22] is the sub-list for method output_type + 22, // [22:22] is the sub-list for method input_type + 22, // [22:22] is the sub-list for extension type_name + 22, // [22:22] is the sub-list for extension extendee + 0, // [0:22] is the sub-list for field type_name } func init() { file_cockroachdb_example_proto_init() } diff --git a/example/cockroachdb/example.pb.gorm.go b/example/cockroachdb/example.pb.gorm.go index 8122fde..f33bc0b 100644 --- a/example/cockroachdb/example.pb.gorm.go +++ b/example/cockroachdb/example.pb.gorm.go @@ -121,6 +121,9 @@ type UserGormModel struct { // @gotags: fake:"{date:2006-01-02}" OptionalDate *time.Time `json:"optionalDate" fake:"{date:2006-01-02}"` + + // @gotags: fake:"skip" + SomeTimestamp *time.Time `gorm:"type:timestamp;" json:"someTimestamp" fake:"skip"` } func (m *UserGormModel) TableName() string { @@ -277,6 +280,10 @@ func (m *UserGormModel) ToProto() (theProto *User, err error) { theProto.OptionalDate = lo.ToPtr(m.OptionalDate.UTC().Format("2006-01-02")) } + if m.SomeTimestamp != nil { + theProto.SomeTimestamp = timestamppb.New(*m.SomeTimestamp) + } + return } @@ -420,6 +427,10 @@ func (p *User) ToModel() (theModel *UserGormModel, err error) { theModel.OptionalDate = &dateUTC } + if p.SomeTimestamp != nil { + theModel.SomeTimestamp = lo.ToPtr(p.SomeTimestamp.AsTime()) + } + return } diff --git a/example/cockroachdb/example.proto b/example/cockroachdb/example.proto index 86021f2..2fa9aeb 100644 --- a/example/cockroachdb/example.proto +++ b/example/cockroachdb/example.proto @@ -89,6 +89,8 @@ message User { string date = 48 [(gorm.field).time_format_override = "2006-01-02"]; // @gotags: fake:"{date:2006-01-02}" optional string optional_date = 49 [(gorm.field).time_format_override = "2006-01-02"]; + // @gotags: fake:"skip" + google.protobuf.Timestamp some_timestamp = 50; } message Company { diff --git a/go.mod b/go.mod index 73faad7..d2bf9dd 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/gertd/go-pluralize v0.2.1 github.com/golang/glog v1.1.1 github.com/google/go-cmp v0.5.9 + github.com/google/uuid v1.3.0 github.com/jackc/pgtype v1.14.0 github.com/lib/pq v1.10.8 github.com/orlangure/gnomock v0.28.0 @@ -28,7 +29,6 @@ require ( github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/google/uuid v1.3.0 // indirect github.com/jackc/pgio v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect diff --git a/plugin/plugin.go b/plugin/plugin.go index 8fe760b..d535aa4 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -500,6 +500,9 @@ var goTypeMap = map[protoreflect.Kind]string{ } func isTimestamp(field *protogen.Field) bool { + if field.Desc.Message() != nil && field.Desc.Message().FullName() == "google.protobuf.Timestamp" { + return true + } fieldName := strings.Replace(strings.Replace(strings.ToLower(field.GoName), "_", "", -1), "-", "", -1) return fieldName == "createdat" || fieldName == "updatedat" || fieldName == "deletedat" }