srijeet0406 commented on code in PR #7631:
URL: https://github.com/apache/trafficcontrol/pull/7631#discussion_r1260365761


##########
traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go:
##########
@@ -2217,3 +2217,18 @@ func ASNExists(tx *sql.Tx, id string) (bool, error) {
        }
        return true, nil
 }
+
+// PhysLocationExists confirms whether the PhysLocationExists exists, and an 
error (if one occurs).
+func PhysLocationExists(tx *sql.Tx, id string) (bool, error) {

Review Comment:
   Instead of performing two queries for deletion (one for checking and one for 
actual deletion), you could just perform the delete query and check the 
`rowsAffected` result from that query. Here's an example:
   
   ```
   func GenericDelete(val GenericDeleter) (error, error, int) {
        result, err := val.APIInfo().Tx.NamedExec(val.DeleteQuery(), val)
        if err != nil {
                return ParseDBError(err)
        }
        if rowsAffected, err := result.RowsAffected(); err != nil {
                return nil, errors.New("deleting " + val.GetType() + ": getting 
rows affected: " + err.Error()), http.StatusInternalServerError
        } else if rowsAffected < 1 {
                return errors.New("no " + val.GetType() + " with that key 
found"), nil, http.StatusNotFound
        } else if rowsAffected > 1 {
                return nil, fmt.Errorf(val.GetType()+" delete affected too many 
rows: %d", rowsAffected), http.StatusInternalServerError
        }
        return nil, nil, http.StatusOK
   }



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to