zhangqian
2023-10-08 44a78f184ca10fba46df2567496895e179d4ac6c
model/procedures.go
@@ -7,6 +7,7 @@
   "encoding/json"
   "fmt"
   "gorm.io/gorm"
   "gorm.io/gorm/clause"
)
type (
@@ -139,6 +140,11 @@
   return slf
}
func (slf *ProceduresSearch) SetChannel(channel int32) *ProceduresSearch {
   slf.Channel = channel
   return slf
}
func (slf *ProceduresSearch) build() *gorm.DB {
   var db = slf.Orm.Model(&Procedures{})
@@ -215,6 +221,21 @@
   return nil
}
func (slf *ProceduresSearch) Upsert(record *Procedures) error {
   var db = slf.build()
   old, err := slf.First()
   if err != gorm.ErrRecordNotFound && old.ID != 0 {
      record.ID = old.ID
   }
   if err := db.Clauses(clause.OnConflict{
      UpdateAll: true,
   }).Create(&record).Error; err != nil {
      return fmt.Errorf("save err: %v, record: %+v", err, record)
   }
   return nil
}
func (slf *ProceduresSearch) Updates(record *Procedures) error {
   var db = slf.build()