Fixed sql generation for diff saving
This commit is contained in:
parent
857db14448
commit
dc6132f30b
|
@ -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(')')
|
||||
|
||||
|
|
Loading…
Reference in New Issue