title: There are many similar dao methods in anorm, is it right?
body: <p>I'm using Play2 with anorm. I think the spirit of anorm is write plain sqls, no magic behind.</p>
  
  <p>But I quickly found I have write a lot of similar dao methods. For example:</p>
  
  <pre><code>case class User(id:Pk[String], username:String, email:String, realname:String, city:String, website:String)
  
  object User {
    val simple = get[Pk[String]]("id") ~ get[String]("username") ~ ... get[String]("website") map {
      case id ~ username ~ ... ~ website = User(id, username, ..., website)
    }
    def findByUsername(username:String) = DB.withConnection { implicit connection =&gt;
       SQL("select * from users where username={username}").on('username-&gt;username).as(simple.singleOpt)
    }
    def findByEmail(email:String) = DB.withConnection { implicit connection =&gt;
       SQL("select * from users where email={email}").on('email-&gt;email).as(simple.singleOpt)
    }
    def findById(id:String) = DB.withConnection { implicit connection =&gt;
       SQL("select * from users where id={id}").on('id-&gt;id).as(simple.singleOpt)
    }
    def findByRealname(keyword:String) = DB.withConnection { implicit connection =&gt;
       SQL("select * from users where realname like {keyword}").on('keyword-&gt;"%"+keyword+"%").as(simple *)
    }
    // more similar methods
  }
  </code></pre>
  
  <p>There methods are almost the same, exception the <code>where</code> clause has small difference. </p>
  
  <p>So I created a <code>findWhere()</code> method as:</p>
  
  <pre><code>def findWhere(conditon, values:Any*) = ...
  </code></pre>
  
  <p>That I can call it in actions:</p>
  
  <pre><code>User.findWhere("id=?", id)
  User.findWhere("username=?", username)
  </code></pre>
  
  <p>It works, but I don't think it's recommended by anorm. </p>
  
  <p>What's the best way to solve this problem?</p>