title: Rust diesel orm queries
body: <p>I am new to rust and diesel orm. I am trying to execute below things on my query:</p>
  <ul>
  <li>count</li>
  <li>select</li>
  <li>order</li>
  <li>limit</li>
  </ul>
  <p>but I am getting error.<br>
  I am using postgres database.<br></p>
  <p>I have added the exact error above the queries in comment.<br>
  Here are my code:</p>
  <p><strong>schema.rs</strong></p>
  <pre><code>table! {
      employee (employee_id) {
          employee_id -&gt; Int4,
          name -&gt; Nullable&lt;Text&gt;,
          age -&gt; Nullable&lt;Int4&gt;,
          address -&gt; Nullable&lt;Text&gt;,
          email -&gt; Nullable&lt;Text&gt;,
          dept_id -&gt; Int4,
          salary -&gt; Nullable&lt;Numeric&gt;,
          created_on -&gt; Nullable&lt;Timestamp&gt;,
          created_by -&gt; Nullable&lt;Text&gt;,
          modified_on -&gt; Nullable&lt;Timestamp&gt;,
          modified_by -&gt; Nullable&lt;Text&gt;,
          is_active -&gt; Nullable&lt;Bool&gt;,
      }
  }
  </code></pre>
  <p><strong>models.rs</strong></p>
  <pre><code>#![allow(unused)]
  #![allow(clippy::all)]
  use super::schema::employee;
  
  use bigdecimal::BigDecimal;
  use chrono::NaiveDateTime;
  
  #[derive(Queryable, Debug, Identifiable)]
  #[table_name = &quot;employee&quot;]
  #[primary_key(employee_id)]
  pub struct Employee {
      pub employee_id: i32,
      pub name: Option&lt;String&gt;,
      pub age: Option&lt;i32&gt;,
      pub address: Option&lt;String&gt;,
      pub email: Option&lt;String&gt;,
      pub dept_id: i32,
      pub salary: Option&lt;BigDecimal&gt;,
      pub created_on: Option&lt;NaiveDateTime&gt;,
      pub created_by: Option&lt;String&gt;,
      pub modified_on: Option&lt;NaiveDateTime&gt;,
      pub modified_by: Option&lt;String&gt;,
      pub is_active: Option&lt;bool&gt;,
  }
  </code></pre>
  <p><strong>cargo.toml</strong></p>
  <pre><code>[dependencies]
  diesel = { version = &quot;1.4.5&quot;, features = [&quot;postgres&quot;,&quot;chrono&quot;,&quot;numeric&quot;] }
  dotenv = &quot;0.15.0&quot;
  chrono = { version = &quot;0.4.19&quot; , features = [&quot;serde&quot;] }
  bigdecimal = { version = &quot;0.1.0&quot; }
  </code></pre>
  <p><strong>main.rs</strong></p>
  <pre><code>#[macro_use]
  extern crate diesel;
  extern crate bigdecimal;
  extern crate chrono;
  extern crate dotenv;
  
  use crate::models::Employee;
  use crate::models::Players;
  use crate::schema::employee::dsl::*;
  
  use diesel::{pg::PgConnection, prelude::*};
  use dotenv::dotenv;
  use std::env;
  
  mod models;
  mod schema;
  
  fn main() {
      dotenv().ok();
      let data_url: String = env::var(&quot;DATABASE_URL&quot;).expect(&quot;DATABASE_URL must be set&quot;);
      let connection: PgConnection =
          PgConnection::establish(&amp;data_url).expect(&amp;format!(&quot;Error connect to {}&quot;, data_url));
  
      //get all employees name
      //This is working fine
      let _employee: Vec&lt;Employee&gt; = employee
          .load::&lt;Employee&gt;(&amp;connection)
          .expect(&quot;Error loading department&quot;);
  
      for emp in _employee {
          println!(&quot;{}&quot;, emp.name.unwrap_or_default());
      }
  
  
      //----------------------------------------------
      //get employees count
      /*
      Error: error[E0282]: type annotations needed
             ^^^^^^^^^^^^^^^ consider giving `total_employees` a type
      */
      let total_employees = employee.count().get_result(&amp;connection).expect(&quot;Error&quot;);
      println!(&quot;{}&quot;, total_employees);
  
  
      //-----------------------------------------------
       //get all names
      /*
          Error: error[E0277]: the trait bound `*const str: FromSql&lt;diesel::sql_types::Nullable&lt;diesel::sql_types::Text&gt;, _&gt;` is not satisfied
           ^^^^ the trait `FromSql&lt;diesel::sql_types::Nullable&lt;diesel::sql_types::Text&gt;, _&gt;` is not implemented for `*const str`
      */
      let all_names = employee.select(name).load::&lt;String&gt;(&amp;connection)?;
      println!(&quot;{}&quot;, all_names);
  
  
      //----------------------------------------------
      //order name
      /*
      Error: error[E0277]: the trait bound `*const str: FromSql&lt;diesel::sql_types::Nullable&lt;diesel::sql_types::Text&gt;, _&gt;` is not          satisfied
      ^^^^ the trait `FromSql&lt;diesel::sql_types::Nullable&lt;diesel::sql_types::Text&gt;, _&gt;` is not implemented for `*const str`
      */
      let ordered_names = employee
          .select(name)
          .order(name.desc())
          .load::&lt;String&gt;(&amp;connection)?;
      println!(&quot;{}&quot;, ordered_names);
  
  
     //------------------------------------------------
     /*
      Error: error[E0277]: the trait bound `*const str: FromSql&lt;diesel::sql_types::Nullable&lt;diesel::sql_types::Text&gt;, _&gt;` is not     satisfied
      ^^^^ the trait `FromSql&lt;diesel::sql_types::Nullable&lt;diesel::sql_types::Text&gt;, _&gt;` is not implemented for `*const str`
       */
      let limited = employee
          .select(name)
          .order(employee_id)
          .limit(1)
          .load::&lt;String&gt;(&amp;connection)?;
      println!(&quot;{}&quot;, limited);
  }
  </code></pre>
  <p>Am I missing something ?
  Can anybody correct me ? <br>
  Thanks!</p>