I have an events
table with these columns
_________________________
|___name_____|___time_____|
| | |
|____________|____________|
The value of time column is auto generated with the current date at creation time.
Equivalently, I have this case class to represent a row in the 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 insert ('blah blah blah', null)
instead of just ('blah blah blah')
, and that makes the time field null
.
If I set a constraint on the time column to NOT NULL
, then I would get an error for the attempt to insert null
.
Of course I can decompose my event
object and perform the insert, but I wonder if there is a kind of mapping that tells Slick that this column is auto-generated, like in the case with the auto-increment id column:
def id = column[Long]("id", O.AutoInc)
Update
So I try setting the time column as follow
def time = column[java.sql.Date]("time", O.AutoInc)
and it seems to work.
The document for AutoInc
states that it is use for auto increment
and auto generated
column.
Though I am not sure if this is the correct way to do it.