title: write a Query List Comprehensions for a mnesia query
body: <p>I'm trying to build a small testing app with erlang+mnesia.</p>
  
  <p>I have a user table build from the #user record, as defined here:</p>
  
  <pre><code>-record(user_details, {name, password}).
  -record(user, {id, details}).
  </code></pre>
  
  <p>then I insert a user with that function:</p>
  
  <pre><code>add_sample_data() -&gt;
      Mat = #user{
        details = #user_details{
      name = "mat", password = "mat"
         }
       }, 
      user:insert_user(Mat),
  </code></pre>
  
  <p>the query <code>[U#user.details || U &lt;- mnesia:table(user)]</code> return a non empty list.
  now I'm trying to build a query which would return a list containing zero record if there is no record with details.name matching Name or the matching record if there is one.</p>
  
  <p>here is the method I use (this one works):</p>
  
  <pre><code>user_exists() -&gt;
    Fun = fun() -&gt;
      Query = qlc:q([
        U#user.details || 
        U &lt;- mnesia:table(user)
      ]),
      qlc:e(Query)
    end,
    case mnesia:transaction(Fun) of
      {atomic, []} -&gt; false;
      {atomic, [_User]} -&gt; true
    end.
  </code></pre>
  
  <p>I copied some stuff from <a href="http://www.scribd.com/doc/20492533/Erlang-Data-Storage-Modules" rel="nofollow noreferrer">this tutorial</a>. A similar problem is solved with <code>mnesia:select</code> in the <code>mne_fun_query({sport, Sport})</code> method (slide 19) but now I'd like to do it with qlc.</p>
  
  <p>I tried various combinations but without any success (often failed at compilation time..).</p>
  
  <p>I'm really new to erlang, if you can tell which query should works and explains it a little, that would be greatly appreciated!</p>
  
  <p>mat.</p>
  
  <p><strong>edit</strong></p>
  
  <p>here is one version which does not work but maybe explain my problem better</p>
  
  <pre><code>user_exists() -&gt;
    Fun = fun() -&gt;
      Query = qlc:q([
        U#user.details || 
        U &lt;- mnesia:table(user), 
        U#user.details.name == "mat"     &lt;&lt;&lt;&lt;&lt; This is the line with the problem
      ]),
      qlc:e(Query)
    end,
    case mnesia:transaction(Fun) of
      {atomic, []} -&gt; false;
      {atomic, [_User]} -&gt; true
    end.
  </code></pre>
  
  <p>and the error I have:</p>
  
  <blockquote>
    <p>mathieu@evangeneer:~/projects/nopair$ make<br>
    Recompile: src/resources/user_resource<br>
    src/resources/user_resource.erl:22: syntax error before: '.'<br>
    src/resources/user_resource.erl:6: function user_exists/2 undefined make:<br>
    *** [erl] Error 1</p>
  </blockquote>