title: How to construct object from multiple tables in Go
body: <p>I'm trying to find the best way to work with objects represented by multiple database tables.</p>
  
  <p>For database access I wrapped sqlx with my own type and then defined some methods:</p>
  
  <pre><code>type DB struct {
      *sqlx.DB
  }
  func (db *DB) GetSomething(id uint32) *Something {} 
  func (db *DB) AddSomething(*Something) {}
  </code></pre>
  
  <p>It works nice for objects that map one-to-one with single database table. I see a couple of ways to work with multi-table objects:</p>
  
  <ol>
  <li>Define methods on *DB that do selects from multiple tables and then
  construct an object. Save is similiar. </li>
  <li>Create a layer on top of *DB which would construct an object.  </li>
  <li>Do not construct an object, use its parts.</li>
  </ol>
  
  <p>I rather prefer number 2, but need help on how to design it in Go.</p>