默认是软删除,除非加入Unscoped()
方法才是真正的永久删除:
// 软删除
func (br *BaseRepository[T]) Delete(entity T, id uint) error {
return br.DB.Delete(&entity, id).Error
}
// 硬删除
func (br *BaseRepository[T]) HardDelete(entity T, id uint) error {
return br.DB.Unscoped().Delete(&entity, id).Error
}