[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 {
|
if str, ok := v.(string); ok {
|
||||||
return str
|
return str
|
||||||
|
} else if raw, ok := v.(db.Expression); ok {
|
||||||
|
return raw
|
||||||
} else if b, err := json.Marshal(v); err == nil {
|
} else if b, err := json.Marshal(v); err == nil {
|
||||||
return string(b)
|
return string(b)
|
||||||
} else {
|
} else {
|
||||||
@ -140,11 +142,15 @@ func (this ResField) ToValue(v any) any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this ResField) GetRawDefault(driver string) db.Expression {
|
func (this ResField) GetRawDefault(driver string) db.Expression {
|
||||||
if this.DataType == contracts.ResDataType_Json && this.Default == "" {
|
if this.DataType == contracts.ResDataType_Json {
|
||||||
return db.Raw("'{}'")
|
if this.Default != "" && this.Default[0:1] == "[" {
|
||||||
}
|
return db.Raw("'[]'")
|
||||||
|
} else if this.Default != "" && this.Default[0:1] == "{" {
|
||||||
if this.DataType == contracts.ResDataType_Boolean {
|
return db.Raw("'{}'")
|
||||||
|
} else if this.Default == "" {
|
||||||
|
return db.Raw("'{}'")
|
||||||
|
}
|
||||||
|
} else if this.DataType == contracts.ResDataType_Boolean {
|
||||||
if v, _ := strconv.ParseBool(this.Default); v {
|
if v, _ := strconv.ParseBool(this.Default); v {
|
||||||
return db.Raw("'1'")
|
return db.Raw("'1'")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user