rob05c closed pull request #2901: Remove some unused/duplicated dbhelper 
functions
URL: https://github.com/apache/trafficcontrol/pull/2901
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go 
b/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
index 866342c8e..7bc31ed8f 100644
--- a/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
+++ b/traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
@@ -22,6 +22,7 @@ package dbhelpers
 import (
        "database/sql"
        "errors"
+       "fmt"
        "strings"
 
        "github.com/apache/trafficcontrol/lib/go-log"
@@ -101,30 +102,6 @@ func parseCriteriaAndQueryValues(queryParamsToSQLCols 
map[string]WhereColumnInfo
        return criteria, queryValues, errs
 }
 
-// FinishTx commits the transaction if commit is true when it's called, 
otherwise it rolls back the transaction. This is designed to be called in a 
defer.
-func FinishTx(tx *sql.Tx, commit *bool) {
-       if tx == nil {
-               return
-       }
-       if !*commit {
-               tx.Rollback()
-               return
-       }
-       tx.Commit()
-}
-
-// FinishTxX commits the transaction if commit is true when it's called, 
otherwise it rolls back the transaction. This is designed to be called in a 
defer.
-func FinishTxX(tx *sqlx.Tx, commit *bool) {
-       if tx == nil {
-               return
-       }
-       if !*commit {
-               tx.Rollback()
-               return
-       }
-       tx.Commit()
-}
-
 // AddTenancyCheck takes a WHERE clause (can be ""), the associated 
queryValues (can be empty),
 // a tenantColumnName that should provide a bigint corresponding to the 
tenantID of the object being checked (this may require a CAST),
 // and an array of the tenantIDs the user has access to; it returns a where 
clause and associated queryValues including filtering based on tenancy.
@@ -140,53 +117,18 @@ func AddTenancyCheck(where string, queryValues 
map[string]interface{}, tenantCol
        return where, queryValues
 }
 
-// GetGlobalParams returns the value of the global param, whether it existed, 
or any error
-func GetGlobalParam(tx *sql.Tx, name string) (string, bool, error) {
-       return GetParam(tx, name, "global")
-}
-
-// GetParam returns the value of the param, whether it existed, or any error.
-func GetParam(tx *sql.Tx, name string, configFile string) (string, bool, 
error) {
-       val := ""
-       if err := tx.QueryRow(`select value from parameter where name = $1 and 
config_file = $2`, name, configFile).Scan(&val); err != nil {
-               if err == sql.ErrNoRows {
-                       return "", false, nil
-               }
-               return "", false, errors.New("Error querying global paramter '" 
+ name + "': " + err.Error())
-       }
-       return val, true, nil
-}
-
-// GetDSNameFromID returns the delivery service name, whether it existed, and 
any error.
+// GetDSNameFromID loads the DeliveryService's xml_id from the database, from 
the ID. Returns whether the delivery service was found, and any error.
 func GetDSNameFromID(tx *sql.Tx, id int) (tc.DeliveryServiceName, bool, error) 
{
        name := tc.DeliveryServiceName("")
-       if err := tx.QueryRow(`select xml_id from deliveryservice where id = 
$1`, id).Scan(&name); err != nil {
+       if err := tx.QueryRow(`SELECT xml_id FROM deliveryservice WHERE id = 
$1`, id).Scan(&name); err != nil {
                if err == sql.ErrNoRows {
                        return tc.DeliveryServiceName(""), false, nil
                }
-               return tc.DeliveryServiceName(""), false, errors.New("querying 
delivery service name: " + err.Error())
+               return tc.DeliveryServiceName(""), false, fmt.Errorf("querying 
xml_id for delivery service ID '%v': %v", id, err)
        }
        return name, true, nil
 }
 
-// returns returns the delivery service name and cdn, whether it existed, and 
any error.
-func GetDSNameAndCDNFromID(tx *sql.Tx, id int) (tc.DeliveryServiceName, 
tc.CDNName, bool, error) {
-       name := tc.DeliveryServiceName("")
-       cdn := tc.CDNName("")
-       if err := tx.QueryRow(`
-SELECT ds.xml_id, cdn.name
-FROM deliveryservice as ds
-JOIN cdn on cdn.id = ds.cdn_id
-WHERE ds.id = $1
-`, id).Scan(&name, &cdn); err != nil {
-               if err == sql.ErrNoRows {
-                       return tc.DeliveryServiceName(""), tc.CDNName(""), 
false, nil
-               }
-               return tc.DeliveryServiceName(""), tc.CDNName(""), false, 
errors.New("querying delivery service name: " + err.Error())
-       }
-       return name, cdn, true, nil
-}
-
 // GetProfileNameFromID returns the profile's name, whether a profile with ID 
exists, or any error.
 func GetProfileNameFromID(id int, tx *sql.Tx) (string, bool, error) {
        name := ""
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/urlkey.go 
b/traffic_ops/traffic_ops_golang/deliveryservice/urlkey.go
index 19c06f809..33312f86e 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/urlkey.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/urlkey.go
@@ -21,7 +21,6 @@ package deliveryservice
 
 import (
        "crypto/rand"
-       "database/sql"
        "errors"
        "fmt"
        "math/big"
@@ -30,6 +29,7 @@ import (
 
        "github.com/apache/trafficcontrol/lib/go-tc"
        "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
        
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/riaksvc"
        "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/tenant"
 )
@@ -47,7 +47,7 @@ func GetURLKeysByID(w http.ResponseWriter, r *http.Request) {
                return
        }
 
-       ds, ok, err := GetDSNameFromID(inf.Tx.Tx, inf.IntParams["id"])
+       ds, ok, err := dbhelpers.GetDSNameFromID(inf.Tx.Tx, inf.IntParams["id"])
        if err != nil {
                api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
nil, errors.New("getting delivery service name from ID: "+err.Error()))
                return
@@ -231,19 +231,6 @@ func CopyURLKeys(w http.ResponseWriter, r *http.Request) {
        api.WriteRespAlert(w, r, tc.SuccessLevel, "Successfully copied and 
stored keys")
 }
 
-// GetDSNameFromID loads the DeliveryService's xml_id from the database, from 
the ID. Returns whether the delivery service was found, and any error.
-// TODO move somewhere generic
-func GetDSNameFromID(tx *sql.Tx, id int) (tc.DeliveryServiceName, bool, error) 
{
-       name := tc.DeliveryServiceName("")
-       if err := tx.QueryRow(`SELECT xml_id FROM deliveryservice where id = 
$1`, id).Scan(&name); err != nil {
-               if err == sql.ErrNoRows {
-                       return tc.DeliveryServiceName(""), false, nil
-               }
-               return tc.DeliveryServiceName(""), false, fmt.Errorf("querying 
xml_id for delivery service ID '%v': %v", id, err)
-       }
-       return name, true, nil
-}
-
 func GenerateURLKeys(w http.ResponseWriter, r *http.Request) {
        inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, nil)
        if userErr != nil || sysErr != nil {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to