gorm
gorm copied to clipboard
How to omit '' columns in Upsert?
Your Question
I want to skip '' values when updating with Upsert.
The document you expected this should be explained
type Test struct {
Id int64 `gorm:"column:id; primaryKey"`
Name string `gorm:"column:name"`
Age int `gorm:"column:age"`
}
d.MDb.Debug().Table("test").Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "id"}},
DoUpdates: clause.AssignmentColumns([]string{"name", "age"}),
}).CreateInBatches(&test, 10)
Expected answer
We have a record
|id|nam|age|
|--|---|---|
|1|hello|18|
I want to update this record, but I want to keep the value of 'hello'
{"id": 1, "name":"", "age": 19}