ocket8888 commented on a change in pull request #3930: Rewrite profile import 
to Go
URL: https://github.com/apache/trafficcontrol/pull/3930#discussion_r331106647
 
 

 ##########
 File path: lib/go-tc/cdns.go
 ##########
 @@ -117,3 +122,13 @@ type CDNConfig struct {
        Name *string `json:"name"`
        ID   *int    `json:"id"`
 }
+
+// CDNExistsByName returns whether a cdn with the given name exists, and any 
error.
+// TODO move to helper package.
+func CDNExistsByName(name string, tx *sql.Tx) (bool, error) {
+       count := 0
+       if err := tx.QueryRow(`SELECT count(*) from cdn where name = $1`, 
name).Scan(&count); err != nil {
 
 Review comment:
   This doesn't matter at all, but if you want to just get a boolean value out 
of the SQL, you could do something like this:
   
   ```go
   var exists bool
   err := tx.QueryRow(`SELECT EXISTS(SELECT * FROM cdn WHERE name = 
$1)`).Scan(&exists)
   return exists, err
   ```
   
   which, again, doesn't matter, it just gives me a warm fuzzy feeling to get 
exactly the information I want out of Postgresql instead of something I 
collapse into the information I want.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to