From dc6132f30b58c8ee59cb6de3e1b8b9c8f433d6dd Mon Sep 17 00:00:00 2001 From: "a.chubar" Date: Tue, 7 Nov 2023 13:39:48 +0300 Subject: [PATCH] Fixed sql generation for diff saving --- tpl/macros_struct.twig | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tpl/macros_struct.twig b/tpl/macros_struct.twig index e6344b4..d0429ae 100644 --- a/tpl/macros_struct.twig +++ b/tpl/macros_struct.twig @@ -150,16 +150,11 @@ func Save{{ ctx.s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ ctx {% endfor %} {% if ctx.raw_nonpk_fields|length > 0 %} - initUpdateLen := updateBuilder.Len() {% for f in ctx.raw_nonpk_fields %} if rec.{{ f|fname }}Changed() { queryBuilder.WriteString(",`{{ f.name }}`") valuesBuilder.WriteString(",?") - - if updateBuilder.Len() > initUpdateLen { - updateBuilder.WriteRune(',') - } - updateBuilder.WriteString("`{{ f.name }}`=VALUES(`{{ f.name }}`)") + updateBuilder.WriteString(",`{{ f.name }}`=VALUES(`{{ f.name }}`)") values = append(values, rec.{{ f|fname }}) } @@ -194,10 +189,7 @@ func Save{{ ctx.s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ ctx queryBuilder.WriteString(",`kv`") valuesBuilder.WriteString(",?") - if updateBuilder.Len() > initUpdateLen { - updateBuilder.WriteRune(',') - } - updateBuilder.WriteString("`kv`=JSON_SET(`kv`") + updateBuilder.WriteString(",`kv`=JSON_SET(`kv`") updateBuilder.WriteString(jsonBuilder.String()) updateBuilder.WriteRune(')')