mirror of https://github.com/go-gorm/gorm.git
Handle data type cases
This commit is contained in:
parent
e3292b3b41
commit
d4d339f3b5
|
@ -224,7 +224,12 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
|
||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := field.TagSettings["TYPE"]; ok {
|
if val, ok := field.TagSettings["TYPE"]; ok {
|
||||||
field.DataType = DataType(val)
|
switch DataType(strings.ToLower(val)) {
|
||||||
|
case Bool, Int, Uint, Float, String, Time, Bytes:
|
||||||
|
field.DataType = DataType(strings.ToLower(val))
|
||||||
|
default:
|
||||||
|
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)) {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue