I have case classes
which have Option[java.sql.Timestamp]
field.
case class BooRow(id:Int, createdTs: Option[java.sql.Timestamp])
case class FooRow(id: Int, name:String, deptId:Int,createdTs:Option[java.sql.Timestamp])
case class BarRow(id:Int,name:String)
looking for a generic solution which is also compile time safe to observe incoming case class
instance and if it finds createdTs:Option[java.sql.Timestamp]
in it then populate it.
Originally thought started with looking at shapless and had posted this question. Gabriele 's answer is right in the context of that previous question but may be I wasn't clear enough in the question so not sure how to "catch" "implicit not found error for that shapeless solution" (for the case class
which doesn't have createdTs
field) somehow. Generic function should populate createdTs
if found in a case class
instance it was passed, if it doesn't find createdTs
in an instance of a case class then do nothing.
I have tagged slick for this question because these are slick generated case classes (not the reason for tagging) but I assume this can be a common need (generically populating such timestamp columns) when dealing with slick/databases in general. To clarify, I am not looking for db based solutions (like triggers etc) but something at an application level also without using structural types.
Edit: Providing default value to createdTs
in case class
declaration is not a desired solution. That will stamp wrong timestamp when case class
instance is created for an "update" query.