title: How do you run a patch/partial database UPDATE in Scala Slick?
body: <p>We'd like to run a patch/partial <code>UPDATE</code> with Slick (3.0.0) so that we only modify some of the fields in a record. Exactly which fields will be updated exactly will only be known at runtime.</p>
  
  <p>For example, for a <a href="http://restcookbook.com/HTTP%20Methods/patch/" rel="noreferrer">REST <code>PATCH</code> request</a>.</p>
  
  <p>Currently we run a <code>SELECT</code> first to get the original record then run an <code>UPDATE</code> but it would be nicer to do this in a single SQL statement.</p>
  
  <p>Something like this:</p>
  
  <pre><code>def patchPerson(name: Option[String], age: Option[Int]) = {
     people.filter(_.name === "M Odersky")
         .map(p =&gt; 
             (name, age) match {
                case (Some(_), Some(_)) =&gt; (p.name, p.age)
                case (Some(_), None)    =&gt; (p.name)
                case (None   , Some(_)) =&gt; (p.age)
             }
         )
         .update(
             (name, age) match {
                case (Some(_), Some(_)) =&gt; (name.get, age.get)
                case (Some(_), None)    =&gt; (name.get)
                case (None   , Some(_)) =&gt; (age.get)
             }
         )
  }
  </code></pre>
  
  <p><em>(Please ignore the ugly code here)</em></p>
  
  <p>The above does not compile with the following error message:</p>
  
  <blockquote>
    <p>No matching Shape found. Slick does not know how to map the given
    types. Possible causes: T in Table[T] does not match your *
    projection. Or you use an unsupported type in a Query (e.g. scala
    List).   Required level: slick.lifted.FlatShapeLevel      Source type:
    Object    Unpacked type: T      Packed type: G</p>
  </blockquote>
  
  <p>And:</p>
  
  <blockquote>
    <p>not enough arguments for method map: (implicit shape:
    slick.lifted.Shape[_ &lt;: slick.lifted.FlatShapeLevel, Object, T,
    G])slick.lifted.Query[G,T,Seq]. Unspecified value parameter shape.</p>
  </blockquote>
  
  <p>I assume this is because Slick expects the tuple length and type to match the results for both the <code>filter</code> and <code>update</code> functions.</p>
  
  <p>We've tried using the Slick <a href="http://slick.typesafe.com/doc/3.0.0/api/index.html#slick.collection.heterogeneous.HList" rel="noreferrer">heterogeneous list</a> class but this also seems to expect the length and types to match.</p>
  
  <p>Is there a way to write this in Slick so that we can update an arbitrary number of fields in a record with one database call?</p>