In many slick examples in which the type parameter of the table is a case class and the table has an auto-incrementing primary key, I have seen an Option used in the case class for the id field:
case class Item(id : Option[Long], name : String)
object Items extends Table[Item]("item"){
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def * = id.? ~ name <> (Item.apply _, Item.unapply _)
}
This kind of makes sense to me, because the id field will have no meaningful value until the object is inserted into the table. However, database queries will always give me back Items that have the id set to something and it gets extremely tedious always folding or pattern matching on something that I know will not be None. I could just put a 0L in the id field when I create a new Item, but this doesn't seem like a good choice.
How is this typically dealt with? Are those the only two options?
This related question has some possible answers in it. The question itself is about a much more specific issue with postgres though.