Skip to content

Commit d23326b

Browse files
authored
chore(spanner): add gorm data type names for PG types (#13584)
Add gorm data type names for PostgreSQL-specific types. This prevents gorm from interpreting these structs as models, and automatically creates columns with the correct data type when used as a field in a model. Needed for googleapis/go-gorm-spanner#199
1 parent bc92500 commit d23326b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

spanner/value.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,11 @@ func (n *PGNumeric) UnmarshalJSON(payload []byte) error {
10511051
return nil
10521052
}
10531053

1054+
// GormDataType is used by gorm to determine the default data type for fields with this type.
1055+
func (n PGNumeric) GormDataType() string {
1056+
return "numeric"
1057+
}
1058+
10541059
// NullProtoMessage represents a Cloud Spanner PROTO that may be NULL.
10551060
// To write a NULL value using NullProtoMessage set ProtoMessageVal to typed nil and set Valid to true.
10561061
type NullProtoMessage struct {
@@ -1285,6 +1290,11 @@ func (n *PGJsonB) UnmarshalJSON(payload []byte) error {
12851290
return nil
12861291
}
12871292

1293+
// GormDataType is used by gorm to determine the default data type for fields with this type.
1294+
func (n PGJsonB) GormDataType() string {
1295+
return "jsonb"
1296+
}
1297+
12881298
func nulljson(valid bool, v interface{}) ([]byte, error) {
12891299
if !valid {
12901300
return []byte("null"), nil

0 commit comments

Comments
 (0)