You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2019/04/16 00:22:43 UTC

[GitHub] [trafficcontrol] moltzaum edited a comment on issue #3484: TO: "info" struct tag example for better generic endpoint handling

moltzaum edited a comment on issue #3484: TO: "info" struct tag example for better generic endpoint handling
URL: https://github.com/apache/trafficcontrol/pull/3484#issuecomment-483464967
 
 
   > So, my initial thoughts on this are that it's using a lot of reflection to mainly just get a set of fields from the struct to scan into when doing a SQL `RETURNING` statement.
   
   I agree. Doing all of this just for `LastUpdated` and join fields is too much overhead. However, this method works for _all_ fields. We can use it to read into an entire object, we can use it to specify PUT and DELETE ids, etc;. If we use it well, it can replace both the `db` tag and boilerplate CRUDer (implementation) functions together. It also is not difficult to add other categories of fields if the need arises. For instance, we could make a new tag specifically for non-numeric ids.
   
   We already have cost of reflection for the `db` tag, but sometimes its use has been overlooked because the named queries are easier to view as general methods with little to no difference in performance cost. I'm essentially hoping to rework the use of the `db` tag in a way that suits our needs better since the `db` tags only allow us to associate a field with something we put into a query -- we can't write back to a field using `db`.
   
   > I'm not sure we can utilize the RETURNING clause in all cases, since IIUC the expression can only contain columns from the table that was just inserted/updated/deleted.  
   
   Its true that in some cases, having another select statement may be unavoidable. However you can return a subquery that isn't related to the main table at all. I'm not really sure what you're getting at though since I don't think how we return items (within sql) relates to the main question: "how do we update certain fields 'generically' in go, in a way that can work easily for every/most endpoints". 
   
   I'm not fond of creating a method `NewReturningFields` because I think it adds to a framework in  a way that makes it more difficult to maintain. Between all the methods we already have, it is not immediately obvious how they are called. I like json tags because if you understand the semantics behind each tag, you only have to look in one place (the struct definition) to understand the majority of the behavior of the endpoint.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services