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

前端 未结 2 1826
暗喜
暗喜 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:26

    Either you enforce the Option passed to Slick by suffixing it with a .getOrElse(theDefault), or you make the DB accepts NULL (from a None value) and defaults it using some trigger.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题