Original post

I am searching for ways to populate a Go template with sql values. So far I have 3 solutions that has pros and cons.

1. Sql standard library
Standard sql library is idiomatic, but you have to repeat the structs twice.


2. Sqlx
Sqlx is an add on to standard library with “StructScan” which makes it more generic. I interpret this is a idiomatic way.


3. JSON experiment
This is DRY at the highest level, but I am considering it as a dead end. Because the function json_agg() does not work with joins etc. But I still consider it is an option for some cases.


My questions

  1. How do I get rid of the time garbage in 1 and 2? Is there a way to use time.Date(YYYY-MM-DD) in a struct sort of?
  2. Is there more ways to achieve this? Simpler or better?