title: Returning the auto incrementing value after an insert using slick
body: <p>I am using slick 2.0.1 (and can upgrade if required) and I want to retrieve the auto incrementing value from the database (postgresql).</p>
  
  <p>I have seen a few questions on SO on this already, but they are fairly old and I was hoping there was a better way than to do what this answer suggests: <a href="https://stackoverflow.com/questions/17634152/scala-play-slick-postgresql-auto-increment?rq=1">Scala &amp; Play! &amp; Slick &amp; PostgreSQL auto increment</a></p>
  
  <pre><code>def autoInc = name ~ price ~ description returning id
  
  def add(product: Product)(implicit s:Session): Long = {
      Products.autoInc.insert(p.name, p.price, p.description)
  }
  </code></pre>
  
  <p><em>You have to re-enter the model's fields in the autoInc method, which is duplicating things which I am hoping to avoid.</em></p>
  
  <p><strong>Is there a better way or I should just do it like this?</strong></p>
  
  <p>The way I have chosen is to have my models poso (plain old scala objects like):</p>
  
  <pre><code>case class Product(.....)
  </code></pre>
  
  <p>And then my dao class looks like:</p>
  
  <pre><code>class ProductDao extends ProductDao {
    class Products(tag: Tag) extends Table[Product](tag, "products") {
  
       def id = ...
       def name = ..
  
       def * = (id, name) &lt;&gt; (Product.tupled, Product.unapply)
  
    }
  
    val products = TableQuery()
  }
  </code></pre>
  
  <p>Also as a side note, for the * method do I have to enter all the properties like that or is there a better way for that also?</p>