Use tag PRECISION to set time's precision for mysql

This commit is contained in:
Jinzhu 2018-02-09 23:18:47 +08:00
parent ae696d051f
commit 8d4e3e5a83
1 changed files with 7 additions and 2 deletions

View File

@ -95,10 +95,15 @@ func (s *mysql) DataTypeOf(field *StructField) string {
}
case reflect.Struct:
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 {
sqlType = fmt.Sprintf("timestamp(%d)", size)
sqlType = fmt.Sprintf("timestamp%v", precision)
} else {
sqlType = fmt.Sprintf("timestamp(%d) NULL", size)
sqlType = fmt.Sprintf("timestamp%v NULL", precision)
}
}
default: