[fix] ToValue 数据类型转换及默认值

This commit is contained in:
what 2023-07-31 21:46:45 +08:00
parent 3f44f0335c
commit d1de9e8dbc

View File

@ -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 == "" {
return db.Raw("'{}'")
}
if this.DataType == contracts.ResDataType_Boolean {
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("'{}'")
}
} else if this.DataType == contracts.ResDataType_Boolean {
if v, _ := strconv.ParseBool(this.Default); v {
return db.Raw("'1'")
}