From 3e942c2e7dfb5d058a2a4ed9e72d05646fa40c69 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 17 Dec 2023 20:54:42 +0300 Subject: [PATCH] Remove last comma from values --- tpl/macros_struct.twig | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tpl/macros_struct.twig b/tpl/macros_struct.twig index fd16194..828ca78 100644 --- a/tpl/macros_struct.twig +++ b/tpl/macros_struct.twig @@ -215,7 +215,8 @@ func Save{{ ctx.s.name }}Diff(ctx context.Context, dbe metadb.Execer, rec {{ ctx } func Save{{ ctx.s.name }}CollectionDiff(ctx context.Context, dbe metadb.Execer, recs []{{ ctx.s.name }}) error { - byFieldsKey := map[string]queryDiffBuilder{} + byFieldsKey := map[string]*queryDiffBuilder{} + for _, rec := range recs { if rec.changedFields.Empty() { continue @@ -238,7 +239,7 @@ func Save{{ ctx.s.name }}CollectionDiff(ctx context.Context, dbe metadb.Execer, {% endfor %} {% endif %} - byFieldsKey[key] = builder + byFieldsKey[key] = &builder } builder := byFieldsKey[key] @@ -298,13 +299,9 @@ func Save{{ ctx.s.name }}CollectionDiff(ctx context.Context, dbe metadb.Execer, } for _, builder := range byFieldsKey { - var index int = 1 - if len(builder.rawValues) > 1 { - index = 2 - } - queryBuilder := builder.query builder.query.WriteRune(')') - queryBuilder.WriteString(builder.values.String()[0 : len(builder.values.String())-index]) + queryBuilder := builder.query + queryBuilder.WriteString(builder.values.String()[0:len(builder.values.String())-1]) queryBuilder.WriteString(builder.update.String()) _, saveErr := dbe.ExecContext(ctx, queryBuilder.String(), builder.rawValues...)