Handle data type cases

This commit is contained in:
Jinzhu 2020-06-19 22:51:46 +08:00
parent e3292b3b41
commit d4d339f3b5
2 changed files with 7 additions and 2 deletions

View File

@ -224,8 +224,13 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
} }
if val, ok := field.TagSettings["TYPE"]; ok { if val, ok := field.TagSettings["TYPE"]; ok {
switch DataType(strings.ToLower(val)) {
case Bool, Int, Uint, Float, String, Time, Bytes:
field.DataType = DataType(strings.ToLower(val))
default:
field.DataType = DataType(val) field.DataType = DataType(val)
} }
}
if v, ok := field.TagSettings["AUTOCREATETIME"]; ok || (field.Name == "CreatedAt" && (field.DataType == Time || field.DataType == Int || field.DataType == Uint)) { if v, ok := field.TagSettings["AUTOCREATETIME"]; ok || (field.Name == "CreatedAt" && (field.DataType == Time || field.DataType == Int || field.DataType == Uint)) {
if strings.ToUpper(v) == "NANO" { if strings.ToUpper(v) == "NANO" {

View File

@ -107,7 +107,7 @@ func TestEmbeddedPointerTypeStruct(t *testing.T) {
} }
type Content struct { type Content struct {
Content interface{} `gorm:"type:string"` Content interface{} `gorm:"type:String"`
} }
func (c Content) Value() (driver.Value, error) { func (c Content) Value() (driver.Value, error) {