Merge a4b79b5c8d2c2fefcacb25d3732c7d2b38722441 into 38f96c65140f00f0b15efc495a487cfd5db510b8

This commit is contained in:
Rob Rodriguez 2018-02-09 14:09:03 +00:00 committed by GitHub
commit 7a0db74074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,8 +66,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) {