Inserting default values if column value is 'None' using slick

前端 未结 2 1824
暗喜
暗喜 2021-01-18 02:08

My problem is simple.

I have a column seqNum: Double which is NOT NULL DEFAULT 1 in CREATE TABLE statement as follows:

<
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 02:37

    Using the default requires not inserting the value at all rather than inserting NULL. This means you will need a custom projection to insert to.

    people.map(_.name).insert("Chris") will use defaults for all other fields. The limitations of scala's native tuple transformations and case class transformations can make this a bit of a hassle. Things like Slick's HLists, Shapeless, Scala Records or Scala XR can help, but are not trivial or very experimental at the moment.

提交回复
热议问题