Skip to content

Commit

Permalink
use untils func
Browse files Browse the repository at this point in the history
  • Loading branch information
hasa1K committed Jul 27, 2023
1 parent 75dd528 commit 07fa85e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions sqle/model/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,22 @@ func (s *Storage) GetAllRulesByTmpNameAndProjectIdInstanceDBType(ruleTemplateNam
}

func (s *Storage) DeleteCustomRule(ruleId string) error {
tx := s.db.Begin()
if err := tx.Where("rule_id = ?", ruleId).Delete(&CustomRule{}).Error; err != nil {
tx.Rollback()
return err
}
if err := tx.Where("rule_id = ?", ruleId).Delete(&RuleTemplateCustomRule{}).Error; err != nil {
tx.Rollback()
return err
err := s.Tx(func(tx *gorm.DB) error {
if err := tx.Where("rule_id = ?", ruleId).Delete(&CustomRule{}).Error; err != nil {
tx.Rollback()
return err
}
if err := tx.Where("rule_id = ?", ruleId).Delete(&RuleTemplateCustomRule{}).Error; err != nil {
tx.Rollback()
return err
}

return nil
})

if err != nil {
return errors.ConnectStorageErrWrapper(err)
}

return errors.New(errors.ConnectStorageError, tx.Commit().Error)
return nil
}

0 comments on commit 07fa85e

Please sign in to comment.