title: How do I make and parse a raw SQL query with Diesel?
body: <p>I'm testing out Rust using the Rocket framework. For the database, I'm using Diesel to interact with my MySQL database.</p>
  <p>Following a few examples, there are a lot of things happening under the hood. I've got a MySQL Database running with a populated tables that I'd like to make a raw query on.</p>
  <p>The below code works:</p>
  <pre><code>use diesel::{prelude::*};
  
  mod schema {
      table! {
          organization {
              id -&gt; Nullable&lt;Integer&gt;,
              name -&gt; Text,
              country -&gt; Text,
          }
      }
  }
  
  use self::schema::organization;
  use self::schema::organization::dsl::{organization as all_orgs};
  
  #[table_name=&quot;organization&quot;]
  #[derive(Serialize, Deserialize, Queryable, Insertable, Debug, Clone)]
  pub struct Organization {
      pub id: Option&lt;i32&gt;,
      pub name: String,
      pub country: String
  }
  
  impl Organization {
      pub fn all(conn: &amp;MysqlConnection) -&gt; Vec&lt;Organization&gt; {
          all_orgs.order(organization).load::&lt;Organization&gt;(conn).unwrap()
      }
  }
  </code></pre>
  <p>However, I do not need to order by anything. In fact, I'd just like to make a raw query as <code>SELECT id, name, country FROM organization</code> and call it a day.</p>
  <p>I've attempted the below after looking at <a href="https://docs.diesel.rs/diesel/fn.sql_query.html" rel="nofollow noreferrer">Diesel documentation</a> and found something called <code>sql_query</code>.</p>
  <p>My code now looks like:</p>
  <pre><code>use diesel::{prelude::*, sql_query};
  
  mod schema {
      table! {
          organization {
              id -&gt; Nullable&lt;Integer&gt;,
              name -&gt; Text,
              country -&gt; Text,
          }
      }
  }
  
  use self::schema::organization;
  
  #[table_name=&quot;organization&quot;]
  #[derive(Serialize, Deserialize, Queryable, Insertable, Debug, Clone)]
  pub struct Organization {
      pub id: Option&lt;i32&gt;,
      pub name: String,
      pub country: String
  }
  
  impl Organization {
      pub fn all(conn: &amp;MysqlConnection) -&gt; Vec&lt;Organization&gt; {
           sql_query(&quot;SELECT id, name, country FROM organization&quot;)
              .load(&amp;conn).unwrap()
      }
  }
  </code></pre>
  <p>However, upon doing <code>cargo run</code> on on this change, I am faced with:</p>
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `&amp;diesel::MysqlConnection: diesel::Connection` is not satisfied
    --&gt; src/org.rs:26:19
     |
  26 |             .load(&amp;conn).unwrap()
     |                   -^^^^
     |                   |
     |                   the trait `diesel::Connection` is not implemented for `&amp;diesel::MysqlConnection`
     |                   help: consider removing the leading `&amp;`-reference
     |
     = help: the following implementations were found:
               &lt;diesel::MysqlConnection as diesel::Connection&gt;
     = note: required because of the requirements on the impl of `LoadQuery&lt;&amp;diesel::MysqlConnection, _&gt;` for `SqlQuery`
  
  error[E0277]: the trait bound `Organization: QueryableByName&lt;_&gt;` is not satisfied
    --&gt; src/org.rs:26:14
     |
  26 |             .load(&amp;conn).unwrap()
     |              ^^^^ the trait `QueryableByName&lt;_&gt;` is not implemented for `Organization`
     |
     = note: required because of the requirements on the impl of `LoadQuery&lt;&amp;diesel::MysqlConnection, Organization&gt;` for `SqlQuery`
  </code></pre>
  <p>How do I satisfy these errors, while being allowed to do a raw SQL query and parse it correctly from the function, given the input parameters and desired output?</p>