Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have the following postgres column definition:

record_time TIMESTAMP WITHOUT TIME ZONE DEFAULT now()

How would I map it to slick? Please take into account that I wish to map the default value generated by the now() function

i.e:

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

Should any extra definition go where the ...???... is currently located?

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
like image 471
Yaneeve Avatar asked Aug 03 '15 11:08

Yaneeve


2 Answers

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

like image 146
AlexITC Avatar answered Sep 20 '22 10:09

AlexITC


I guess this is not supported yet. Here is issue: https://github.com/slick/slick/issues/214

like image 34
Igor Mielientiev Avatar answered Sep 23 '22 10:09

Igor Mielientiev