You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wonder what the intended way is to build a WHERE statements to match all primary key in a template like: WHERE id1 = $1 AND id2 = $2 AND id3 = $3.
With intended I means, without using legacy or custom functions.
The only way I found is really ugly:
sqlstr+=" WHERE"
{{ range $i, $field:= $t.PrimaryKeys-}}
// Sprintf code is generated because of a missing arith. add template functionsqlstr+=" {{ $field.SQLName }} = $"+fmt.Sprint(i-1)
// if statement code is generated because comparision can not be done in template, because of missing add functionif {{ $i }} +1!= {{ (len $t.PrimaryKeys) }} {
sqlstr+=" AND"
}
{{ end-}}
I could define add, sub functions in funcs.go.tpl to improve it.
This seems such a basic scenario though that I think that I'm probably missing the simple intended way to do it? :-)
thanks
The text was updated successfully, but these errors were encountered:
fho
changed the title
templates: how to create WHERE string for multiple primarykeys
templates: how to create WHERE string for multiple primary keys
Sep 21, 2021
Hello,
I wonder what the intended way is to build a WHERE statements to match all primary key in a template like:
WHERE id1 = $1 AND id2 = $2 AND id3 = $3
.With intended I means, without using legacy or custom functions.
The only way I found is really ugly:
I could define
add
,sub
functions infuncs.go.tpl
to improve it.This seems such a basic scenario though that I think that I'm probably missing the simple intended way to do it? :-)
thanks
The text was updated successfully, but these errors were encountered: