gorm on duplicate用法

gorm on duplicate

Posted by 大攀 on Wednesday, February 24, 2021

TOC

friend := models.Friend{
   GameId:     p.gameID,
   Uid:        uid,
   UNick:      uNick,
   UAvatar:    uAvatar,
   Fid:        fid,
   FNick:      fNick,
   FAvatar:    fAvatar,
   CreateTime: time.Now().Unix(),
}
err := mysql.MysqlClient.Table(p.tableName).Where("game_id = ? and uid = ? and fid = ?", p.gameID, uid, fid).Assign(models.Friend{CreateTime: time.Now().Unix()}).FirstOrCreate(&friend).Error

comments powered by Disqus