Is there any builtin support to build e.g. dynamic UPDATE queries?
I found the sqlx.Named function which is able to take a map and assign the values according to the keys in the query, but is it possible with sqlx to build a (whole) query based on a given map?
Currently I'm building the query this way:
...
params := map[string]interface{}{
"name": "John",
"age":32,
}
named := make([]string, 0, len(params))
for key := range params {
named = append(named, fmt.Sprintf("%s=:%s", key, key))
}
params["id"] = 232
result, err := db.NamedExec(fmt.Sprintf("UPDATE users SET %s WHERE id=:id;", strings.Join(named, ", ")), params)
...
Many thanks for your help...
Is there any builtin support to build e.g. dynamic
UPDATEqueries?I found the
sqlx.Namedfunction which is able to take a map and assign the values according to the keys in the query, but is it possible with sqlx to build a (whole) query based on a given map?Currently I'm building the query this way:
Many thanks for your help...