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/15 16:53:53 UTC

[GitHub] [trafficcontrol] rawlinp commented on issue #3484: TO: "info" struct tag example for better generic endpoint handling

rawlinp commented on issue #3484: TO: "info" struct tag example for better generic endpoint handling
URL: https://github.com/apache/trafficcontrol/pull/3484#issuecomment-483332691
 
 
   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. Ideally, we should be trying to use reflection only as a last ditch effort when the problem can't reasonably be solved without it. Originally I was thinking along the lines of something similar to 
   ```
   func (v *TOASNV11) NewReadObj() interface{} { return &tc.ASNNullable{} }
   ```
   where `TOASNV11` has a method like `NewReturningFields` that returns pointers to the fields that would be scanned into from the `RETURNING` clause.
   
   However, 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. So, we should most likely be following up `INSERT`/`UPDATE`s with `SELECT`s, ideally just reusing the main `SelectQuery` that each struct already implements. TC is a read-heavy system, so I wouldn't be worried about doing extra `SELECT`s after every `INSERT`/`UPDATE`. Utilizing the `SelectQuery` methods like this would save us from having to do reflection or adding more methods like `NewReturningFields` that I described above. What do you think about doing it that way instead?
   
   Here is some relevant info about `RETURNING` clauses (which I might be misunderstanding) https://www.postgresql.org/docs/9.6/sql-insert.html:
   > The optional RETURNING clause causes INSERT to compute and return value(s) based on each row actually inserted (or updated, if an ON CONFLICT DO UPDATE clause was used). This is primarily useful for obtaining values that were supplied by defaults, such as a serial sequence number. However, any expression using the table's columns is allowed.
   
   > output_expression
   An expression to be computed and returned by the INSERT command after each row is inserted or updated. The expression can use any column names of the table named by table_name. Write * to return all columns of the inserted or updated row(s).

----------------------------------------------------------------
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