title: MySQL 1:N Data Mapping
body: <p>Something really bugs me and im not sure what is the "correct" approach.
  If i make a select to get contacts from my database there are a decent amount of joins involved.</p>
  
  <p>It will look something like this (around 60-70 columns):</p>
  
  <pre><code>SELECT * 
  FROM contacts
  LEFT JOIN company
  LEFT JOIN person
  LEFT JOIN address
  LEFT JOIN person_communication
  LEFT JOIN company_communication
  LEFT JOIN categories
  LEFT JOIN notes
  </code></pre>
  
  <p>company and person are 1:1 cardinality so its straight forward.
  But "address", "communication" and "categories" are 1:n cardinality.</p>
  
  <p>So depending on the amount of rows in the 1:n tables i will get a lot of "double" rows (I don't know whats the real term for that, the rows are not double i know that the address or phone number etc is different). For myself as a contact, a fairly filled contact, i get 85 rows back.</p>
  
  <p>How do you guys work with that?
  In my PHP application i always wrote some "Data-Mapper" where the array key was the "contact.ID aka primary" and then checked if it exists and then pushed the additional data into it. Also PHP is not really type strict what makes it easy.</p>
  
  <p>Now I'm learning GO(golang) and i thought screw that LOOOONG select and data mapping just write selects for all the 1:n.... yeah no, not enough connections to load a table full of contacts. I know that i can increase the connections but the error seems to imply that this would be the wrong way.
  I use the following driver: <a href="https://github.com/go-sql-driver/mysql" rel="nofollow noreferrer">https://github.com/go-sql-driver/mysql</a></p>
  
  <p>I also tried GROUP_CONCAT but then i running in trouble parsing it back.</p>
  
  <p>Do i have to do my mapping approach again or is there some nice solution out there? I found it quite dirty at points tho?</p>