- insert into my_table values(‘1’,‘a’) :
type MyTable struct {
x string
y string
}
func (tn *MyTable) Create(db *gorm.DB) error {
return db.Create(tn).Error
}
func (tn *MyTable) TableName() string {
return "my_table"
}
- insert ignore into my_table values(‘1’,‘a’):
type MyTable struct {
x string
y string
}
func (tn *MyTable) Create(db *gorm.DB) error {
return db.Clauses(clause.Insert{Modifier: "IGNORE"}).Create(tn).Error
}
func (tn *MyTable) TableName() string {
return "my_table"
}