move the json check to its own function

This commit is contained in:
Adrian 2018-02-09 00:11:14 +08:00
parent feb013c976
commit 300cf4acd7

View File

@ -70,7 +70,7 @@ func (s *postgres) DataTypeOf(field *StructField) string {
if IsByteArrayOrSlice(dataValue) {
if isUUID(dataValue) {
sqlType = "uuid"
} else if _, ok := dataValue.Interface().(json.RawMessage); ok {
} else if isJSON(dataValue) {
sqlType = "jsonb"
} else {
sqlType = "bytea"
@ -134,3 +134,11 @@ func isUUID(value reflect.Value) bool {
lower := strings.ToLower(typename)
return "uuid" == lower || "guid" == lower
}
func isJSON(value reflect.Value) bool {
if _, ok := value.Interface().(json.RawMessage); ok {
return true
} else {
return false
}
}