[fix] ToValue 数据类型转换
This commit is contained in:
parent
cd4e1b4789
commit
3f44f0335c
@ -1,6 +1,7 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@ -126,17 +127,30 @@ func (this ResField) ToValue(v any) any {
|
||||
return this.Default
|
||||
}
|
||||
|
||||
return v
|
||||
if str, ok := v.(string); ok {
|
||||
return str
|
||||
} else if b, err := json.Marshal(v); err == nil {
|
||||
return string(b)
|
||||
} else {
|
||||
panic(fmt.Sprintf("%s, 类型转换错误, %s", this.Code, err))
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Trim(cast.ToString(v), " ")
|
||||
}
|
||||
|
||||
func (this ResField) GetRawDefault(driver string) db.Expression {
|
||||
if this.DataType == "json" && this.Default == "" {
|
||||
if this.DataType == contracts.ResDataType_Json && this.Default == "" {
|
||||
return db.Raw("'{}'")
|
||||
}
|
||||
|
||||
if this.DataType == contracts.ResDataType_Boolean {
|
||||
if v, _ := strconv.ParseBool(this.Default); v {
|
||||
return db.Raw("'1'")
|
||||
}
|
||||
return db.Raw("'0'")
|
||||
}
|
||||
|
||||
if len(this.Default) > 4 && strings.ToLower(this.Default[0:4]) == "sql:" {
|
||||
sql := strings.ToLower(this.Default[4:])
|
||||
if sql == "uuid()" {
|
||||
|
Loading…
Reference in New Issue
Block a user