mirror of https://github.com/go-gorm/gorm.git
Use tag PRECISION to set time's precision for mysql
This commit is contained in:
parent
ae696d051f
commit
8d4e3e5a83
|
@ -95,10 +95,15 @@ func (s *mysql) DataTypeOf(field *StructField) string {
|
||||||
}
|
}
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
if _, ok := dataValue.Interface().(time.Time); ok {
|
if _, ok := dataValue.Interface().(time.Time); ok {
|
||||||
|
precision := ""
|
||||||
|
if p, ok := field.TagSettings["PRECISION"]; ok {
|
||||||
|
precision = fmt.Sprintf("(%s)", p)
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := field.TagSettings["NOT NULL"]; ok {
|
if _, ok := field.TagSettings["NOT NULL"]; ok {
|
||||||
sqlType = fmt.Sprintf("timestamp(%d)", size)
|
sqlType = fmt.Sprintf("timestamp%v", precision)
|
||||||
} else {
|
} else {
|
||||||
sqlType = fmt.Sprintf("timestamp(%d) NULL", size)
|
sqlType = fmt.Sprintf("timestamp%v NULL", precision)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue