title: How do I keep a global Postgres connection?
body: <p>I want to store the Postgres connection on <strong>global scope</strong> to access from any function in a module. Here is an example:</p>
  <pre class="lang-rust prettyprint-override"><code>use postgres::{Client, NoTls};
  
  static mut client: Option&lt;Client&gt; = None;
  
  pub fn get_player(id: i32) {
      // Use global client connection object:
      for row in client.unwrap().query(&quot;SELECT * FROM public.\&quot;User\&quot; WHERE \&quot;accountID\&quot;=$1;&quot;,&amp;[&amp;id]).unwrap(){
          let id: i32 = row.get(0);
          let name: &amp;str = row.get(1);
  
          println!(&quot;found player: {} {}&quot;, id, name);
      }
  }
  
  pub fn init() {
      let mut connection = Client::connect(&quot;host=localhost user=postgres&quot;, NoTls);
      match connection {
          Ok(cli) =&gt; {
              println!(&quot;Database connected.&quot;);
              client = Some(cli);
          }
          Err(_) =&gt; println!(&quot;Database ERROR while connecting.&quot;),
      }
  }
  </code></pre>
  <p>It is not compiling &amp; working as intended and I don't know how to make this in Rust.</p>