protoc-gen-gorm icon indicating copy to clipboard operation
protoc-gen-gorm copied to clipboard

Add support for map of scalar value types as/and hstore data type for PostgreSQL database

Open AnPiakhota-Infoblox opened this issue 3 years ago • 0 comments

protoc-gen-gorm generates nothing against map field in proto3 file. For example the next proto message

message Request {
  option (gorm.opts) = {
    ormable: true
    multi_account: true
    include: []
  };
  gorm.types.UUIDValue id = 1;
  map<string, string> data = 2;
}

is generated into

type RequestORM struct {
	AccountID string
	Id        *go_uuid1.UUID `gorm:"type:uuid"`
}

Map is omitted but could be stored as PostgreSQL hstore data type that stores sets of key/value pairs. Other scalar types could be supported as well as far as they could be properly converted to their string representation.

Although hstore itself is not implemented in protoc-gen-gorm but it shouldn't be difficult to add it similar to JSONValue type. GORM V1 supports it as well.

message Request {
  option (gorm.opts) = {
    ormable: true
    multi_account: true
    include: []
  };
  gorm.types.UUIDValue id = 1;
  gorm.types.JSONValue config = 2;
  gorm.types.Hstore headers = 3;
}
type RequestORM struct {
  Config          *postgres.Jsonb    `gorm:"type:jsonb"`
  Headers         *postgres.Hstore   `gorm:"type:hstore"`
}

AnPiakhota-Infoblox avatar Mar 12 '21 18:03 AnPiakhota-Infoblox