title: Raw SQL queries in a REST Api
body: <p>Say I have these 2 tables:</p>
  
  <h3>posts</h3>
  
  <pre><code> id | user_id | title | slug | content | views
  ----+---------+-------+------+---------+-------
  </code></pre>
  
  <h3>users</h3>
  
  <pre><code> id | username | email | hash | role | auth 
  ----+----------+-------+------+------+------
  </code></pre>
  
  <p>With these two tables I want to do a <code>SELECT * FROM posts ...</code> query and ultimately end up responding with something like this:</p>
  
  <pre><code>{[
    {
      "id": "1",
      "user_id": "2",
      "title": "Foo",
      "slug": "foo",
      "content": "bar",
      "views": "0",
      "user": {
        "id": "2",
        "username": "john",
        "email": "john@smith.com",
        "hash": "aeigh*£HAEGhoiaehg",
        "role": "admin",
        "auth": "aeg89hiae9g8hA*H£GA(*EHG"
      }
    }
  ]}
  </code></pre>
  
  <p>I'm pretty new to SQL, and patterns like this seem pretty common when using an ORM, so I'm wondering what steps I have to do to get a result like this using raw SQL.</p>
  
  <p>Any idea?</p>