DataTypeOf should now correctly identify dataValues that are 'json.RawMessage' types as 'jsonb' columns

This commit is contained in:
Adrian 2018-02-08 23:58:03 +08:00
parent 87fc1b2473
commit feb013c976

View File

@ -5,6 +5,7 @@ import (
"reflect" "reflect"
"strings" "strings"
"time" "time"
"encoding/json"
) )
type postgres struct { type postgres struct {
@ -67,9 +68,12 @@ func (s *postgres) DataTypeOf(field *StructField) string {
} }
default: default:
if IsByteArrayOrSlice(dataValue) { if IsByteArrayOrSlice(dataValue) {
sqlType = "bytea"
if isUUID(dataValue) { if isUUID(dataValue) {
sqlType = "uuid" sqlType = "uuid"
} else if _, ok := dataValue.Interface().(json.RawMessage); ok {
sqlType = "jsonb"
} else {
sqlType = "bytea"
} }
} }
} }