Default Date Column with Slick 3.1.0

I have an events table with these columns

  _________________________ |___name_____|___time_____| | | | |____________|____________| 

The value of the temporary column is automatically created with the current date at the time of creation.

Equivalently, I have this case class to represent a row in a table.

 case class Event(name: String, time: Option[java.sql.Date] = None) 

Now the problem is that when I try to insert an event with

 val event = Event("blah blah blah") events += event 

Slick actually inserts ('blah blah blah', null) instead of just ('blah blah blah') , and this makes the time field null .

If I set the limit on the time column to NOT NULL , then I would get an error for trying to insert null .

Of course, I can decompose my event object and perform an insert, but I wonder if there is some kind of mapping that tells Slick that this column is automatically generated, for example, in the case of a column with an auto increment identifier

 def id = column[Long]("id", O.AutoInc) 

Update

So I am trying to set the time column as follows

 def time = column[java.sql.Date]("time", O.AutoInc) 

and it seems to work.

The document for AutoInc states that it is used for the auto increment and auto generated columns.

Although I'm not sure if this is the right way to do this.

+5
source share

Source: https://habr.com/ru/post/1234113/


All Articles