增加自定义类型实现FromDB,ToDB方法,使用指针类型添加/更新时使用空更新,不使用默认值

This commit is contained in:
venjiang 2020-02-21 18:57:26 +08:00
parent bc8bb23ad0
commit bb8b2f6dc8
2 changed files with 9 additions and 1 deletions

View File

@ -558,8 +558,11 @@ func (session *Session) value2Interface(col *core.Column, fieldValue reflect.Val
if col.SQLType.IsBlob() {
return data, nil
}
if len(data) > 0 {
return string(data), nil
}
return nil, nil
}
fieldType := fieldValue.Type()
k := fieldType.Kind()

View File

@ -330,6 +330,11 @@ func (statement *Statement) buildUpdates(bean interface{},
if err != nil {
engine.logger.Error(err)
} else {
if fieldType.Kind() == reflect.Ptr && len(data) == 0 {
args = append(args, nil)
colNames = append(colNames, fmt.Sprintf("%v=?", engine.Quote(col.Name)))
continue
}
val = data
}
goto APPEND