From a4b79b5c8d2c2fefcacb25d3732c7d2b38722441 Mon Sep 17 00:00:00 2001 From: Rob Rodriguez Date: Thu, 23 Nov 2017 14:50:44 -0800 Subject: [PATCH] Adding StringArray and RawMessage(JSONB) support to postgres dialect --- dialect_postgres.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dialect_postgres.go b/dialect_postgres.go index 6fdf4df1..90aa0c93 100644 --- a/dialect_postgres.go +++ b/dialect_postgres.go @@ -65,8 +65,23 @@ func (s *postgres) DataTypeOf(field *StructField) string { if dataValue.Type().Name() == "Hstore" { sqlType = "hstore" } + case reflect.Slice: + if dataValue.Type().Name() == "StringArray" { + if _, ok := field.TagSettings["SIZE"]; !ok { + size = 0 // if SIZE haven't been set, use `text` as the default type, as there are no performance different + } + if size > 0 && size < 65532 { + sqlType = fmt.Sprintf("varchar(%d)[]", size) + } else { + sqlType = "text[]" + } + break + } + fallthrough default: - if IsByteArrayOrSlice(dataValue) { + if dataValue.Type().Name() == "RawMessage" { + sqlType = "JSONB DEFAULT '{}'::JSONB" + } else if IsByteArrayOrSlice(dataValue) { sqlType = "bytea" if isUUID(dataValue) { sqlType = "uuid"