forked from mirror/gorm
Set db type after autotime
This commit is contained in:
parent
4eae3fea41
commit
2476c0fbb4
|
@ -223,15 +223,6 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
|
||||||
field.DataType = DataType(dataTyper.GormDataType())
|
field.DataType = DataType(dataTyper.GormDataType())
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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" {
|
||||||
field.AutoCreateTime = UnixNanosecond
|
field.AutoCreateTime = UnixNanosecond
|
||||||
|
@ -248,6 +239,15 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if field.Size == 0 {
|
if field.Size == 0 {
|
||||||
switch reflect.Indirect(fieldValue).Kind() {
|
switch reflect.Indirect(fieldValue).Kind() {
|
||||||
case reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.Float64:
|
case reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.Float64:
|
||||||
|
|
Loading…
Reference in New Issue