Slick 3 auto-generated - default column (timestamp), how to define Rep [Date] function

I have the following postgres column definition:

record_time TIMESTAMP WITHOUT TIME ZONE DEFAULT now() 

How do I match it to a stain? Please note that I want to map the default value generated by the now() function

i.e:

 def recordTimestamp: Rep[Date] = column[Date]("record_time", ...???...) 

Should any additional definition go where it is ...???... ?

EDIT (1)

I do not want to use

 column[Date]("record_time", O.Default(new Date(System.currentTimeMillis()))) // or some such applicative generation of the date column value 
+5
source share
3 answers

I think this is not yet supported. Here is the question: https://github.com/slick/slick/issues/214

+2
source

I found a blog explaining that you can use the following:

 // slick 3 import slick.profile.SqlProfile.ColumnOption.SqlType def created = column[Timestamp]("created", SqlType("timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP")) // slick 3 def createdAt = column[Timestamp]("createdAt", O.NotNull, O.DBType("timestamp default now()")) 

see http://queirozf.com/entries/scala-slick-dealing-with-datetime-timestamp-attributes

+3
source

Slick 3 Example

 import slick.driver.PostgresDriver.api._ import slick.lifted._ import java.sql.{Date, Timestamp} /** A representation of the message decorated for Slick persistence * created_date should always be null on insert operations. * It is set at the database level to ensure time syncronicity * Id is the Twitter snowflake id. All columns NotNull unless declared as Option * */ class RawMessages(tag: Tag) extends Table[(String, Option[String], Timestamp)](tag, Some("rti"), "RawMessages") { def id = column[String]("id", O.PrimaryKey) def MessageString = column[Option[String]]("MessageString") def CreatedDate = column[Timestamp]("CreatedDate", O.SqlType("timestamp default now()")) def * = (id, MessageString, CreatedDate) } 
+2
source

All Articles