I have a struct mapping to mysql table as below and want to update fields which are sent in a PUT request payload
type Notification struct {
Id int64 `json:"id"`
Type NotificationType
Subject string `json:"confidence"`
Body string `json:"body"`
CreatedDate time.Time `json:"created_dt"`
CreatedBy int64 `json:"created_by"`
ParentNotification int64 `json:"parent_id"`
IsExpired bool `json:"expired"`
}
Currently I am asking all the fields to be included in payload even though the data is not changed and updating all columns using query with db.Exec(query) statement.
Is there any way where I can ask client to include only fields which are changed in payload and update only those fields?
{
"body" : "new body"
"subject" : "new subject"
}
I am working with below packages in db side.
"database/sql"
_ "github.com/go-sql-driver/mysql"