I get a JSON from a client on the successful submit of user details.
Some element in the JSON can be skipped since they were not updated.
On the Golang server side, I have an equivalent struct defined.
The server successfully marshals the JSON bytes into the struct.
type user struct {
Id *int64 `json:",omitempty"`
Name *string `json:",omitempty"`
Age *int64 `json:",omitempty"`
}
How do I create a dynamic update statement depending on the available JSON elements?
For example, I might get the Id and Age alone.
How can I create a update statement dynamically, like update user set age = $1 where id = $2
Another time it might be Id and Name.