[fix] ToValue 数据类型转换及默认值
This commit is contained in:
parent
3f44f0335c
commit
d1de9e8dbc
@ -129,6 +129,8 @@ func (this ResField) ToValue(v any) any {
|
||||
|
||||
if str, ok := v.(string); ok {
|
||||
return str
|
||||
} else if raw, ok := v.(db.Expression); ok {
|
||||
return raw
|
||||
} else if b, err := json.Marshal(v); err == nil {
|
||||
return string(b)
|
||||
} else {
|
||||
@ -140,11 +142,15 @@ func (this ResField) ToValue(v any) any {
|
||||
}
|
||||
|
||||
func (this ResField) GetRawDefault(driver string) db.Expression {
|
||||
if this.DataType == contracts.ResDataType_Json && this.Default == "" {
|
||||
if this.DataType == contracts.ResDataType_Json {
|
||||
if this.Default != "" && this.Default[0:1] == "[" {
|
||||
return db.Raw("'[]'")
|
||||
} else if this.Default != "" && this.Default[0:1] == "{" {
|
||||
return db.Raw("'{}'")
|
||||
} else if this.Default == "" {
|
||||
return db.Raw("'{}'")
|
||||
}
|
||||
|
||||
if this.DataType == contracts.ResDataType_Boolean {
|
||||
} else if this.DataType == contracts.ResDataType_Boolean {
|
||||
if v, _ := strconv.ParseBool(this.Default); v {
|
||||
return db.Raw("'1'")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user