auto update value of time field if given time value is zero for package gdb

This commit is contained in:
John Guo 2021-08-10 20:30:32 +08:00
parent 9c5642f141
commit 91dd9e2bf9

View File

@ -195,8 +195,20 @@ func ConvertDataForTableRecord(value interface{}) map[string]interface{} {
} }
case reflect.Struct: case reflect.Struct:
switch v.(type) { switch r := v.(type) {
case time.Time, *time.Time, gtime.Time, *gtime.Time: // If the time is zero, it then updates it to nil,
// which will insert/update the value to database as "null".
case time.Time:
if r.IsZero() {
data[k] = nil
}
case gtime.Time:
if r.IsZero() {
data[k] = nil
}
case *time.Time, *gtime.Time:
continue continue
case Counter, *Counter: case Counter, *Counter: