From d1de9e8dbcad69611805e818e94b0b3f100aa125 Mon Sep 17 00:00:00 2001 From: what Date: Mon, 31 Jul 2023 21:46:45 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20ToValue=20=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BD=AC=E6=8D=A2=E5=8F=8A=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/res_field.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/base/res_field.go b/base/res_field.go index e33d6b3..ddf2ab2 100644 --- a/base/res_field.go +++ b/base/res_field.go @@ -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'") }