1
2
3
4
5
6
7
8
9
10
11
func (um *Model) InsertOrUpdate(session *xorm.Session) (int64, error) {

sql := fmt.Sprintf(`INSERT INTO %s (id,user_id,mine_id,status) VALUES(?,?,?,?)
ON CONFLICT (user_id,mine_id) DO UPDATE SET
status = ?;`, um.TableName())
result, err := session.SQL(sql, um.Id, um.UserId, um.MineId, um.Status).Execute()
if err != nil {
return -1, err
}
return result.RowsAffected()
}